[macruby-changes] [905] MacRuby/branches/experimental
source_changes at macosforge.org
source_changes at macosforge.org
Fri Mar 13 16:40:22 PDT 2009
Revision: 905
http://trac.macosforge.org/projects/ruby/changeset/905
Author: lsansonetti at apple.com
Date: 2009-03-13 16:40:21 -0700 (Fri, 13 Mar 2009)
Log Message:
-----------
reimplement argf + cleanup
Modified Paths:
--------------
MacRuby/branches/experimental/io.c
MacRuby/branches/experimental/ruby.c
Modified: MacRuby/branches/experimental/io.c
===================================================================
--- MacRuby/branches/experimental/io.c 2009-03-13 22:59:41 UTC (rev 904)
+++ MacRuby/branches/experimental/io.c 2009-03-13 23:40:21 UTC (rev 905)
@@ -742,7 +742,7 @@
long data_read = 0;
- // First let's check if there is something to read in our ungets buffer.
+ // First let's check if there is something to read in our ungetc buffer.
if (io_struct->ungetc_buf_len > 0) {
data_read = MIN(io_struct->ungetc_buf_len, len);
memcpy(buffer, &io_struct->ungetc_buf[io_struct->ungetc_buf_pos],
@@ -1522,6 +1522,19 @@
return prep_io(fd, rb_io_modenum_flags(mode), klass, path);
}
+static VALUE
+rb_io_getline(int argc, VALUE *argv, VALUE io)
+{
+#if 0 // TODO
+ VALUE rs;
+ long limit;
+
+ prepare_getline_args(argc, argv, &rs, &limit, io);
+ return rb_io_getline_1(rs, limit, io);
+#endif
+ abort();
+}
+
VALUE
rb_io_gets(VALUE io, SEL sel)
{
@@ -1625,6 +1638,20 @@
rb_notimplement();
}
+VALUE
+rb_io_binmode(VALUE io, SEL sel)
+{
+ // TODO
+#if 0
+ rb_io_t *fptr;
+
+ GetOpenFile(io, fptr);
+ fptr->mode |= FMODE_BINMODE;
+ return io;
+#endif
+ abort();
+}
+
/*
* call-seq:
* ios.binmode => ios
@@ -1637,7 +1664,8 @@
static VALUE
rb_io_binmode_m(VALUE io, SEL sel)
{
-rb_notimplement();
+ rb_io_binmode(io, 0);
+ return io;
}
/*
@@ -2178,13 +2206,20 @@
* World
*/
+/*
+ * call-seq:
+ * IO.for_fd(fd, mode) => io
+ *
+ * Synonym for <code>IO::new</code>.
+ *
+ */
+
static VALUE
rb_io_initialize(VALUE io, SEL sel, int argc, VALUE *argv)
{
-rb_notimplement();
+ rb_notimplement();
}
-
/*
* call-seq:
* File.new(filename, mode="r") => file
@@ -2237,87 +2272,284 @@
}
-/*
- * call-seq:
- * IO.for_fd(fd, mode) => io
- *
- * Synonym for <code>IO::new</code>.
- *
- */
+static inline void
+argf_init(struct argf *p, VALUE v)
+{
+ p->filename = Qnil;
+ p->current_file = Qnil;
+ p->lineno = Qnil;
+ GC_WB(&p->argv, v);
+}
-// removed.
-
-
static VALUE
argf_alloc(VALUE klass)
{
-rb_notimplement();
+ struct argf *p;
+
+ VALUE argf = Data_Make_Struct(klass, struct argf, NULL, NULL, p);
+ argf_init(p, Qnil);
+
+ return argf;
}
#undef rb_argv
+#define filename ARGF.filename
+#define current_file ARGF.current_file
+#define gets_lineno ARGF.gets_lineno
+#define init_p ARGF.init_p
+#define next_p ARGF.next_p
+#define lineno ARGF.lineno
+#define ruby_inplace_mode ARGF.inplace
+#define argf_binmode ARGF.binmode
+#define argf_enc ARGF.enc
+#define argf_enc2 ARGF.enc2
#define rb_argv ARGF.argv
static VALUE
argf_initialize(VALUE argf, SEL sel, VALUE argv)
{
-rb_notimplement();
+ memset(&ARGF, 0, sizeof(ARGF));
+ argf_init(&ARGF, argv);
+
+ return argf;
}
static VALUE
argf_initialize_copy(VALUE argf, SEL sel, VALUE orig)
{
- rb_notimplement();
+ ARGF = argf_of(orig);
+ GC_WB(&rb_argv, rb_obj_dup(rb_argv));
+ if (ARGF.inplace) {
+ const char *inplace = ARGF.inplace;
+ ARGF.inplace = 0;
+ GC_WB(&ARGF.inplace, ruby_strdup(inplace));
+ }
+ return argf;
}
static VALUE
argf_set_lineno(VALUE argf, SEL sel, VALUE val)
{
-rb_notimplement();
+ gets_lineno = NUM2INT(val);
+ lineno = INT2FIX(gets_lineno);
+ return Qnil;
}
static VALUE
argf_lineno(VALUE argf, SEL sel)
{
-rb_notimplement();
+ return lineno;
}
-// static VALUE
-// argf_forward(VALUE argf, SEL sel, int argc, VALUE *argv)
-// {
-// rb_notimplement();
-// }
-//
-// static void
-// argf_close(VALUE file, SEL sel)
-// {
-// rb_notimplement();
-// }
-//
-// static int
-// argf_next_argv(VALUE argf, SEL sel)
-// {
-// rb_notimplement();
-// }
-//
-// static VALUE
-// argf_getline(VALUE argf, SEL sel, int argc, VALUE *argv)
-// {
-// rb_notimplement();
-// }
+static VALUE
+argf_forward(VALUE argf, SEL sel, int argc, VALUE *argv)
+{
+ // TODO
+ //return rb_funcall3(current_file, rb_frame_this_func(), argc, argv);
+ abort();
+}
-#if 0
+#define next_argv() argf_next_argv(argf)
+#define ARGF_GENERIC_INPUT_P() \
+ (current_file == rb_stdin && TYPE(current_file) != T_FILE)
+
+#define ARGF_FORWARD(argc, argv) do {\
+ if (ARGF_GENERIC_INPUT_P())\
+ return argf_forward(argf, 0, argc, argv);\
+} while (0)
+
+#define NEXT_ARGF_FORWARD(argc, argv) do {\
+ if (!next_argv()) return Qnil;\
+ ARGF_FORWARD(argc, argv);\
+} while (0)
+
+static void
+argf_close(VALUE file, SEL sel)
+{
+ rb_funcall3(file, rb_intern("close"), 0, 0);
+}
+
+static int
+argf_next_argv(VALUE argf)
+{
+#if 0 // TODO
+ char *fn;
+ rb_io_t *fptr;
+ int stdout_binmode = 0;
+
+ if (TYPE(rb_stdout) == T_FILE) {
+ GetOpenFile(rb_stdout, fptr);
+ if (fptr->mode & FMODE_BINMODE)
+ stdout_binmode = 1;
+ }
+
+ if (init_p == 0) {
+ if (!NIL_P(rb_argv) && RARRAY_LEN(rb_argv) > 0) {
+ next_p = 1;
+ }
+ else {
+ next_p = -1;
+ }
+ init_p = 1;
+ gets_lineno = 0;
+ }
+
+ if (next_p == 1) {
+ next_p = 0;
+retry:
+ if (RARRAY_LEN(rb_argv) > 0) {
+ filename = rb_ary_shift(rb_argv);
+ fn = StringValueCStr(filename);
+ if (strlen(fn) == 1 && fn[0] == '-') {
+ current_file = rb_stdin;
+ if (ruby_inplace_mode) {
+ rb_warn("Can't do inplace edit for stdio; skipping");
+ goto retry;
+ }
+ }
+ else {
+ int fr = rb_sysopen(fn, O_RDONLY, 0);
+
+ if (ruby_inplace_mode) {
+ struct stat st;
+#ifndef NO_SAFE_RENAME
+ struct stat st2;
+#endif
+ VALUE str;
+ int fw;
+
+ if (TYPE(rb_stdout) == T_FILE && rb_stdout != orig_stdout) {
+ rb_io_close(rb_stdout);
+ }
+ fstat(fr, &st);
+ if (*ruby_inplace_mode) {
+ str = rb_str_new2(fn);
+#ifdef NO_LONG_FNAME
+ ruby_add_suffix(str, ruby_inplace_mode);
+#else
+ rb_str_cat2(str, ruby_inplace_mode);
+#endif
+#ifdef NO_SAFE_RENAME
+ (void)close(fr);
+ (void)unlink(RSTRING_PTR(str));
+ (void)rename(fn, RSTRING_PTR(str));
+ fr = rb_sysopen(RSTRING_PTR(str), O_RDONLY, 0);
+#else
+ if (rename(fn, RSTRING_PTR(str)) < 0) {
+ rb_warn("Can't rename %s to %s: %s, skipping file",
+ fn, RSTRING_PTR(str), strerror(errno));
+ close(fr);
+ goto retry;
+ }
+#endif
+ }
+ else {
+#ifdef NO_SAFE_RENAME
+ rb_fatal("Can't do inplace edit without backup");
+#else
+ if (unlink(fn) < 0) {
+ rb_warn("Can't remove %s: %s, skipping file",
+ fn, strerror(errno));
+ close(fr);
+ goto retry;
+ }
+#endif
+ }
+ fw = rb_sysopen(fn, O_WRONLY|O_CREAT|O_TRUNC, 0666);
+#ifndef NO_SAFE_RENAME
+ fstat(fw, &st2);
+#ifdef HAVE_FCHMOD
+ fchmod(fw, st.st_mode);
+#else
+ chmod(fn, st.st_mode);
+#endif
+ if (st.st_uid!=st2.st_uid || st.st_gid!=st2.st_gid) {
+ fchown(fw, st.st_uid, st.st_gid);
+ }
+#endif
+ rb_stdout = prep_io(fw, FMODE_WRITABLE, rb_cFile, fn);
+ if (stdout_binmode) {
+ rb_io_binmode(rb_stdout, 0);
+ }
+ }
+ current_file = prep_io(fr, FMODE_READABLE, rb_cFile, fn);
+ }
+ if (argf_binmode) {
+ rb_io_binmode(current_file);
+ }
+ if (argf_enc) {
+ rb_io_t *fptr;
+
+ GetOpenFile(current_file, fptr);
+ fptr->enc = argf_enc;
+ fptr->enc2 = argf_enc2;
+ }
+ }
+ else {
+ next_p = 1;
+ return Qfalse;
+ }
+ }
+ else if (next_p == -1) {
+ current_file = rb_stdin;
+ filename = rb_str_new2("-");
+ if (ruby_inplace_mode) {
+ rb_warn("Can't do inplace edit for stdio");
+ rb_stdout = orig_stdout;
+ }
+ }
+ return Qtrue;
+#endif
+ abort();
+}
+
static VALUE
+argf_getline(VALUE argf, SEL sel, int argc, VALUE *argv)
+{
+ VALUE line;
+
+retry:
+ if (!next_argv()) {
+ return Qnil;
+ }
+ if (ARGF_GENERIC_INPUT_P()) {
+ line = rb_funcall3(current_file, rb_intern("gets"), argc, argv);
+ }
+ else {
+ if (argc == 0 && rb_rs == rb_default_rs) {
+ line = rb_io_gets(current_file, 0);
+ }
+ else {
+ line = rb_io_getline(argc, argv, current_file);
+ }
+ if (NIL_P(line) && next_p != -1) {
+ argf_close(current_file, 0);
+ next_p = 1;
+ goto retry;
+ }
+ }
+ if (!NIL_P(line)) {
+ gets_lineno++;
+ lineno = INT2FIX(gets_lineno);
+ }
+ return line;
+}
+
+static VALUE
argf_lineno_getter(ID id, VALUE *var)
{
- rb_notimplement();
+ VALUE argf = *var;
+ return lineno;
}
static void
argf_lineno_setter(VALUE val, ID id, VALUE *var)
{
- rb_notimplement();
+ VALUE argf = *var;
+ int n = NUM2INT(val);
+ gets_lineno = n;
+ lineno = INT2FIX(n);
}
-#endif
/*
* call-seq:
@@ -2352,16 +2584,25 @@
* parameter is gradually losing favor in the Ruby community.
*/
+static VALUE argf_gets(VALUE, SEL, int, VALUE *);
+
static VALUE
rb_f_gets(VALUE recv, SEL sel, int argc, VALUE *argv)
{
-rb_notimplement();
+ if (recv == argf) {
+ return argf_gets(argf, 0, argc, argv);
+ }
+ return rb_funcall2(argf, rb_intern("gets"), argc, argv);
}
static VALUE
argf_gets(VALUE recv, SEL sel, int argc, VALUE *argv)
{
-rb_notimplement();
+ VALUE line;
+
+ line = argf_getline(argf, 0, argc, argv);
+ rb_lastline_set(line);
+ return line;
}
/*
@@ -2877,80 +3118,108 @@
static VALUE
argf_filename(VALUE argf, SEL sel)
{
-rb_notimplement();
+ next_argv();
+ return filename;
}
-#if 0
static VALUE
argf_filename_getter(ID id, VALUE *var)
{
- rb_notimplement();
+ return argf_filename(*var, 0);
}
-#endif
static VALUE
argf_file(VALUE argf, SEL sel)
{
- rb_notimplement();
+ next_argv();
+ return current_file;
}
static VALUE
argf_binmode_m(VALUE argf, SEL sel)
{
-rb_notimplement();
+ argf_binmode = 1;
+ next_argv();
+ ARGF_FORWARD(0, 0);
+ rb_io_binmode(current_file, 0);
+ return argf;
}
static VALUE
argf_skip(VALUE argf, SEL sel)
{
-rb_notimplement();
+ if (next_p != -1) {
+ argf_close(current_file, 0);
+ next_p = 1;
+ }
+ return argf;
}
static VALUE
argf_close_m(VALUE argf, SEL sel)
{
-rb_notimplement();
+ next_argv();
+ argf_close(current_file, 0);
+ if (next_p != -1) {
+ next_p = 1;
+ }
+ gets_lineno = 0;
+ return argf;
}
static VALUE
argf_closed(VALUE argf, SEL sel)
{
-rb_notimplement();
+ next_argv();
+ ARGF_FORWARD(0, 0);
+ return rb_io_closed(current_file, 0);
}
static VALUE
argf_to_s(VALUE argf, SEL sel)
{
-rb_notimplement();
+ return rb_str_new2("ARGF");
}
static VALUE
-argf_inplace_mode_get(VALUE argf)
+argf_inplace_mode_get(VALUE argf, SEL sel)
{
-rb_notimplement();
+ if (ruby_inplace_mode == NULL) {
+ return Qnil;
+ }
+ return rb_str_new2(ruby_inplace_mode);
}
-#if 0
static VALUE
opt_i_get(ID id, VALUE *var)
{
- rb_notimplement();
+ return argf_inplace_mode_get(*var, 0);
}
-#endif
static VALUE
-argf_inplace_mode_set(VALUE argf, VALUE val)
+argf_inplace_mode_set(VALUE argf, SEL sel, VALUE val)
{
- rb_notimplement();
+ if (!RTEST(val)) {
+ if (ruby_inplace_mode != NULL) {
+ free(ruby_inplace_mode);
+ }
+ ruby_inplace_mode = NULL;
+ }
+ else {
+ StringValue(val);
+ if (ruby_inplace_mode != NULL) {
+ free(ruby_inplace_mode);
+ }
+ ruby_inplace_mode = strdup(RSTRING_BYTEPTR(val));
+ }
+ return argf;
}
-#if 0
static void
opt_i_set(VALUE val, ID id, VALUE *var)
{
- rb_notimplement();
+ argf_inplace_mode_set(*var, 0, val);
}
-#endif
const char *
ruby_get_inplace_mode(void)
@@ -2965,24 +3234,21 @@
}
static VALUE
-argf_argv(VALUE argf)
+argf_argv(VALUE argf, SEL sel)
{
-rb_notimplement();
+ return rb_argv;
}
-#if 0
static VALUE
argf_argv_getter(ID id, VALUE *var)
{
- rb_notimplement();
+ return argf_argv(*var, 0);
}
-#endif
VALUE
rb_get_argv(void)
{
- // TODO
- return Qnil;
+ return rb_argv;
}
/*
@@ -3316,19 +3582,17 @@
rb_objc_define_method(rb_cARGF, "internal_encoding", argf_internal_encoding, 0);
rb_objc_define_method(rb_cARGF, "set_encoding", argf_set_encoding, -1);
- argf = Qnil;
+ argf = rb_class_new_instance(0, 0, rb_cARGF);
-#if 0 // TODO
rb_define_readonly_variable("$<", &argf);
rb_define_global_const("ARGF", argf);
rb_define_hooked_variable("$.", &argf, argf_lineno_getter, argf_lineno_setter);
rb_define_hooked_variable("$FILENAME", &argf, argf_filename_getter, 0);
- //GC_WB(&filename, rb_str_new2("-"));
+ GC_WB(&filename, rb_str_new2("-"));
rb_define_hooked_variable("$-i", &argf, opt_i_get, opt_i_set);
rb_define_hooked_variable("$*", &argf, argf_argv_getter, 0);
-#endif
Init_File();
Modified: MacRuby/branches/experimental/ruby.c
===================================================================
--- MacRuby/branches/experimental/ruby.c 2009-03-13 22:59:41 UTC (rev 904)
+++ MacRuby/branches/experimental/ruby.c 2009-03-13 23:40:21 UTC (rev 905)
@@ -35,10 +35,6 @@
# define MAXPATHLEN 1024
#endif
-#if defined(__MACOS__) && defined(__MWERKS__)
-#include <console.h>
-#endif
-
#include "ruby/util.h"
#ifndef HAVE_STDLIB_H
@@ -83,11 +79,7 @@
struct {
struct {
VALUE name;
-#if WITH_OBJC
rb_encoding *enc;
-#else
- int index;
-#endif
} enc;
} src, ext;
};
@@ -154,69 +146,8 @@
#define CharNext(p) ((p) + mblen(p, RUBY_MBCHAR_MAXSIZE))
#endif
-#if defined DOSISH || defined __CYGWIN__
-static inline void
-translate_char(char *p, int from, int to)
-{
- while (*p) {
- if ((unsigned char)*p == from)
- *p = to;
- p = CharNext(p);
- }
-}
-#endif
-
-#if defined _WIN32 || defined __CYGWIN__ || defined __DJGPP__
-static VALUE
-rubylib_mangled_path(const char *s, unsigned int l)
-{
- static char *newp, *oldp;
- static int newl, oldl, notfound;
- char *ptr;
- VALUE ret;
-
- if (!newp && !notfound) {
- newp = getenv("RUBYLIB_PREFIX");
- if (newp) {
- oldp = newp = strdup(newp);
- while (*newp && !ISSPACE(*newp) && *newp != ';') {
- newp = CharNext(newp); /* Skip digits. */
- }
- oldl = newp - oldp;
- while (*newp && (ISSPACE(*newp) || *newp == ';')) {
- newp = CharNext(newp); /* Skip whitespace. */
- }
- newl = strlen(newp);
- if (newl == 0 || oldl == 0) {
- rb_fatal("malformed RUBYLIB_PREFIX");
- }
- translate_char(newp, '\\', '/');
- }
- else {
- notfound = 1;
- }
- }
- if (!newp || l < oldl || STRNCASECMP(oldp, s, oldl) != 0) {
- return rb_str_new(s, l);
- }
- ret = rb_str_new(0, l + newl - oldl);
- ptr = RSTRING_BYTEPTR(ret); /* ok */
- memcpy(ptr, newp, newl);
- memcpy(ptr + newl, s + oldl, l - oldl);
- ptr[l + newl - oldl] = 0;
- RSTRING_SYNC(ret);
- return ret;
-}
-
-static VALUE
-rubylib_mangled_path2(const char *s)
-{
- return rubylib_mangled_path(s, strlen(s));
-}
-#else
#define rubylib_mangled_path rb_str_new
#define rubylib_mangled_path2 rb_str_new2
-#endif
static void
push_include(const char *path, VALUE (*filter)(VALUE))
@@ -239,50 +170,12 @@
}
}
-#ifdef __CYGWIN__
-static void
-push_include_cygwin(const char *path, VALUE (*filter)(VALUE))
-{
- const char *p, *s;
- char rubylib[FILENAME_MAX];
- VALUE buf = 0;
-
- p = path;
- while (*p) {
- unsigned int len;
- while (*p == ';')
- p++;
- if (!*p) break;
- for (s = p; *s && *s != ';'; s = CharNext(s));
- len = s - p;
- if (*s) {
- if (!buf) {
- buf = rb_str_new(p, len);
- p = RSTRING_PTR(buf);
- }
- else {
- rb_str_resize(buf, len);
- p = strncpy(RSTRING_BYTEPTR(buf), p, len); /* ok */
- RSTRING_SYNC(buf);
- }
- }
- if (cygwin_conv_to_posix_path(p, rubylib) == 0)
- p = rubylib;
- push_include(p, filter);
- if (!*s) break;
- p = s + 1;
- }
-}
-
-#define push_include push_include_cygwin
-#endif
-
void
ruby_push_include(const char *path, VALUE (*filter)(VALUE))
{
- if (path == 0)
- return;
- push_include(path, filter);
+ if (path != NULL) {
+ push_include(path, filter);
+ }
}
static VALUE
@@ -301,10 +194,12 @@
expand_include_path(VALUE path)
{
const char *p = RSTRING_PTR(path);
- if (!p)
+ if (!p) {
return path;
- if (*p == '.' && p[1] == '/')
+ }
+ if (*p == '.' && p[1] == '/') {
return path;
+ }
return rb_file_expand_path(path, Qnil);
}
@@ -314,22 +209,6 @@
ruby_push_include(path, expand_include_path);
}
-#if defined DOSISH || defined __CYGWIN__
-#define LOAD_RELATIVE 1
-#endif
-
-#if defined _WIN32 || defined __CYGWIN__
-static HMODULE libruby;
-
-BOOL WINAPI
-DllMain(HINSTANCE dll, DWORD reason, LPVOID reserved)
-{
- if (reason == DLL_PROCESS_ATTACH)
- libruby = dll;
- return TRUE;
-}
-#endif
-
void
ruby_init_loadpath(void)
{
@@ -339,28 +218,7 @@
char *p;
int rest;
-#if defined _WIN32 || defined __CYGWIN__
- GetModuleFileName(libruby, libpath, sizeof libpath);
-#elif defined(DJGPP)
- extern char *__dos_argv0;
- strncpy(libpath, __dos_argv0, sizeof(libpath) - 1);
-#elif defined(__human68k__)
- extern char **_argv;
- strncpy(libpath, _argv[0], sizeof(libpath) - 1);
-#elif defined(__EMX__)
- _execname(libpath, sizeof(libpath) - 1);
-#endif
-
libpath[sizeof(libpath) - 1] = '\0';
-#if defined DOSISH
- translate_char(libpath, '\\', '/');
-#elif defined __CYGWIN__
- {
- char rubylib[FILENAME_MAX];
- cygwin_conv_to_posix_path(libpath, rubylib);
- strncpy(libpath, rubylib, sizeof(libpath));
- }
-#endif
p = strrchr(libpath, '/');
if (p) {
*p = 0;
@@ -416,22 +274,11 @@
}
}
-#if WITH_OBJC
static CFMutableArrayRef req_list = NULL;
-#else
-struct req_list {
- char *name;
- struct req_list *next;
-};
-static struct {
- struct req_list *last, head;
-} req_list = {&req_list.head,};
-#endif
static void
add_modules(const char *mod)
{
-#if WITH_OBJC
CFStringRef mod_str;
if (req_list == NULL) {
req_list = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
@@ -439,16 +286,6 @@
mod_str = CFStringCreateWithFileSystemRepresentation(NULL, mod);
CFArrayAppendValue(req_list, mod_str);
CFRelease(mod_str);
-#else
- struct req_list *list;
-
- list = ALLOC(struct req_list);
- list->name = ALLOC_N(char, strlen(mod) + 1);
- strcpy(list->name, mod);
- list->next = 0;
- req_list.last->next = list;
- req_list.last = list;
-#endif
}
extern void Init_ext(void);
@@ -457,7 +294,6 @@
static void
require_libraries(void)
{
-#if WITH_OBJC
Init_ext(); /* should be called here for some reason :-( */
if (req_list != NULL) {
@@ -473,23 +309,6 @@
}
CFRelease(req_list);
}
-#else
- struct req_list *list = req_list.head.next;
- struct req_list *tmp;
- ID require = rb_intern("require");
-
- Init_ext(); /* should be called here for some reason :-( */
- req_list.last = 0;
- while (list) {
- VALUE feature = rb_str_new2(list->name);
- tmp = list->next;
- xfree(list->name);
- xfree(list);
- list = tmp;
- rb_funcall2(rb_vm_top_self(), require, 1, &feature);
- }
- req_list.head.next = 0;
-#endif
}
static void
@@ -963,45 +782,27 @@
static void
ruby_init_gems(int enable)
{
- if (enable) rb_define_module("Gem");
+ if (enable) {
+ rb_define_module("Gem");
+ }
//Init_prelude();
}
-#if WITH_OBJC
static rb_encoding *
opt_enc_find(VALUE enc_name)
{
rb_encoding *enc = rb_enc_find2(enc_name);
- if (enc == NULL)
+ if (enc == NULL) {
rb_raise(rb_eRuntimeError, "unknown encoding name - %s",
RSTRING_PTR(enc_name));
+ }
return enc;
}
-#else
-static int
-opt_enc_index(VALUE enc_name)
-{
- const char *s = RSTRING_PTR(enc_name);
- int i = rb_enc_find_index(s);
- if (i < 0) {
- rb_raise(rb_eRuntimeError, "unknown encoding name - %s", s);
- }
- else if (rb_enc_dummy_p(rb_enc_from_index(i))) {
- rb_raise(rb_eRuntimeError, "dummy encoding is not acceptable - %s ", s);
- }
- return i;
-}
-#endif
-
VALUE rb_progname;
VALUE rb_argv0;
-#if WITH_OBJC
static rb_encoding *src_encoding;
-#else
-static int src_encoding_index = -1; /* TODO: VM private */
-#endif
static VALUE
process_options(VALUE arg)
@@ -1109,9 +910,6 @@
}
ruby_script(opt->script);
-#if defined DOSISH || defined __CYGWIN__
- translate_char(RSTRING_PTR(rb_progname), '\\', '/');
-#endif
GC_WB(&opt->script_name, rb_str_new4(rb_progname));
opt->script = RSTRING_PTR(opt->script_name);
ruby_set_argv(argc, argv);
@@ -1122,38 +920,18 @@
rb_set_safe_level_force(0);
ruby_init_gems(!(opt->disable & DISABLE_BIT(gems)));
lenc = rb_locale_encoding();
-#if !WITH_OBJC
- for (i = 0; i < RARRAY_LEN(rb_argv); i++) {
- rb_enc_associate(RARRAY_PTR(rb_argv)[i], lenc);
- }
-#endif
parser = rb_parser_new();
if (opt->yydebug) rb_parser_set_yydebug(parser, Qtrue);
if (opt->ext.enc.name != 0) {
-#if WITH_OBJC
opt->ext.enc.enc = opt_enc_find(opt->ext.enc.name);
-#else
- opt->ext.enc.index = opt_enc_index(opt->ext.enc.name);
-#endif
}
if (opt->src.enc.name != 0) {
-#if WITH_OBJC
opt->src.enc.enc = opt_enc_find(opt->src.enc.name);
src_encoding = opt->src.enc.enc;
-#else
- opt->src.enc.index = opt_enc_index(opt->src.enc.name);
- src_encoding_index = opt->src.enc.index;
-#endif
}
-#if WITH_OBJC
if (opt->ext.enc.enc != NULL) {
enc = opt->ext.enc.enc;
}
-#else
- if (opt->ext.enc.index >= 0) {
- enc = rb_enc_from_index(opt->ext.enc.index);
- }
-#endif
else {
enc = lenc;
}
@@ -1162,21 +940,12 @@
rb_set_safe_level_force(safe);
if (opt->e_script) {
rb_encoding *eenc;
-#if WITH_OBJC
if (opt->src.enc.enc != NULL) {
eenc = opt->src.enc.enc;
}
-#else
- if (opt->src.enc.index >= 0) {
- eenc = rb_enc_from_index(opt->src.enc.index);
- }
-#endif
else {
eenc = lenc;
}
-#if !WITH_OBJC
- rb_enc_associate(opt->e_script, eenc);
-#endif
require_libraries();
tree = rb_parser_compile_string(parser, opt->script, opt->e_script, 1);
}
@@ -1248,13 +1017,6 @@
}
else {
int fd, mode = O_RDONLY;
-#if defined DOSISH || defined __CYGWIN__
- {
- const char *ext = strrchr(fname, '.');
- if (ext && STRCASECMP(ext, ".exe") == 0)
- mode |= O_BINARY;
- }
-#endif
if ((fd = open(fname, mode)) < 0) {
rb_load_fail(fname);
}
@@ -1269,11 +1031,6 @@
int no_src_enc = !opt->src.enc.name;
int no_ext_enc = !opt->ext.enc.name;
-#if !WITH_OBJC
- enc = rb_usascii_encoding();
- rb_funcall(f, rb_intern("set_encoding"), 1, rb_enc_from_encoding(enc));
-#endif
-
if (opt->xflag) {
forbid_setid("-x");
opt->xflag = Qfalse;
@@ -1351,20 +1108,11 @@
}
rb_io_ungetc(f, 0, INT2FIX('#'));
if (no_src_enc && opt->src.enc.name) {
-#if WITH_OBJC
opt->src.enc.enc = opt_enc_find(opt->src.enc.name);
src_encoding = opt->src.enc.enc;
-#else
- opt->src.enc.index = opt_enc_index(opt->src.enc.name);
- src_encoding_index = opt->src.enc.index;
-#endif
}
if (no_ext_enc && opt->ext.enc.name) {
-#if WITH_OBJC
opt->ext.enc.enc = opt_enc_find(opt->ext.enc.name);
-#else
- opt->ext.enc.index = opt_enc_index(opt->ext.enc.name);
-#endif
}
}
else if (!NIL_P(c)) {
@@ -1372,31 +1120,13 @@
}
require_libraries(); /* Why here? unnatural */
}
-#if WITH_OBJC
if (opt->src.enc.enc != NULL) {
enc = opt->src.enc.enc;
}
else {
enc = rb_locale_encoding();
}
-#else
- if (opt->src.enc.index >= 0) {
- enc = rb_enc_from_index(opt->src.enc.index);
- }
- else if (f == rb_stdin) {
- enc = rb_locale_encoding();
- }
- else {
- enc = rb_usascii_encoding();
- }
-#endif
-#if !WITH_OBJC
- rb_funcall(f, rb_intern("set_encoding"), 1, rb_enc_from_encoding(enc));
-#endif
tree = (NODE *)rb_parser_compile_file(parser, fname, f, line_start);
-#if !WITH_OBJC
- rb_funcall(f, rb_intern("set_encoding"), 1, rb_parser_encoding(parser));
-#endif
if (script && rb_parser_end_seen_p(parser)) {
rb_define_global_const("DATA", f);
}
@@ -1412,11 +1142,7 @@
struct cmdline_options opt;
MEMZERO(&opt, opt, 1);
-#if WITH_OBJC
opt.src.enc.enc = src_encoding;
-#else
- opt.src.enc.index = src_encoding_index;
-#endif
return load_file(rb_parser_new(), fname, 0, &opt);
}
@@ -1529,10 +1255,6 @@
euid = (int)geteuid();
gid = (int)getgid();
egid = (int)getegid();
-#ifdef VMS
- uid |= gid << 16;
- euid |= egid << 16;
-#endif
if (uid && (euid != uid || egid != gid)) {
rb_set_safe_level(1);
}
@@ -1541,12 +1263,15 @@
static void
forbid_setid(const char *s)
{
- if (euid != uid)
- rb_raise(rb_eSecurityError, "no %s allowed while running setuid", s);
- if (egid != gid)
- rb_raise(rb_eSecurityError, "no %s allowed while running setgid", s);
- if (rb_safe_level() > 0)
- rb_raise(rb_eSecurityError, "no %s allowed in tainted mode", s);
+ if (euid != uid) {
+ rb_raise(rb_eSecurityError, "no %s allowed while running setuid", s);
+ }
+ if (egid != gid) {
+ rb_raise(rb_eSecurityError, "no %s allowed while running setgid", s);
+ }
+ if (rb_safe_level() > 0) {
+ rb_raise(rb_eSecurityError, "no %s allowed in tainted mode", s);
+ }
}
static void
@@ -1558,12 +1283,15 @@
static VALUE
opt_W_getter(VALUE val, ID id)
{
- if (ruby_verbose == Qnil)
+ if (ruby_verbose == Qnil) {
return INT2FIX(0);
- if (ruby_verbose == Qfalse)
+ }
+ if (ruby_verbose == Qfalse) {
return INT2FIX(1);
- if (ruby_verbose == Qtrue)
+ }
+ if (ruby_verbose == Qtrue) {
return INT2FIX(2);
+ }
return Qnil; /* not reached */
}
@@ -1585,21 +1313,11 @@
rb_define_global_const("ARGV", rb_argv);
rb_global_variable(&rb_argv0);
-
-#ifdef MSDOS
- /*
- * There is no way we can refer to them from ruby, so close them to save
- * space.
- */
- (void)fclose(stdaux);
- (void)fclose(stdprn);
-#endif
}
void
ruby_set_argv(int argc, char **argv)
{
-#if 0 // TODO
int i;
VALUE av = rb_argv;
@@ -1616,7 +1334,6 @@
OBJ_FREEZE(arg);
rb_ary_push(av, arg);
}
-#endif
}
static VALUE
@@ -1667,7 +1384,6 @@
void
ruby_sysinit(int *argc, char ***argv)
{
-#if defined(__APPLE__) && (defined(__MACH__) || defined(__DARWIN__))
int i, n = *argc, len = 0;
char **v1 = *argv, **v2, *p;
@@ -1684,14 +1400,10 @@
}
v2[n] = 0;
*argv = v2;
-#elif defined(__MACOS__) && defined(__MWERKS__)
- *argc = ccommand(argv);
-#elif defined(_WIN32)
- void rb_w32_sysinit(int *argc, char ***argv);
- rb_w32_sysinit(argc, argv);
-#endif
+
origarg.argc = *argc;
origarg.argv = *argv;
+
#if !defined(PSTAT_SETCMD) && !defined(HAVE_SETPROCTITLE)
origarg.len = get_arglen(origarg.argc, origarg.argv);
#endif
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090313/1a39c074/attachment-0001.html>
More information about the macruby-changes
mailing list