diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-12-22 09:01:55 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-12-22 09:01:55 +0000 |
commit | 6d583574ab87c7cd18b66382c6892b545167bff6 (patch) | |
tree | 515b7c169ce2cd30fe085c5d861f5fad59aa76f7 | |
parent | e299d511db939232c628d6880e61c32e83937d66 (diff) |
1.1d1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1dev@357 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 29 | ||||
-rw-r--r-- | MANIFEST | 5 | ||||
-rw-r--r-- | Makefile.in | 3 | ||||
-rw-r--r-- | ToDo | 1 | ||||
-rw-r--r-- | config_h.dj | 2 | ||||
-rw-r--r-- | config_s.dj | 4 | ||||
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | defines.h | 6 | ||||
-rw-r--r-- | dln.c | 23 | ||||
-rw-r--r-- | enum.c | 4 | ||||
-rw-r--r-- | eval.c | 59 | ||||
-rw-r--r-- | ext/curses/curses.c | 8 | ||||
-rw-r--r-- | ext/curses/extconf.rb | 4 | ||||
-rw-r--r-- | ext/dbm/dbm.c | 30 | ||||
-rw-r--r-- | ext/extmk.rb.in | 48 | ||||
-rw-r--r-- | ext/gtk/gtk.c | 2 | ||||
-rw-r--r-- | hash.c | 180 | ||||
-rw-r--r-- | instruby.rb | 6 | ||||
-rw-r--r-- | intern.h | 3 | ||||
-rw-r--r-- | io.c | 4 | ||||
-rw-r--r-- | lib/delegate.rb | 28 | ||||
-rw-r--r-- | lib/getoptlong.rb | 473 | ||||
-rw-r--r-- | lib/mkmf.rb | 8 | ||||
-rw-r--r-- | missing/setenv.c | 4 | ||||
-rw-r--r-- | parse.y | 11 | ||||
-rw-r--r-- | process.c | 4 | ||||
-rw-r--r-- | re.c | 4 | ||||
-rw-r--r-- | regex.c | 173 | ||||
-rw-r--r-- | ruby.c | 18 | ||||
-rw-r--r-- | sample/test.rb | 16 | ||||
-rw-r--r-- | string.c | 6 | ||||
-rw-r--r-- | win32/Makefile | 5 |
32 files changed, 917 insertions, 256 deletions
@@ -1,3 +1,32 @@ +Tue Dec 22 18:01:08 1998 Yukihiro Matsumoto <matz@netlab.co.jp> + + * experimental version 1.1d1 released. + +Mon Dec 21 01:33:03 1998 Yukihiro Matsumoto <matz@netlab.co.jp> + + * eval.c (TMP_PROTECT): add volatile to ensure GC protection. + + * string.c (rb_str_gsub_bang): calculate buffer size properly. + + * parse.y (lex_get_str): needed to return Qnil at EOS. + + * eval.c (find_file): check policy modified, raise exception + immediately for tainted load_path. + + * hash.c (rb_f_setenv): do not depend on setenv() nor putenv(). + +Thu Dec 17 06:29:23 1998 Yukihiro Matsumoto <matz@netlab.co.jp> + + * ext/tk/tkutil.c (tk_s_new): use rb_obj_instance_eval(), instead + of rb_yield_0(). + + * eval.c (rb_f_require): forgot to call find_file in some cases. + + * eval.c (rb_f_require): `require "feature.so"' to load dynamic + libraries. old `require "feature.o"' is still OK. + + * eval.c (rb_eval): yield without value dumped core. + Wed Dec 16 16:28:31 1998 Yukihiro Matsumoto <matz@netlab.co.jp> * experimental version 1.1d0 (pre1.2) released. @@ -103,6 +103,7 @@ lib/finalize.rb lib/ftplib.rb lib/ftools.rb lib/getopts.rb +lib/getoptlong.rb lib/importenv.rb lib/jcode.rb lib/mailread.rb @@ -135,7 +136,7 @@ misc/README misc/inf-ruby.el misc/ruby-mode.el misc/rubydb2x.el -mics/rubydb3x.el +misc/rubydb3x.el missing/alloca.c missing/crypt.c missing/dir.h @@ -147,7 +148,6 @@ missing/memmove.c missing/mkdir.c missing/nt.c missing/nt.h -missing/setenv.c missing/strcasecmp.c missing/strchr.c missing/strdup.c @@ -193,6 +193,7 @@ sample/occur.rb sample/occur2.rb sample/philos.rb sample/pi.rb +sample/rename.rb sample/rbc.rb sample/rcs.awk sample/rcs.dat diff --git a/Makefile.in b/Makefile.in index ff1c2d1f58..0283a5e678 100644 --- a/Makefile.in +++ b/Makefile.in @@ -144,9 +144,6 @@ memmove.o: @srcdir@/missing/memmove.c mkdir.o: @srcdir@/missing/mkdir.c $(CC) $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/mkdir.c -setenv.o: @srcdir@/missing/setenv.c - $(CC) $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/setenv.c - vsnprintf.o: @srcdir@/missing/vsnprintf.c $(CC) $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/vsnprintf.c @@ -12,6 +12,7 @@ Hacking Interpreter * remove rb_eval() recursions * syntax tree -> bytecode ??? * scrambled script, or script filter +* regular expression bug /(?:\s+\d+){2}/ URGENT!! Extension Libraries diff --git a/config_h.dj b/config_h.dj index 2a81c29594..ebed8c446a 100644 --- a/config_h.dj +++ b/config_h.dj @@ -1,4 +1,4 @@ -#define THREAD 1 +#define USE_THREAD 1 #define SIZEOF_INT 4 #define SIZEOF_LONG 4 #define SIZEOF_VOIDP 4 diff --git a/config_s.dj b/config_s.dj index d6d3836613..e172e30e8b 100644 --- a/config_s.dj +++ b/config_s.dj @@ -1,7 +1,7 @@ s%@CFLAGS@%-g -O2%g s%@CPPFLAGS@%%g s%@CXXFLAGS@%%g -s%@DEFS@% -DTHREAD=1 -DSIZEOF_INT=4 -DSIZEOF_LONG=4 -DSIZEOF_VOIDP=4 -DHAVE_PROTOTYPES=1 -DHAVE_STDARG_PROTOTYPES=1 -DHAVE_ATTR_NORETURN=1 -DHAVE_DIRENT_H=1 -DSTDC_HEADERS=1 -DHAVE_STDLIB_H=1 -DHAVE_UNISTD_H=1 -DHAVE_LIMITS_H=1 -DHAVE_SYS_FILE_H=1 -DHAVE_SYS_IOCTL_H=1 -DHAVE_PWD_H=1 -DHAVE_SYS_TIME_H=1 -DHAVE_SYS_TIMES_H=1 -DHAVE_SYS_PARAM_H=1 -DHAVE_SYS_WAIT_H=1 -DHAVE_STRING_H=1 -DHAVE_UTIME_H=1 -DHAVE_MEMORY_H=1 -DHAVE_DIRECT_H=1 -DHAVE_ST_BLKSIZE=1 -DHAVE_ST_RDEV=1 -DGETGROUPS_T=gid_t -DRETSIGTYPE=void -DHAVE_ALLOCA=1 -Dvfork=fork -DHAVE_DUP2=1 -DHAVE_SETENV=1 -DHAVE_MEMMOVE=1 -DHAVE_MKDIR=1 -DHAVE_STRCASECMP=1 -DHAVE_STRERROR=1 -DHAVE_STRFTIME=1 -DHAVE_STRCHR=1 -DHAVE_STRSTR=1 -DHAVE_STRTOUL=1 -DHAVE_STRDUP=1 -DHAVE_FMOD=1 -DHAVE_RANDOM=1 -DHAVE_WAITPID=1 -DHAVE_GETCWD=1 -DHAVE_TRUNCATE=1 -DHAVE_CHSIZE=1 -DHAVE_TIMES=1 -DHAVE_UTIMES=1 -DHAVE_FCNTL=1 -DHAVE_SETITIMER=1 -DHAVE_GETGROUPS=1 -DHAVE_SIGPROCMASK=1 -DHAVE_SIGACTION=1 -DHAVE_SETSID=1 -DPOSIX_SIGNAL=1 -DBSD_SETPGRP=setpgrp -DRSHIFT=\(x,y\)\ \(\(x\)\>\>y\) -DFILE_COUNT=_cnt -DDLEXT=\".so\" -DRUBY_LIB=\"/usr/local/lib/ruby\" -DRUBY_SITE_LIB=\"/usr/local/lib/ruby/site_ruby\" -DRUBY_ARCHLIB=\"/usr/local/lib/ruby/i386-djgpp\" -DRUBY_SITE_ARCHLIB=\"/usr/local/lib/ruby/site_ruby/i386-djgpp\" -DRUBY_PLATFORM=\"i386-djgpp\" %g +s%@DEFS@% -DUSE_THREAD=1 -DSIZEOF_INT=4 -DSIZEOF_LONG=4 -DSIZEOF_VOIDP=4 -DHAVE_PROTOTYPES=1 -DHAVE_STDARG_PROTOTYPES=1 -DHAVE_ATTR_NORETURN=1 -DHAVE_DIRENT_H=1 -DSTDC_HEADERS=1 -DHAVE_STDLIB_H=1 -DHAVE_UNISTD_H=1 -DHAVE_LIMITS_H=1 -DHAVE_SYS_FILE_H=1 -DHAVE_SYS_IOCTL_H=1 -DHAVE_PWD_H=1 -DHAVE_SYS_TIME_H=1 -DHAVE_SYS_TIMES_H=1 -DHAVE_SYS_PARAM_H=1 -DHAVE_SYS_WAIT_H=1 -DHAVE_STRING_H=1 -DHAVE_UTIME_H=1 -DHAVE_MEMORY_H=1 -DHAVE_DIRECT_H=1 -DHAVE_ST_BLKSIZE=1 -DHAVE_ST_RDEV=1 -DGETGROUPS_T=gid_t -DRETSIGTYPE=void -DHAVE_ALLOCA=1 -Dvfork=fork -DHAVE_DUP2=1 -DHAVE_SETENV=1 -DHAVE_MEMMOVE=1 -DHAVE_MKDIR=1 -DHAVE_STRCASECMP=1 -DHAVE_STRERROR=1 -DHAVE_STRFTIME=1 -DHAVE_STRCHR=1 -DHAVE_STRSTR=1 -DHAVE_STRTOUL=1 -DHAVE_STRDUP=1 -DHAVE_FMOD=1 -DHAVE_RANDOM=1 -DHAVE_WAITPID=1 -DHAVE_GETCWD=1 -DHAVE_TRUNCATE=1 -DHAVE_CHSIZE=1 -DHAVE_TIMES=1 -DHAVE_UTIMES=1 -DHAVE_FCNTL=1 -DHAVE_SETITIMER=1 -DHAVE_GETGROUPS=1 -DHAVE_SIGPROCMASK=1 -DHAVE_SIGACTION=1 -DHAVE_SETSID=1 -DPOSIX_SIGNAL=1 -DBSD_SETPGRP=setpgrp -DRSHIFT=\(x,y\)\ \(\(x\)\>\>y\) -DFILE_COUNT=_cnt -DDLEXT=\".so\" -DRUBY_LIB=\"/usr/local/lib/ruby\" -DRUBY_SITE_LIB=\"/usr/local/lib/ruby/site_ruby\" -DRUBY_ARCHLIB=\"/usr/local/lib/ruby/i386-djgpp\" -DRUBY_SITE_ARCHLIB=\"/usr/local/lib/ruby/site_ruby/i386-djgpp\" -DRUBY_PLATFORM=\"i386-djgpp\" %g s%@LDFLAGS@%%g s%@LIBS@%-lm %g s%@exec_prefix@%${prefix}%g @@ -46,4 +46,6 @@ s%@setup@%Setup%g s%@LIBRUBY@%libruby.a%g s%@LIBRUBYARG@%libruby.a%g s%@SOLIBS@%%g +s%@srcdir%.%g s%@arch@%i386-djgpp%g +ac_given_srcdir=. diff --git a/configure.in b/configure.in index 33b43deed2..09fb25fdeb 100644 --- a/configure.in +++ b/configure.in @@ -170,7 +170,7 @@ AC_TYPE_SIGNAL AC_FUNC_ALLOCA AC_FUNC_VFORK AC_FUNC_MEMCMP -AC_REPLACE_FUNCS(dup2 setenv memmove mkdir strcasecmp strerror strftime\ +AC_REPLACE_FUNCS(dup2 memmove mkdir strcasecmp strerror strftime\ strchr strstr strtoul strdup crypt flock vsnprintf) AC_CHECK_FUNCS(fmod killpg drand48 random wait4 waitpid syscall getcwd\ truncate chsize times utimes fcntl lockf setitimer\ @@ -44,6 +44,12 @@ #define FLUSH_REGISTER_WINDOWS /* empty */ #endif +#if defined(MSDOS) || defined(NT) || defined(__human68k__) || defined(__MACOS__) +#define RUBY_LIB_SEP ";" +#else +#define RUBY_LIB_SEP ":" +#endif + #if defined(__human68k__) || defined(__CYGWIN32__) #undef HAVE_RANDOM #undef HAVE_SETITIMER @@ -1354,7 +1354,7 @@ dln_load(file) return ; } #else/* OPENSTEP dyld functions */ - { + { int dyld_result ; NSObjectFileImage obj_file ; /* handle, but not use it */ /* "file" is module file name . @@ -1363,29 +1363,24 @@ dln_load(file) void (*init_fct)(); - dyld_result = NSCreateObjectFileImageFromFile( file, &obj_file ); + dyld_result = NSCreateObjectFileImageFromFile( file, &obj_file ); - if (dyld_result != NSObjectFileImageSuccess) - { - LoadError("Failed to load %.200s", file); - } - - NSLinkModule(obj_file, file, Qtrue); + if (dyld_result != NSObjectFileImageSuccess) { + rb_loaderror("Failed to load %.200s", file); + } + NSLinkModule(obj_file, file, TRUE); /* lookup the initial function */ - /*NSIsSymbolNameDefined require function name without "_" */ - if( NSIsSymbolNameDefined( buf + 1 ) ) - { - LoadError("Failed to lookup Init function %.200s",file); + /*NSIsSymbolNameDefined require function name without "_" */ + if( NSIsSymbolNameDefined( buf + 1 ) ) { + rb_loaderror("Failed to lookup Init function %.200s",file); } /* NSLookupAndBindSymbol require function name with "_" !! */ - init_fct = NSAddressOfSymbol( NSLookupAndBindSymbol( buf ) ); (*init_fct)(); - return ; } #endif /* rld or dyld */ @@ -343,10 +343,10 @@ each_with_index_i(val, indexp) VALUE val; int *indexp; { -#if 0 +#if 1 rb_yield(rb_assoc_new(val, INT2FIX(*indexp))); #else - rb_yield(rb_ary_concat(val, INT2FIX(*indexp))); + rb_yield(rb_ary_concat(rb_Array(val), INT2FIX(*indexp))); #endif (*indexp)++; return Qnil; @@ -45,12 +45,6 @@ char *strrchr _((char*,char)); #endif #endif -#if defined(MSDOS) || defined(NT) || defined(__human68k__) || defined(__MACOS__) -#define RUBY_LIB_SEP ";" -#else -#define RUBY_LIB_SEP ":" -#endif - VALUE rb_cProc; static VALUE rb_cBinding; static VALUE proc_call _((VALUE,VALUE)); @@ -856,6 +850,7 @@ error_print() #if !defined(NT) && !defined(__MACOS__) extern char **environ; #endif +char **rb_origenviron; void rb_call_inits _((void)); void Init_stack _((void)); @@ -872,6 +867,12 @@ ruby_init() ruby_frame = top_frame = &frame; ruby_iter = &iter; +#ifdef __MACOS__ + rb_origenviron = 0; +#else + rb_origenviron = environ; +#endif + Init_heap(); PUSH_SCOPE(); ruby_scope->local_vars = 0; @@ -1281,10 +1282,10 @@ rb_mod_alias_method(mod, newname, oldname) } #if defined(C_ALLOCA) && defined(USE_THREAD) -# define TMP_PROTECT NODE *__protect_tmp=0 -# define TMP_ALLOC(type,n) \ - (__protect_tmp = rb_node_newnode(NODE_ALLOCA, \ - rb_str_new(0,sizeof(type)*(n)),0,__protect_tmp), \ +# define TMP_PROTECT NODE * volatile __protect_tmp=0 +# define TMP_ALLOC(type,n) \ + (__protect_tmp = rb_node_newnode(NODE_ALLOCA,\ + rb_str_new(0,sizeof(type)*(n)),0,__protect_tmp),\ (void*)RSTRING(__protect_tmp->nd_head)->ptr) #else # define TMP_PROTECT typedef int foobazzz @@ -1920,9 +1921,16 @@ rb_eval(self, node) break; case NODE_YIELD: - result = rb_eval(self, node->nd_stts); - if (nd_type(node->nd_stts) == NODE_RESTARGS && RARRAY(result)->len == 1) { - result = RARRAY(result)->ptr[0]; + if (node->nd_stts) { + result = rb_eval(self, node->nd_stts); + if (nd_type(node->nd_stts) == NODE_RESTARGS && + RARRAY(result)->len == 1) + { + result = RARRAY(result)->ptr[0]; + } + } + else { + result = Qnil; } result = rb_yield_0(result, 0, 0); break; @@ -4215,7 +4223,7 @@ yield_under(under, self) return exec_under(yield_under_i, under, self); } -static VALUE +VALUE rb_obj_instance_eval(argc, argv, self) int argc; VALUE *argv; @@ -4307,7 +4315,6 @@ find_file(file) char *file; { extern VALUE rb_load_path; - VALUE vpath; char *path; if (is_absolute_path(file)) { @@ -4319,6 +4326,7 @@ find_file(file) } if (rb_load_path) { + volatile VALUE vpath; int i; Check_Type(rb_load_path, T_ARRAY); @@ -4328,8 +4336,8 @@ find_file(file) vpath = rb_ary_join(rb_load_path, rb_str_new2(RUBY_LIB_SEP)); Check_SafeStr(vpath); path = RSTRING(vpath)->ptr; - if (safe_level >= 2) { - rb_path_check(path); + if (safe_level >= 2 && !rb_path_check(path)) { + rb_raise(rb_eSecurityError, "loading from unsefe path %s", vpath); } } else { @@ -4454,7 +4462,7 @@ rb_provided(feature) if (strcmp(f, feature) == 0) return Qtrue; len = strlen(feature); if (strncmp(f, feature, len) == 0 - && (strcmp(f+len, ".rb") == 0 ||strcmp(f+len, ".o") == 0)) { + && (strcmp(f+len, ".rb") == 0 ||strcmp(f+len, ".so") == 0)) { return Qtrue; } p++; @@ -4475,11 +4483,11 @@ rb_provide(feature) if (!rb_provided(feature)) { ext = strrchr(feature, '.'); - if (strcmp(DLEXT, ext) == 0) { - buf = ALLOCA_N(char, strlen(feature)+1); + if (ext && strcmp(DLEXT, ext) == 0) { + buf = ALLOCA_N(char, strlen(feature)+4); strcpy(buf, feature); ext = strrchr(buf, '.'); - strcpy(ext, ".o"); + strcpy(ext, ".so"); feature = buf; } rb_ary_push(rb_features, rb_str_new2(feature)); @@ -4505,15 +4513,16 @@ rb_f_require(obj, fname) file = find_file(file); if (file) goto rb_load; } - else if (strcmp(".o", ext) == 0) { + else if (strcmp(".so", ext) == 0 || strcmp(".o", ext) == 0) { file = feature = RSTRING(fname)->ptr; - if (strcmp(".o", DLEXT) != 0) { + if (strcmp(ext, DLEXT) != 0) { buf = ALLOCA_N(char, strlen(file)+sizeof(DLEXT)+1); strcpy(buf, feature); ext = strrchr(buf, '.'); strcpy(ext, DLEXT); - file = find_file(buf); + file = buf; } + file = find_file(file); if (file) goto dyna_load; } else if (strcmp(DLEXT, ext) == 0) { @@ -6490,7 +6499,7 @@ catch_timer(sig) } } #else -int thread_tick = rb_THREAD_TICK; +int rb_thread_tick = THREAD_TICK; #endif static VALUE rb_thread_raise _((int, VALUE*, VALUE)); diff --git a/ext/curses/curses.c b/ext/curses/curses.c index 3d3991373a..f3d1bc0970 100644 --- a/ext/curses/curses.c +++ b/ext/curses/curses.c @@ -360,7 +360,7 @@ curses_getstr(obj) { char rtn[1024]; /* This should be big enough.. I hope */ getstr(rtn); - return rb_str_taint(rb_str_new2(rtn)); + return rb_tainted_str_new2(rtn); } /* def delch */ @@ -377,7 +377,9 @@ static VALUE curses_deleteln(obj) VALUE obj; { +#ifdef HAVE_DELETELN deleteln(); +#endif return Qnil; } @@ -729,7 +731,7 @@ window_getstr(obj) GetWINDOW(obj, winp); wgetstr(winp->window, rtn); - return rb_str_taint(rb_str_new2(rtn)); + return rb_tainted_str_new2(rtn); } /* def delch */ @@ -749,10 +751,12 @@ static VALUE window_deleteln(obj) VALUE obj; { +#ifdef HAVE_WDELETELN struct windata *winp; GetWINDOW(obj, winp); wdeleteln(winp->window); +#endif return Qnil; } diff --git a/ext/curses/extconf.rb b/ext/curses/extconf.rb index 244c9085c4..442a9424a2 100644 --- a/ext/curses/extconf.rb +++ b/ext/curses/extconf.rb @@ -2,6 +2,8 @@ require 'mkmf' $CFLAGS="-I/usr/include/ncurses -I/usr/local/include/ncurses" $LDFLAGS="-L/usr/local/lib" make=FALSE + +have_library("mytinfo", "tgetent") if /bow/ =~ PLATFORM if have_header("ncurses.h") and have_library("ncurses", "initscr") make=TRUE elsif have_header("ncurses/curses.h") and have_library("ncurses", "initscr") @@ -15,7 +17,7 @@ else end if make then - for f in ["isendwin", "ungetch", "beep", "doupdate", "flash"] + for f in %w(isendwin ungetch beep doupdate flash deleteln wdeleteln) have_func(f) end create_makefile("curses") diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c index 4a3d1127e6..2764a325e1 100644 --- a/ext/dbm/dbm.c +++ b/ext/dbm/dbm.c @@ -121,7 +121,7 @@ fdbm_fetch(obj, keystr) if (value.dptr == 0) { return Qnil; } - return rb_str_taint(rb_str_new(value.dptr, value.dsize)); + return rb_tainted_str_new(value.dptr, value.dsize); } static VALUE @@ -191,8 +191,8 @@ fdbm_shift(obj) val = dbm_fetch(dbm, key); dbm_delete(dbm, key); - keystr = rb_str_taint(rb_str_new(key.dptr, key.dsize)); - valstr = rb_str_taint(rb_str_new(val.dptr, val.dsize)); + keystr = rb_tainted_str_new(key.dptr, key.dsize); + valstr = rb_tainted_str_new(val.dptr, val.dsize); return rb_assoc_new(keystr, valstr); } @@ -210,8 +210,8 @@ fdbm_delete_if(obj) dbm = dbmp->di_dbm; for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { val = dbm_fetch(dbm, key); - keystr = rb_str_taint(rb_str_new(key.dptr, key.dsize)); - valstr = rb_str_taint(rb_str_new(val.dptr, val.dsize)); + keystr = rb_tainted_str_new(key.dptr, key.dsize); + valstr = rb_tainted_str_new(val.dptr, val.dsize); if (RTEST(rb_yield(rb_assoc_new(keystr, valstr)))) { if (dbm_delete(dbm, key)) { rb_raise(rb_eRuntimeError, "dbm_delete failed"); @@ -255,8 +255,8 @@ fdbm_invert(obj) dbm = dbmp->di_dbm; for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { val = dbm_fetch(dbm, key); - keystr = rb_str_taint(rb_str_new(key.dptr, key.dsize)); - valstr = rb_str_taint(rb_str_new(val.dptr, val.dsize)); + keystr = rb_tainted_str_new(key.dptr, key.dsize); + valstr = rb_tainted_str_new(val.dptr, val.dsize); rb_hash_aset(hash, valstr, keystr); } return obj; @@ -396,7 +396,7 @@ fdbm_each_value(obj) dbm = dbmp->di_dbm; for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { val = dbm_fetch(dbm, key); - rb_yield(rb_str_taint(rb_str_new(val.dptr, val.dsize))); + rb_yield(rb_tainted_str_new(val.dptr, val.dsize)); } return obj; } @@ -412,7 +412,7 @@ fdbm_each_key(obj) GetDBM(obj, dbmp); dbm = dbmp->di_dbm; for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { - rb_yield(rb_str_taint(rb_str_new(key.dptr, key.dsize))); + rb_yield(rb_tainted_str_new(key.dptr, key.dsize)); } return obj; } @@ -431,8 +431,8 @@ fdbm_each_pair(obj) for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { val = dbm_fetch(dbm, key); - keystr = rb_str_taint(rb_str_new(key.dptr, key.dsize)); - valstr = rb_str_taint(rb_str_new(val.dptr, val.dsize)); + keystr = rb_tainted_str_new(key.dptr, key.dsize); + valstr = rb_tainted_str_new(val.dptr, val.dsize); rb_yield(rb_assoc_new(keystr, valstr)); } @@ -453,7 +453,7 @@ fdbm_keys(obj) ary = rb_ary_new(); for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { - rb_ary_push(ary, rb_str_taint(rb_str_new(key.dptr, key.dsize))); + rb_ary_push(ary, rb_tainted_str_new(key.dptr, key.dsize)); } return ary; @@ -474,7 +474,7 @@ fdbm_values(obj) ary = rb_ary_new(); for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { val = dbm_fetch(dbm, key); - rb_ary_push(ary, rb_str_taint(rb_str_new(val.dptr, val.dsize))); + rb_ary_push(ary, rb_tainted_str_new(val.dptr, val.dsize)); } return ary; @@ -537,8 +537,8 @@ fdbm_to_a(obj) ary = rb_ary_new(); for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { val = dbm_fetch(dbm, key); - rb_ary_push(ary, rb_assoc_new(rb_str_taint(rb_str_new(key.dptr, key.dsize)), - rb_str_taint(rb_str_new(val.dptr, val.dsize)))); + rb_ary_push(ary, rb_assoc_new(rb_tainted_str_new(key.dptr, key.dsize), + rb_tainted_str_new(val.dptr, val.dsize))); } return ary; diff --git a/ext/extmk.rb.in b/ext/extmk.rb.in index e1623529b6..33580e99fc 100644 --- a/ext/extmk.rb.in +++ b/ext/extmk.rb.in @@ -135,26 +135,34 @@ def have_library(lib, func) end end - cfile = open("conftest.c", "w") - cfile.printf "\ + if func && func != "" + cfile = open("conftest.c", "w") + cfile.printf "\ int main() { return 0; } int t() { %s(); return 0; } ", func - cfile.close + cfile.close - begin + begin + if $libs + libs = "-l" + lib + " " + $libs + else + libs = "-l" + lib + end + unless try_link(libs) + $lib_cache[lib] = 'no' + $cache_mod = TRUE + return FALSE + end + ensure + system "rm -f conftest*" + end + else if $libs libs = "-l" + lib + " " + $libs else libs = "-l" + lib end - unless try_link(libs) - $lib_cache[lib] = 'no' - $cache_mod = TRUE - return FALSE - end - ensure - system "rm -f conftest*" end $libs = libs @@ -299,7 +307,7 @@ archdir = $(pkglibdir)/@arch@ #### End of system configuration section. #### " - mfile.printf "LOCAL_LIBS = %s\n", $local_libs if $local_libs + mfile.printf "LOCAL_LIBS = %s\n", $local_libs unless $local_libs == "" mfile.printf "LIBS = %s\n", $libs mfile.printf "OBJS = " if !$objs then @@ -313,7 +321,7 @@ archdir = $(pkglibdir)/@arch@ mfile.printf $objs.join(" ") mfile.printf "\n" - mfile.printf << EOS + mfile.printf <<EOS TARGET = #{target}.#{$static ? "a" : "@DLEXT@"} INSTALL = #{$dots}@INSTALL@ @@ -354,7 +362,7 @@ $(TARGET): $(OBJS) elsif "@DLEXT@" != "o" mfile.printf "\ $(TARGET): $(OBJS) - $(LDSHARED) $(DLDFLAGS) -o $(TARGET) $(OBJS) $(LOCAL_LIBS) $(LIBS) + $(LDSHARED) $(DLDFLAGS) -o $(TARGET) $(OBJS) $(LIBS) $(LOCAL_LIBS) " elsif not File.exist?(target + ".c") and not File.exist?(target + ".cc") if PLATFORM == "m68k-human" @@ -410,9 +418,9 @@ def extmake(target) $objs = nil $libs = PLATFORM =~ /cygwin32|beos|openstep|nextstep|rhapsody/ ? nil : "-lc" - $local_libs = nil # to be assigned in extconf.rb - $CFLAGS = nil - $LDFLAGS = nil + $local_libs = "" # to be assigned in extconf.rb + $CFLAGS = "" + $LDFLAGS = "" begin system "mkdir", target unless File.directory?(target) @@ -444,10 +452,10 @@ def extmake(target) end end if $static - $extlibs = "" unless $extlibs - $extlibs += " " + $LDFLAGS if $LDFLAGS - $extlibs += " " + $local_libs if $local_libs + $extlibs ||= "" + $extlibs += " " + $LDFLAGS unless $LDFLAGS == "" $extlibs += " " + $libs if $libs + $extlibs += " " + $local_libs unless $local_libs == "" end ensure Dir.chdir ".." diff --git a/ext/gtk/gtk.c b/ext/gtk/gtk.c index 1afe083d9e..28a4bd17b3 100644 --- a/ext/gtk/gtk.c +++ b/ext/gtk/gtk.c @@ -988,7 +988,7 @@ gdkgc_set_function(self, func) GdkFunction f; f = (GdkFunction) NUM2INT(func); if (f != GDK_COPY && f != GDK_INVERT && f != GDK_XOR) - ArgError("function out of range"); + rb_raise(rb_eArgError, "function out of range"); gdk_gc_set_function(get_gdkgc(self), f); return func; @@ -823,12 +823,13 @@ rb_hash_update(hash1, hash2) return hash1; } -#ifndef __MACOS__ /* environment variables nothing on MacOS. */ +#ifndef __MACOS__ /* no environment variables on MacOS. */ static int path_tainted = -1; #ifndef NT extern char **environ; #endif +static char **origenviron; static VALUE env_delete(obj, name) @@ -838,9 +839,10 @@ env_delete(obj, name) char *nam, *val = 0; rb_secure(4); - nam = STR2CSTR(name); - len = strlen(nam); + Check_SafeStr(name); + nam = RSTRING(name)->ptr; if (strcmp(nam, "PATH") == 0) path_tainted = 0; + len = strlen(nam); for(i=0; environ[i]; i++) { if (strncmp(environ[i], nam, len) == 0 && environ[i][len] == '=') { val = environ[i]+len+1; @@ -895,7 +897,7 @@ path_check_1(path) char *s; for (;;) { - if (stat(path, &st) == 0 && (st.st_mode & 2)) { + if (stat(path, &st) == 0 && (st.st_mode & 002)) { return 0; } s = strrchr(path, '/'); @@ -906,19 +908,17 @@ path_check_1(path) } } -void +int rb_path_check(path) char *path; { - char *p = path; - char *pend = strchr(path, ':'); + char *p, *pend; + const char sep = *RUBY_LIB_SEP; - if (!path) { - path_tainted = 0; - } + if (!path) return 1; p = path; - pend = strchr(path, ':'); + pend = strchr(path, sep); for (;;) { int safe; @@ -926,26 +926,158 @@ rb_path_check(path) if (pend) *pend = '\0'; safe = path_check_1(p); if (!pend) break; - *pend = ':'; + *pend = sep; if (!safe) { - path_tainted = 1; - return; + return 0; } p = pend + 1; - pend = strchr(p, ':'); + pend = strchr(p, sep); } - path_tainted = 0; + return 1; +} + +static void +path_tainted_p(path) + char *path; +{ + path_tainted = rb_path_check(path)?0:1; } int rb_env_path_tainted() { if (path_tainted < 0) { - rb_path_check(getenv("PATH")); + path_tainted_p(getenv("PATH")); } return path_tainted; } +static int +envix(nam) +char *nam; +{ + register int i, len = strlen(nam); + + for (i = 0; environ[i]; i++) { + if ( +#ifdef WIN32 + strnicmp(environ[i],nam,len) == 0 +#else + memcmp(environ[i],nam,len) == 0 +#endif + && environ[i][len] == '=') + break; /* memcmp must come first to avoid */ + } /* potential SEGV's */ + return i; +} + +static void +my_setenv(name, value) + char *name; + char *value; +{ +#ifdef WIN32 +#ifdef USE_WIN32_RTL_ENV + register char *envstr; + STRLEN namlen = strlen(name); + STRLEN vallen; + char *oldstr = environ[envix(name)]; + + /* putenv() has totally broken semantics in both the Borland + * and Microsoft CRTLs. They either store the passed pointer in + * the environment without making a copy, or make a copy and don't + * free it. And on top of that, they dont free() old entries that + * are being replaced/deleted. This means the caller must + * free any old entries somehow, or we end up with a memory + * leak every time setenv() is called. One might think + * one could directly manipulate environ[], like the UNIX code + * above, but direct changes to environ are not allowed when + * calling putenv(), since the RTLs maintain an internal + * *copy* of environ[]. Bad, bad, *bad* stink. + * GSAR 97-06-07 + */ + + if (!value) { + if (!oldstr) + return; + value = ""; + vallen = 0; + } + else + vallen = strlen(val); + envstr = ALLOC_N(char, namelen + vallen + 3); + sprintf(envstr,"%s=%s",name,value); + putenv(envstr); + if (oldstr) free(oldstr); +#ifdef _MSC_VER + free(envstr); /* MSVCRT leaks without this */ +#endif + +#else /* !USE_WIN32_RTL_ENV */ + + /* The sane way to deal with the environment. + * Has these advantages over putenv() & co.: + * * enables us to store a truly empty value in the + * environment (like in UNIX). + * * we don't have to deal with RTL globals, bugs and leaks. + * * Much faster. + * Why you may want to enable USE_WIN32_RTL_ENV: + * * environ[] and RTL functions will not reflect changes, + * which might be an issue if extensions want to access + * the env. via RTL. This cuts both ways, since RTL will + * not see changes made by extensions that call the Win32 + * functions directly, either. + * GSAR 97-06-07 + */ + SetEnvironmentVariable(name,value); +#endif + +#else /* WIN32 */ + + register int i=envix(name); /* where does it go? */ + + if (environ == origenviron) { /* need we copy environment? */ + int j; + int max; + char **tmpenv; + + for (max = i; environ[max]; max++) ; + tmpenv = ALLOC_N(char*, max+2); + for (j=0; j<max; j++) /* copy environment */ + tmpenv[j] = strdup(environ[j]); + tmpenv[max] = 0; + environ = tmpenv; /* tell exec where it is now */ + } + if (!value) { + while (environ[i]) { + environ[i] = environ[i+1]; + i++; + } + return; + } + if (!environ[i]) { /* does not exist yet */ + REALLOC_N(environ, char*, i+2); /* just expand it a bit */ + environ[i+1] = 0; /* make sure it's null terminated */ + } + else { + free(environ[i]); + } + environ[i] = ALLOC_N(char, strlen(name) + strlen(value) + 2); +#ifndef MSDOS + sprintf(environ[i],"%s=%s",name,value); /* all that work just for this */ +#else + /* MS-DOS requires environment variable names to be in uppercase */ + /* [Tom Dinger, 27 August 1990: Well, it doesn't _require_ it, but + * some utilities and applications may break because they only look + * for upper case strings. (Fixed strupr() bug here.)] + */ + strcpy(environ[i],name); strupr(environ[i]); + sprintf(environ[i] + strlen(name),"=%s", value); +#endif /* MSDOS */ + +#endif /* WIN32 */ +} + static VALUE rb_f_setenv(obj, name, value) VALUE obj, name, value; @@ -954,27 +1086,28 @@ rb_f_setenv(obj, name, value) rb_raise(rb_eSecurityError, "cannot change environment variable"); } - Check_SafeStr(name); if (NIL_P(value)) { env_delete(obj, name); return Qnil; } + Check_SafeStr(name); Check_SafeStr(value); if (strlen(RSTRING(name)->ptr) != RSTRING(name)->len) rb_raise(rb_eArgError, "Bad environment name"); if (strlen(RSTRING(value)->ptr) != RSTRING(value)->len) rb_raise(rb_eArgError, "Bad environment value"); - - setenv(RSTRING(name)->ptr, RSTRING(value)->ptr, 1); + + my_setenv(RSTRING(name)->ptr, RSTRING(value)->ptr); if (strcmp(RSTRING(name)->ptr, "PATH") == 0) { if (rb_obj_tainted(value)) { /* already tainted, no check */ path_tainted = 1; return Qtrue; } - - rb_path_check(RSTRING(name)->ptr); + else { + path_tainted_p(RSTRING(value)->ptr); + } } return Qtrue; } @@ -1182,7 +1315,7 @@ env_to_hash(obj) return hash; } -#endif /* ifndef __MACOS__ environment variables nothing on MacOS. */ +#endif /* ifndef __MACOS__ no environment variables on MacOS. */ void Init_Hash() @@ -1245,6 +1378,7 @@ Init_Hash() rb_define_method(rb_cHash,"value?", rb_hash_has_value, 1); #ifndef __MACOS__ /* environment variables nothing on MacOS. */ + origenviron = environ; envtbl = rb_obj_alloc(rb_cObject); rb_extend_object(envtbl, rb_mEnumerable); diff --git a/instruby.rb b/instruby.rb index 93a6557d1f..8a66a079db 100644 --- a/instruby.rb +++ b/instruby.rb @@ -25,19 +25,21 @@ File.install "ruby#{binsuffix}", for dll in Dir['*.dll'] File.install dll, "#{bindir}/#{dll}", 0755, TRUE end -File.makedirs "#{libdir}", TRUE +File.makedirs libdir, TRUE +File.makedirs archdir, TRUE for lib in ["libruby.so", "libruby.so.LIB"] if File.exist? lib File.install lib, "#{libdir}", 0644, TRUE end end -File.makedirs libdir, TRUE Dir.chdir "ext" system "../miniruby#{binsuffix} extmk.rb install" Dir.chdir CONFIG["srcdir"] for f in Dir["lib/*.rb"] File.install f, "#{libdir}", 0644, TRUE end + +File.makedirs(archdir,TRUE) for f in Dir["*.h"] File.install f, "#{archdir}", 0644, TRUE end @@ -109,6 +109,7 @@ VALUE rb_apply _((VALUE, ID, VALUE)); VALUE rb_funcall2 _((VALUE, ID, int, VALUE*)); void rb_backtrace _((void)); ID rb_frame_last_func _((void)); +VALUE rb_obj_instance_eval _((int, VALUE*, VALUE)); void rb_load _((VALUE, VALUE)); void rb_provide _((char*)); VALUE rb_f_require _((VALUE, VALUE)); @@ -149,7 +150,7 @@ VALUE rb_hash_new _((void)); VALUE rb_hash_freeze _((VALUE)); VALUE rb_hash_aref _((VALUE, VALUE)); VALUE rb_hash_aset _((VALUE, VALUE, VALUE)); -void rb_path_check _((char *)); +int rb_path_check _((char *)); int rb_env_path_tainted _((void)); /* io.c */ extern VALUE rb_fs; @@ -61,6 +61,8 @@ struct timeval { #include <net/socket.h> #endif +#include "util.h" + VALUE rb_cIO; VALUE rb_eEOFError; VALUE rb_eIOError; @@ -2278,7 +2280,7 @@ rb_io_ctl(io, req, arg, io_p) # endif TRAP_END; #else - if (!rb_io_p) { + if (!io_p) { rb_notimplement(); } TRAP_BEG; diff --git a/lib/delegate.rb b/lib/delegate.rb index 594c500cab..749f2e62ad 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -30,9 +30,9 @@ class Delegator for method in obj.methods next if preserved.include? method eval <<-EOS - def self.#{method}(*args, &block) + def self.#{method}(*args, &block) begin - __getobj__.__send__(:#{method}, *args, &block) + __getobj__.__send__(:{method}, *args, &block) rescue Exception c = -caller(0).size if /:in `__getobj__'$/ =~ $@[c-1] #` @@ -44,8 +44,8 @@ class Delegator $@[c,n] = nil raise end - end - EOS + end + EOS end end @@ -88,18 +88,18 @@ def DelegateClass(superclass) EOS for method in methods klass.module_eval <<-EOS - def #{method}(*args, &block) - begin - @obj.__send__(:#{method}, *args, &block) - rescue - $@[0,2] = nil - raise + def #{method}(*args, &block) + begin + @obj.__send__(:{method}, *args, &block) + rescue + $@[0,2] = nil + raise + end + end + EOS end - end - EOS + return klass; end - return klass; -end if __FILE__ == $0 class ExtArray<DelegateClass(Array) diff --git a/lib/getoptlong.rb b/lib/getoptlong.rb new file mode 100644 index 0000000000..98a73ae3db --- /dev/null +++ b/lib/getoptlong.rb @@ -0,0 +1,473 @@ +# -*- Ruby -*- +# Copyright (C) 1998 Motoyuki Kasahara +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# + +# +# Documents and latest version of `getoptlong.rb' are found at: +# http://www.sra.co.jp/people/m-kasahr/ruby/getoptlong/ +# + +# +# Parse command line options just like GNU getopt_long(). +# +class GetoptLong + # + # Orderings. + # + ORDERINGS = [REQUIRE_ORDER = 0, PERMUTE = 1, RETURN_IN_ORDER = 2] + + # + # Argument flags. + # + ARGUMENT_FLAGS = [NO_ARGUMENT = 0, REQUIRED_ARGUMENT = 1, + OPTIONAL_ARGUMENT = 2] + + # + # Status codes. + # + STATUS_YET, STATUS_STARTED, STATUS_TERMINATED = 0..2 + + # + # Error types. + # + class AmbigousOption < StandardError; end + class NeedlessArgument < StandardError; end + class MissingArgument < StandardError; end + class InvalidOption < StandardError; end + + # + # Initializer. + # + def initialize(*arguments) + # + # Current ordering. + # + if ENV.include?('POSIXLY_CORRECT') + @ordering = REQUIRE_ORDER + else + @ordering = PERMUTE + end + + # + # Hash table of option names. + # Keyes of the table are option names, and their values are canonical + # names of the options. + # + @canonical_names = Hash.new + + # + # Hash table of argument flags. + # Keyes of the table are option names, and their values are argument + # flags of the options. + # + @argument_flags = Hash.new + + # + # Whether error messages are output to stderr. + # + @quiet_flag = FALSE + + # + # Status code. + # + @status = STATUS_YET + + # + # Error code. + # + @error = nil + + # + # Error message. + # + @error_message = nil + + # + # Rest of catinated short options. + # + @rest_singles = '' + + # + # List of non-option-arguments. + # Append them to ARGV when option processing is terminated. + # + @non_option_arguments = Array.new + + if 0 < arguments.length + set_options(*arguments) + end + end + + # + # Set ordering. + # + def ordering=(ordering) + # + # The method is failed if option processing has already started. + # + if @status != STATUS_YET + set_error(ArgumentError, "argument error") + raise RuntimeError, + "invoke ordering=, but option processing has already started" + end + + # + # Check ordering. + # + if !ORDERINGS.include?(ordering) + raise ArgumentError, "invalid ordering `#{ordering}'" + end + if ordering == PERMUTE && ENV.include?('POSIXLY_CORRECT') + @ordering = REQUIRE_ORDER + else + @ordering = ordering + end + end + + # + # Return ordering. + # + attr_reader :ordering + + # + # Set options + # + def set_options(*arguments) + # + # The method is failed if option processing has already started. + # + if @status != STATUS_YET + raise RuntimeError, + "invoke set_options, but option processing has already started" + end + + # + # Clear tables of option names and argument flags. + # + @canonical_names.clear + @argument_flags.clear + + arguments.each do |arg| + # + # Each argument must be an Array. + # + if !arg.is_a?(Array) + raise ArgumentError, "the option list contains non-Array argument" + end + + # + # Find an argument flag and it set to `argument_flag'. + # + argument_flag = nil + arg.each do |i| + if ARGUMENT_FLAGS.include?(i) + if argument_flag != nil + raise ArgumentError, "too many argument-flags" + end + argument_flag = i + end + end + raise ArgumentError, "no argument-flag" if argument_flag == nil + + canonical_name = nil + arg.each do |i| + # + # Check an option name. + # + next if i == argument_flag + begin + if !i.is_a?(String) || i !~ /^-([^-]|-.+)$/ + raise ArgumentError, "an invalid option `#{i}'" + end + if (@canonical_names.include?(i)) + raise ArgumentError, "option redefined `#{i}'" + end + rescue + @canonical_names.clear + @argument_flags.clear + raise + end + + # + # Register the option (`i') to the `@canonical_names' and + # `@canonical_names' Hashes. + # + if canonical_name == nil + canonical_name = i + end + @canonical_names[i] = canonical_name + @argument_flags[i] = argument_flag + end + raise ArgumentError, "no option name" if canonical_name == nil + end + return self + end + + # + # Set/Unset `quit' mode. + # + attr_writer :quiet + + # + # Return the flag of `quiet' mode. + # + attr_reader :quiet + + # + # `quiet?' is an alias of `quiet'. + # + alias quiet? quiet + + # + # Termintate option processing. + # + def terminate + return if @status == STATUS_TERMINATED + raise RuntimeError, "an error has occured" if @error != nil + + @status = STATUS_TERMINATED + @non_option_arguments.reverse_each do |argument| + ARGV.unshift(argument) + end + + @canonical_names = nil + @argument_flags = nil + @rest_singles = nil + @non_option_arguments = nil + + return self + end + + # + # Examine whether option processing is termintated or not. + # + def terminated? + return @status == STATUS_TERMINATED + end + + # + # Set an error (protected). + # + def set_error(type, message) + $stderr.print("#{$0}: #{message}\n") if !@quiet_flag + + @error = type + @error_message = message + @canonical_names = nil + @argument_flags = nil + @rest_singles = nil + @non_option_arguments = nil + + raise type, message + end + protected :set_error + + # + # Examine whether an option processing is failed. + # + attr_reader :error + + # + # `error?' is an alias of `error'. + # + alias error? error + + # + # Return an error message. + # + def error_message + return @error_message + end + + # + # Get next option name and its argument as an array. + # + def get + name, argument = nil, '' + + # + # Check status. + # + return if @error != nil + case @status + when STATUS_YET + @status = STATUS_STARTED + when STATUS_TERMINATED + return + end + + # + # Get next option argument. + # + if 0 < @rest_singles.length + $_ = '-' + @rest_singles + elsif (ARGV.length == 0) + terminate + return nil + elsif @ordering == PERMUTE + while 0 < ARGV.length && ARGV[0] !~ /^-./ + @non_option_arguments.push(ARGV.shift) + end + if ARGV.length == 0 + terminate + return + end + $_ = ARGV.shift + elsif @ordering == REQUIRE_ORDER + if (ARGV[0] !~ /^-./) + terminate + return nil + end + $_ = ARGV.shift + else + $_ = ARGV.shift + end + + # + # Check the special argument `--'. + # `--' indicates the end of the option list. + # + if $_ == '--' && @rest_singles.length == 0 + terminate + return nil + end + + # + # Check for long and short options. + # + if /^(--[^=]+)/ && @rest_singles.length == 0 + # + # This is a long style option, which start with `--'. + # + pattern = $1 + if @canonical_names.include?(pattern) + name = pattern + else + # + # The option `name' is not registered in `@canonical_names'. + # It may be an abbreviated. + # + match_count = 0 + @canonical_names.each_key do |key| + if key.index(pattern) == 0 + name = key + match_count += 1 + end + end + if 2 <= match_count + set_error(AmbigousOption, "option `#{$_}' is ambiguous") + elsif match_count == 0 + set_error(InvalidOption, "unrecognized option `#{$_}'") + end + end + + # + # Check an argument to the option. + # + if @argument_flags[name] == REQUIRED_ARGUMENT + if /=(.*)$/ + argument = $1 + elsif 0 < ARGV.length + argument = ARGV.shift + else + set_error(MissingArgument, "option `#{$_}' requires an argument") + end + elsif @argument_flags[name] == OPTIONAL_ARGUMENT + if /=(.*)$/ + argument = $1 + elsif 0 < ARGV.length && ARGV[0] !~ /^-./ + argument = ARGV.shift + else + argument = '' + end + elsif /=(.*)$/ + set_error(NeedlessArgument, + "option `#{name}' doesn't allow an argument") + end + + elsif /^(-(.))(.*)/ + # + # This is a short style option, which start with `-' (not `--'). + # Short options may be catinated (e.g. `-l -g' is equivalent to + # `-lg'). + # + name, ch, @rest_singles = $1, $2, $3 + + if @canonical_names.include?(name) + # + # The option `name' is found in `@canonical_names'. + # Check its argument. + # + if @argument_flags[name] == REQUIRED_ARGUMENT + if 0 < @rest_singles.length + argument = @rest_singles + @rest_singles = '' + elsif 0 < ARGV.length + argument = ARGV.shift + else + # 1003.2 specifies the format of this message. + set_error(MissingArgument, "option requires an argument -- #{ch}") + end + elsif @argument_flags[name] == OPTIONAL_ARGUMENT + if 0 < @rest_singles.length + argument = @rest_singles + @rest_singles = '' + elsif 0 < ARGV.length && ARGV[0] !~ /^-./ + argument = ARGV.shift + else + argument = '' + end + end + else + # + # This is an invalid option. + # 1003.2 specifies the format of this message. + # + if ENV.include?('POSIXLY_CORRECT') + set_error(InvalidOption, "illegal option -- #{ch}") + else + set_error(InvalidOption, "invalid option -- #{ch}") + end + end + else + # + # This is a non-option argument. + # Only RETURN_IN_ORDER falled into here. + # + return '', $_ + end + + return @canonical_names[name], argument + end + + # + # `get_option' is an alias of `get'. + # + alias get_option get + + # + # Iterator version of `get'. + # + def each + loop do + name, argument = get_option + break if name == nil + yield name, argument + end + end + + # + # `each_option' is an alias of `each'. + # + alias each_option each +end diff --git a/lib/mkmf.rb b/lib/mkmf.rb index 218b3b19f6..3f6f992b9c 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -326,7 +326,7 @@ EOMF if CONFIG["DLEXT"] != "o" mfile.printf <<EOMF $(TARGET): $(OBJS) - $(LDSHARED) $(DLDFLAGS) -o $(TARGET) $(OBJS) $(LOCAL_LIBS) $(LIBS) + $(LDSHARED) $(DLDFLAGS) -o $(TARGET) $(OBJS) $(LIBS) $(LOCAL_LIBS) EOMF elsif not File.exist?(target + ".c") and not File.exist?(target + ".cc") or mfile.print "$(TARGET): $(OBJS)\n" @@ -385,9 +385,9 @@ EOMF end end -$local_libs = nil $libs = PLATFORM =~ /cygwin32|beos/ ? nil : "-lc" $objs = nil -$CFLAGS = nil -$LDFLAGS = nil +$local_libs = "" +$CFLAGS = "" +$LDFLAGS = "" $defs = [] diff --git a/missing/setenv.c b/missing/setenv.c index c9cb4b20e0..7e8cd383e0 100644 --- a/missing/setenv.c +++ b/missing/setenv.c @@ -10,7 +10,7 @@ #ifndef NT extern char **environ; #endif -extern char **origenviron; +extern char **rb_origenviron; #ifndef NT char *strdup(); @@ -41,7 +41,7 @@ int n; { register int i=envix(nam); /* where does it go? */ - if (environ == origenviron) { /* need we copy environment? */ + if (environ == rb_origenviron) { /* need we copy environment? */ int j; int max; char **tmpenv; @@ -1679,6 +1679,7 @@ lex_get_str(s) beg = RSTRING(s)->ptr; if (lex_gets_ptr) { + if (RSTRING(s)->len == lex_gets_ptr) return Qnil; beg += lex_gets_ptr; } pend = RSTRING(s)->ptr + RSTRING(s)->len; @@ -2246,7 +2247,8 @@ here_document(term, indent) int c; char *eos, *p; int len; - VALUE str, line; + VALUE str; + volatile VALUE line; char *save_beg, *save_end, *save_lexp; NODE *list = 0; int linesave = ruby_sourceline; @@ -2307,6 +2309,13 @@ here_document(term, indent) lex_pbeg = lex_p = RSTRING(line)->ptr; lex_pend = lex_p + RSTRING(line)->len; +#if 0 + if (indent) { + while (*lex_p && *lex_p == '\t') { + lex_p++; + } + } +#endif switch (parse_string(term, '\n', '\n')) { case tSTRING: case tXSTRING: @@ -612,7 +612,7 @@ rb_f_system(argc, argv) } argv[0] = RARRAY(argv[0])->ptr[0]; } - cmd = rb_ary_join(ary_new4(argc, argv), rb_str_new2(" ")); + cmd = rb_ary_join(rb_ary_new4(argc, argv), rb_str_new2(" ")); Check_SafeStr(cmd); state = do_spawn(RSTRING(cmd)->ptr); @@ -631,7 +631,7 @@ rb_f_system(argc, argv) } argv[0] = RARRAY(argv[0])->ptr[0]; } - cmd = rb_ary_join(ary_new4(argc, argv), rb_str_new2(" ")); + cmd = rb_ary_join(rb_ary_new4(argc, argv), rb_str_new2(" ")); Check_SafeStr(cmd); state = system(RSTRING(cmd)->ptr); @@ -428,12 +428,16 @@ rb_reg_search(reg, str, start, reverse) else if (reg_kcode != curr_kcode) kcode_reset_option(); +#ifdef USE_THREAD if (rb_thread_scope_shared_p()) { match = Qnil; } else { match = rb_backref_get(); } +#else + match = rb_backref_get(); +#endif if (NIL_P(match)) { if (matchcache) { match = matchcache; @@ -86,9 +86,9 @@ char *alloca(); #define FREE_AND_RETURN_VOID(stackb) return #define FREE_AND_RETURN(stackb,val) return(val) #define DOUBLE_STACK(stackx,stackb,len,type) \ - (stackx = (type*) alloca(2 * len * sizeof(type)), \ + (stackx = (type*)alloca(2 * len * sizeof(type)), \ /* Only copy what is in use. */ \ - (type*) memcpy(stackx, stackb, len * sizeof (type))) + (type*)memcpy(stackx, stackb, len * sizeof (type))) #else /* NO_ALLOCA defined */ #define RE_ALLOCATE xmalloc @@ -129,13 +129,13 @@ char *alloca(); #include "regex.h" /* Subroutines for re_compile_pattern. */ -static void store_jump P((char *, int, char *)); -static void insert_jump P((int, char *, char *, char *)); -static void store_jump_n P((char *, int, char *, unsigned)); -static void insert_jump_n P((int, char *, char *, char *, unsigned)); -static void insert_op P((int, char *, char *)); -static void insert_op_2 P((int, char *, char *, int, int)); -static int memcmp_translate P((unsigned char *, unsigned char *, int)); +static void store_jump P((char*, int, char*)); +static void insert_jump P((int, char*, char*, char*)); +static void store_jump_n P((char*, int, char*, unsigned)); +static void insert_jump_n P((int, char*, char*, char*, unsigned)); +static void insert_op P((int, char*, char*)); +static void insert_op_2 P((int, char*, char*, int, int)); +static int memcmp_translate P((unsigned char*, unsigned char*, int)); static int alt_match_null_string_p (); static int common_op_match_null_string_p (); static int group_match_null_string_p (); @@ -154,7 +154,7 @@ static char re_syntax_table[256]; static void init_syntax_once P((void)); static unsigned char *translate = 0; static void init_regs P((struct re_registers*, unsigned int)); -static void bm_init_skip P((int *, unsigned char*, int, char *)); +static void bm_init_skip P((int *, unsigned char*, int, char*)); #undef P @@ -354,7 +354,7 @@ enum regexpcode at SOURCE. */ #define EXTRACT_NUMBER(destination, source) \ { (destination) = *(source) & 0377; \ - (destination) += SIGN_EXTEND_CHAR (*(char *)((source) + 1)) << 8; } + (destination) += SIGN_EXTEND_CHAR (*(char*)((source) + 1)) << 8; } /* Same as EXTRACT_NUMBER, except increment the pointer for source to point to second byte of SOURCE. Note that SOURCE has to be a value @@ -404,7 +404,7 @@ long re_syntax_options = 0; translation. */ #define PATFETCH_RAW(c) \ do {if (p == pend) goto end_of_pattern; \ - c = (unsigned char) *p++; \ + c = (unsigned char)*p++; \ } while (0) /* Go backwards one character in the pattern. */ @@ -437,7 +437,7 @@ long re_syntax_options = 0; if (bufp->allocated == (1L<<16)) goto too_big; \ bufp->allocated *= 2; \ if (bufp->allocated > (1L<<16)) bufp->allocated = (1L<<16); \ - bufp->buffer = (char *) xrealloc (bufp->buffer, bufp->allocated); \ + bufp->buffer = (char*)xrealloc (bufp->buffer, bufp->allocated); \ if (bufp->buffer == 0) \ goto memory_exhausted; \ b = (b - old_buffer) + bufp->buffer; \ @@ -643,7 +643,7 @@ print_partial_compiled_pattern(start, end) /* Loop over pattern commands. */ while (p < pend) { - switch ((enum regexpcode) *p++) + switch ((enum regexpcode)*p++) { case unused: printf ("/unused"); @@ -706,7 +706,7 @@ print_partial_compiled_pattern(start, end) register int c; printf ("/charset%s", - (enum regexpcode) *(p - 1) == charset_not ? "_not" : ""); + (enum regexpcode)*(p - 1) == charset_not ? "_not" : ""); mcnt = *p++; printf("/%d", mcnt); @@ -876,7 +876,7 @@ calculate_must_string(start, end) /* Loop over pattern commands. */ while (p < pend) { - switch ((enum regexpcode) *p++) + switch ((enum regexpcode)*p++) { case unused: break; @@ -1027,7 +1027,7 @@ re_compile_pattern(pattern, size, bufp) char greedy; - /* Address of beginning of regexp, or inside of last \(. */ + /* Address of beginning of regexp, or inside of last (. */ char *begalt = b; @@ -1041,8 +1041,8 @@ re_compile_pattern(pattern, size, bufp) /* In processing an interval, at most this many matches can be made. */ int upper_bound; - /* Stack of information saved by \( and restored by \). - Five stack elements are pushed by each \(: + /* Stack of information saved by ( and restored by ). + Five stack elements are pushed by each (: First, the value of b. Second, the value of fixup_alt_jump. Third, the value of begalt. @@ -1054,7 +1054,7 @@ re_compile_pattern(pattern, size, bufp) int *stacke = stackb + 40; int *stackt; - /* Counts \('s as they are encountered. Remembered for the matching \), + /* Counts ('s as they are encountered. Remembered for the matching ), where it becomes the register number to put in the stop_memory command. */ @@ -1077,10 +1077,10 @@ re_compile_pattern(pattern, size, bufp) bufp->allocated = INIT_BUF_SIZE; if (bufp->buffer) /* EXTEND_BUFFER loses when bufp->allocated is 0. */ - bufp->buffer = (char *) xrealloc (bufp->buffer, INIT_BUF_SIZE); + bufp->buffer = (char*)xrealloc (bufp->buffer, INIT_BUF_SIZE); else /* Caller did not allocate a buffer. Do it for them. */ - bufp->buffer = (char *) xmalloc(INIT_BUF_SIZE); + bufp->buffer = (char*)xmalloc(INIT_BUF_SIZE); if (!bufp->buffer) goto memory_exhausted; begalt = b = bufp->buffer; } @@ -1447,7 +1447,7 @@ re_compile_pattern(pattern, size, bufp) /* Discard any character set/class bitmap bytes that are all 0 at the end of the map. Decrement the map-length byte too. */ - while ((int) b[-1] > 0 && b[b[-1] - 1] == 0) + while ((int)b[-1] > 0 && b[b[-1] - 1] == 0) b[-1]--; if (b[-1] != (1 << BYTEWIDTH) / BYTEWIDTH) memmove(&b[b[-1]], &b[(1 << BYTEWIDTH) / BYTEWIDTH], @@ -1468,8 +1468,8 @@ re_compile_pattern(pattern, size, bufp) negative = 1; break; - case ')': case ':': + case ')': break; case 'x': @@ -1625,6 +1625,7 @@ re_compile_pattern(pattern, size, bufp) stackp--; break; + case ':': default: break; } @@ -1858,7 +1859,7 @@ re_compile_pattern(pattern, size, bufp) } } - while ((int) b[-1] > 0 && b[b[-1] - 1] == 0) + while ((int)b[-1] > 0 && b[b[-1] - 1] == 0) b[-1]--; if (b[-1] != (1 << BYTEWIDTH) / BYTEWIDTH) memmove(&b[b[-1]], &b[(1 << BYTEWIDTH) / BYTEWIDTH], @@ -2378,7 +2379,7 @@ void re_compile_fastmap(bufp) struct re_pattern_buffer *bufp; { - unsigned char *pattern = (unsigned char *) bufp->buffer; + unsigned char *pattern = (unsigned char*)bufp->buffer; int size = bufp->used; register char *fastmap = bufp->fastmap; register unsigned char *p = pattern; @@ -2404,7 +2405,7 @@ re_compile_fastmap(bufp) break; } #ifdef SWITCH_ENUM_BUG - switch ((int) ((enum regexpcode)*p++)) + switch ((int)((enum regexpcode)*p++)) #else switch ((enum regexpcode)*p++) #endif @@ -2467,11 +2468,11 @@ re_compile_fastmap(bufp) For a * loop, it has pushed its failure point already; If so, discard that as redundant. */ - if ((enum regexpcode) *p != on_failure_jump - && (enum regexpcode) *p != try_next - && (enum regexpcode) *p != succeed_n - && (enum regexpcode) *p != finalize_push - && (enum regexpcode) *p != finalize_push_n) + if ((enum regexpcode)*p != on_failure_jump + && (enum regexpcode)*p != try_next + && (enum regexpcode)*p != succeed_n + && (enum regexpcode)*p != finalize_push + && (enum regexpcode)*p != finalize_push_n) continue; p++; EXTRACT_NUMBER_AND_INCR(j, p); @@ -2782,7 +2783,7 @@ re_search(bufp, string, size, startpos, range, regs) register unsigned char *p, c; int irange = range; - p = (unsigned char *)string+startpos; + p = (unsigned char*)string+startpos; while (range > 0) { c = *p++; @@ -2813,6 +2814,7 @@ re_search(bufp, string, size, startpos, range, regs) } if (startpos > size) return -1; + if (anchor && size > 0 && startpos == size) return -1; if (fastmap && startpos == size && range >= 0 && (bufp->can_be_null == 0 || (bufp->can_be_null && size > 0 @@ -2843,7 +2845,7 @@ re_search(bufp, string, size, startpos, range, regs) register unsigned short c; int irange = range; - p = (unsigned char *)string+startpos; + p = (unsigned char*)string+startpos; while (range > 0) { c = *p++; if (ismbchar(c) && fastmap[c] != 2) { @@ -2988,11 +2990,11 @@ typedef union } \ \ /* Push how many registers we saved. */ \ - *stackp++ = (unsigned char *)last_used_reg; \ + *stackp++ = (unsigned char*)last_used_reg; \ \ *stackp++ = pattern_place; \ *stackp++ = string_place; \ - *stackp++ = (unsigned char *)0; /* non-greedy flag */ \ + *stackp++ = (unsigned char*)0; /* non-greedy flag */ \ } while(0) @@ -3002,13 +3004,13 @@ typedef union do { \ int temp; \ stackp -= NUM_NONREG_ITEMS; /* Remove failure points (and flag). */ \ - temp = (int) *--stackp; /* How many regs pushed. */ \ + temp = (int)*--stackp; /* How many regs pushed. */ \ temp *= NUM_REG_ITEMS; /* How much to take off the stack. */ \ stackp -= temp; /* Remove the register info. */ \ } while(0) /* Registers are set to a sentinel when they haven't yet matched. */ -#define REG_UNSET_VALUE ((unsigned char *) -1) +#define REG_UNSET_VALUE ((unsigned char*)-1) #define REG_UNSET(e) ((e) == REG_UNSET_VALUE) #define PREFETCH if (d == dend) goto fail @@ -3087,7 +3089,7 @@ re_match(bufp, string_arg, size, pos, regs) int size, pos; struct re_registers *regs; { - register unsigned char *p = (unsigned char *) bufp->buffer; + register unsigned char *p = (unsigned char*)bufp->buffer; unsigned char *p1; /* Pointer to beyond end of buffer. */ @@ -3095,7 +3097,7 @@ re_match(bufp, string_arg, size, pos, regs) unsigned num_regs = bufp->re_nsub; - unsigned char *string = (unsigned char *) string_arg; + unsigned char *string = (unsigned char*)string_arg; register unsigned char *d, *dend; register int mcnt; /* Multipurpose. */ @@ -3167,7 +3169,7 @@ re_match(bufp, string_arg, size, pos, regs) #endif /* Initialize subexpression text positions to -1 to mark ones that no - \( or ( and \) or ) has been seen for. Also set all registers to + ( or ( and ) or ) has been seen for. Also set all registers to inactive and mark them as not having matched anything or ever failed. */ for (mcnt = 0; mcnt < num_regs; mcnt++) { @@ -3206,7 +3208,7 @@ re_match(bufp, string_arg, size, pos, regs) #ifdef DEBUG_REGEX fprintf(stderr, "regex loop(%d): matching 0x%02d\n", - p - (unsigned char *) bufp->buffer, + p - (unsigned char*)bufp->buffer, *p); #endif /* End of pattern means we might have succeeded. */ @@ -3280,10 +3282,10 @@ re_match(bufp, string_arg, size, pos, regs) #endif { - /* \( [or `(', as appropriate] is represented by start_memory, - \) by stop_memory. Both of those commands are followed by + /* ( [or `(', as appropriate] is represented by start_memory, + ) by stop_memory. Both of those commands are followed by a register number in the next byte. The text matched - within the \( and \) is recorded under that number. */ + within the ( and ) is recorded under that number. */ case start_memory: /* Find out if this group can match the empty string. */ p1 = p; /* To send to group_match_null_string_p. */ @@ -3320,35 +3322,31 @@ re_match(bufp, string_arg, size, pos, regs) /* If just failed to match something this time around with a sub- expression that's in a loop, try to force exit from the loop. */ - if ((! MATCHED_SOMETHING(reg_info[*p]) - || (enum regexpcode) p[-3] == start_memory) - && (p + 1) != pend) + if ((p + 1) != pend && + (! MATCHED_SOMETHING(reg_info[*p]) + || (enum regexpcode)p[-3] == start_memory)) { - int is_a_jump_n = 0; - register unsigned char *p2 = p + 2; + p1 = p + 2; mcnt = 0; - switch (*p2++) + switch (*p1++) { case jump_n: case finalize_push_n: - is_a_jump_n = 1; case finalize_jump: case maybe_finalize_jump: case jump: case dummy_failure_jump: - EXTRACT_NUMBER_AND_INCR(mcnt, p2); - if (is_a_jump_n) - p2 += 2; + EXTRACT_NUMBER_AND_INCR(mcnt, p1); break; } - p2 += mcnt; + p1 += mcnt; /* If the next operation is a jump backwards in the pattern to an on_failure_jump, exit from the loop by forcing a failure after pushing on the stack the on_failure_jump's jump in the pattern, and d. */ - if (mcnt < 0 && (enum regexpcode) *p2 == on_failure_jump - && (enum regexpcode) p2[3] == start_memory && p2[4] == *p) + if (mcnt < 0 && (enum regexpcode)*p1 == on_failure_jump + && (enum regexpcode)p1[3] == start_memory && p1[4] == *p) { /* If this group ever matched anything, then restore what its registers were before trying this last @@ -3372,13 +3370,13 @@ re_match(bufp, string_arg, size, pos, regs) regstart[r] = old_regstart[r]; /* xx why this test? */ - if ((int) old_regend[r] >= (int) regstart[r]) + if ((int)old_regend[r] >= (int)regstart[r]) regend[r] = old_regend[r]; } } - p2++; - EXTRACT_NUMBER_AND_INCR(mcnt, p2); - PUSH_FAILURE_POINT(p2 + mcnt, d); + p1++; + EXTRACT_NUMBER_AND_INCR(mcnt, p1); + PUSH_FAILURE_POINT(p1 + mcnt, d); goto fail; } } @@ -3425,7 +3423,7 @@ re_match(bufp, string_arg, size, pos, regs) past them. */ if ((options & RE_OPTION_IGNORECASE) ? memcmp_translate(d, d2, mcnt) - : memcmp((char *)d, (char *)d2, mcnt)) + : memcmp((char*)d, (char*)d2, mcnt)) goto fail; d += mcnt, d2 += mcnt; } @@ -3578,10 +3576,13 @@ re_match(bufp, string_arg, size, pos, regs) failure point which is what we will end up popping. */ /* Skip over open/close-group commands. */ - while (p2 + 2 < pend - && ((enum regexpcode) *p2 == stop_memory - || (enum regexpcode) *p2 == start_memory)) - p2 += 3; /* Skip over args, too. */ + while (p2 + 2 < pend) { + if ((enum regexpcode)*p2 == stop_memory + || (enum regexpcode)*p2 == start_memory) + p2 += 3; /* Skip over args, too. */ + else + break; + } if (p2 == pend) p[-3] = (unsigned char)finalize_jump; @@ -3696,15 +3697,11 @@ re_match(bufp, string_arg, size, pos, regs) continue; case set_number_at: - { - register unsigned char *p1; - - EXTRACT_NUMBER_AND_INCR(mcnt, p); - p1 = p + mcnt; - EXTRACT_NUMBER_AND_INCR(mcnt, p); - STORE_NUMBER(p1, mcnt); - continue; - } + EXTRACT_NUMBER_AND_INCR(mcnt, p); + p1 = p + mcnt; + EXTRACT_NUMBER_AND_INCR(mcnt, p); + STORE_NUMBER(p1, mcnt); + continue; case try_next: EXTRACT_NUMBER_AND_INCR(mcnt, p); @@ -3884,7 +3881,7 @@ re_match(bufp, string_arg, size, pos, regs) d = *--stackp; p = *--stackp; /* Restore register info. */ - last_used_reg = (long) *--stackp; + last_used_reg = (long)*--stackp; /* Make the ones that weren't saved -1 or 0 again. */ for (this_reg = num_regs - 1; this_reg > last_used_reg; this_reg--) @@ -3905,11 +3902,11 @@ re_match(bufp, string_arg, size, pos, regs) if (p < pend) { int is_a_jump_n = 0; - unsigned char *p1 = p; - + + p1 = p; /* If failed to a backwards jump that's part of a repetition loop, need to pop this failure point and use the next one. */ - switch ((enum regexpcode) *p1) + switch ((enum regexpcode)*p1) { case jump_n: case finalize_push_n: @@ -3923,9 +3920,9 @@ re_match(bufp, string_arg, size, pos, regs) p1 += mcnt; if (p1 >= pend) break; - if ((is_a_jump_n && (enum regexpcode) *p1 == succeed_n) + if ((is_a_jump_n && (enum regexpcode)*p1 == succeed_n) || (!is_a_jump_n - && (enum regexpcode) *p1 == on_failure_jump)) + && (enum regexpcode)*p1 == on_failure_jump)) goto fail; break; default: @@ -3969,7 +3966,7 @@ group_match_null_string_p (p, end, reg_info) false, as appropriate, when we get to one that can't, or to the matching stop_memory. */ - switch ((enum regexpcode) *p1) + switch ((enum regexpcode)*p1) { /* Could be either a loop or a series of alternatives. */ case on_failure_jump: @@ -3999,7 +3996,7 @@ group_match_null_string_p (p, end, reg_info) with an on_failure_jump (see above) that jumps to right past a jump_past_alt. */ - while ((enum regexpcode) p1[mcnt-3] == jump_past_alt) + while ((enum regexpcode)p1[mcnt-3] == jump_past_alt) { /* `mcnt' holds how many bytes long the alternative is, including the ending `jump_past_alt' and @@ -4015,14 +4012,14 @@ group_match_null_string_p (p, end, reg_info) /* Break if it's the beginning of an n-th alternative that doesn't begin with an on_failure_jump. */ - if ((enum regexpcode) *p1 != on_failure_jump) + if ((enum regexpcode)*p1 != on_failure_jump) break; /* Still have to check that it's not an n-th alternative that starts with an on_failure_jump. */ p1++; EXTRACT_NUMBER_AND_INCR (mcnt, p1); - if ((enum regexpcode) p1[mcnt-3] != jump_past_alt) + if ((enum regexpcode)p1[mcnt-3] != jump_past_alt) { /* Get to the beginning of the n-th alternative. */ p1 -= 3; @@ -4075,7 +4072,7 @@ alt_match_null_string_p (p, end, reg_info) /* Skip over opcodes that can match nothing, and break when we get to one that can't. */ - switch ((enum regexpcode) *p1) + switch ((enum regexpcode)*p1) { /* It's a loop. */ case on_failure_jump: @@ -4109,7 +4106,7 @@ common_op_match_null_string_p (p, end, reg_info) int reg_no; unsigned char *p1 = *p; - switch ((enum regexpcode) *p1++) + switch ((enum regexpcode)*p1++) { case unused: case begline: @@ -81,12 +81,6 @@ static char **origargv; #define RUBY_SITE_LIB "/usr/local/lib/site_ruby" #endif -#if defined(MSDOS) || defined(NT) || defined(__MACOS__) -#define RUBY_LIB_SEP ';' -#else -#define RUBY_LIB_SEP ':' -#endif - extern VALUE rb_load_path; static FILE *e_fp; @@ -96,6 +90,8 @@ static void addpath(path) char *path; { + const char sep = *RUBY_LIB_SEP; + if (path == 0) return; #if defined(__CYGWIN32__) { @@ -104,14 +100,14 @@ addpath(path) path = rubylib; } #endif - if (strchr(path, RUBY_LIB_SEP)) { + if (strchr(path, sep)) { char *p, *s; VALUE ary = rb_ary_new(); p = path; while (*p) { - while (*p == RUBY_LIB_SEP) p++; - if (s = strchr(p, RUBY_LIB_SEP)) { + while (*p == sep) p++; + if (s = strchr(p, sep)) { rb_ary_push(ary, rb_str_new(p, (int)(s-p))); p = s + 1; } @@ -623,7 +619,7 @@ set_arg0(val, id) len = s - origargv[0]; } #endif - s = str2cstr(val, &i); + s = rb_str2cstr(val, &i); #ifndef __hpux if (i > len) { memcpy(origargv[0], s, len); @@ -650,7 +646,7 @@ set_arg0(val, id) j.pst_command = s; pstat(PSTAT_SETCMD, j, i, 0, 0); } - rb_progname = str_taint(str_new(s, i)); + rb_progname = rb_tainted_str_new(s, i); #endif } diff --git a/sample/test.rb b/sample/test.rb index 8748b60b50..f28327659e 100644 --- a/sample/test.rb +++ b/sample/test.rb @@ -414,17 +414,6 @@ tt{|i| break if i == 5} ok(i == 5) # iterator break/redo/next/retry -unless defined? loop - def loop - while true - yield - end - end - ok(false) -else - ok(true) -end - done = true loop{ break @@ -685,10 +674,13 @@ ok(a == 1) a, *b = 1, 2, 3 ok(a == 1 && b == [2, 3]) +a, (b, c), d = 1, [2, 3], 4 +ok(a == 1 && b == 2 && c == 3 && d == 4) + *a = 1, 2, 3 ok(a == [1, 2, 3]) -*a = 1..3 +*a = 1..3 # array conversion ok(a == [1, 2, 3]) check "call" @@ -60,14 +60,14 @@ rb_tainted_str_new(ptr, len) char *ptr; int len; { - return rb_str_new(ptr, len); + return rb_obj_taint(rb_str_new(ptr, len)); } VALUE rb_tainted_str_new2(ptr) char *ptr; { - return rb_str_new2(ptr); + return rb_obj_taint(rb_str_new2(ptr)); } VALUE @@ -1095,7 +1095,7 @@ rb_str_gsub_bang(argc, argv, str) else { val = rb_reg_regsub(repl, str, regs); } - len = beg + RSTRING(val)->len + 3; + len = (bp - buf) + (beg - offset) + RSTRING(val)->len + 3; if (blen < len) { while (blen < len) blen *= 2; len = bp - buf; diff --git a/win32/Makefile b/win32/Makefile index 135d657780..75e4712ec9 100644 --- a/win32/Makefile +++ b/win32/Makefile @@ -20,7 +20,7 @@ LDFLAGS = $(CFLAGS) -Fm #CFLAGS = -nologo -DNT=1 -Zi -MD #LDFLAGS = $(CFLAGS) -Fm -MD LIBS = $(EXTLIBS) advapi32.lib wsock32.lib -MISSING = crypt.obj setenv.obj alloca.obj nt.obj +MISSING = crypt.obj alloca.obj nt.obj prefix = binprefix = @@ -157,9 +157,6 @@ memmove.obj: missing/memmove.c mkdir.obj: missing/mkdir.c $(CC) $(CFLAGS) $(CPPFLAGS) -c missing/mkdir.c -setenv.obj: missing/setenv.c - $(CC) -I. $(CFLAGS) $(CPPFLAGS) -c missing/setenv.c - strerror.obj: missing/strerror.c $(CC) $(CFLAGS) $(CPPFLAGS) -c missing/strerror.c |