diff --git a/bignum.c b/bignum.c index 38513c2373..ffdd24df79 100644 --- a/bignum.c +++ b/bignum.c @@ -252,11 +252,11 @@ rb_cstr2inum(str, base) if (*end == '_') goto bigparse; if (badcheck) { - if (end == str) goto bad; /* no number */ while (*end && ISSPACE(*end)) end++; + if (end == str) goto bad; /* no number */ if (*end) { /* trailing garbage */ bad: - rb_raise(rb_eArgError, "invalid value for Integer: \"%s\"", s); + rb_invalid_str(s, "Integer"); } } diff --git a/configure.in b/configure.in index b70f95d722..35647e4597 100644 --- a/configure.in +++ b/configure.in @@ -290,7 +290,6 @@ dnl Checks for library functions. AC_TYPE_GETGROUPS AC_TYPE_SIGNAL AC_FUNC_ALLOCA -AC_FUNC_VFORK AC_FUNC_MEMCMP AC_REPLACE_FUNCS(dup2 memmove mkdir strcasecmp strncasecmp strerror strftime\ strchr strstr strtoul crypt flock vsnprintf\ diff --git a/defines.h b/defines.h index 3ca631ef12..bdf3e856bd 100644 --- a/defines.h +++ b/defines.h @@ -59,11 +59,15 @@ #define EXTERN extern #endif -#ifdef sparc -#define FLUSH_REGISTER_WINDOWS asm("ta 3") -#else -#define FLUSH_REGISTER_WINDOWS /* empty */ -#endif +#if defined(sparc) || defined(__sparc__) +# if defined(linux) || defined(__linux__) +#define FLUSH_REGISTER_WINDOWS asm("ta 0x83") +# else /* Solaris, not sparc linux */ +#define FLUSH_REGISTER_WINDOWS asm("ta 0x03") +# endif /* trap always to flush register windows if we are on a Sparc system */ +#else /* Not a sparc, so */ +#define FLUSH_REGISTER_WINDOWS /* empty -- nothing to do here */ +#endif #if defined(MSDOS) || defined(_WIN32) || defined(__human68k__) || defined(__EMX__) #define DOSISH 1 diff --git a/error.c b/error.c index 010a27243a..d8dab15df9 100644 --- a/error.c +++ b/error.c @@ -447,6 +447,15 @@ nometh_args(self) return rb_iv_get(self, "args"); } +void +rb_invalid_str(str, type) + const char *str, *type; +{ + VALUE s = rb_str_inspect(rb_str_new2(str)); + + rb_raise(rb_eArgError, "invalid value for %s: %s", type, RSTRING(s)->ptr); +} + #ifdef __BEOS__ typedef struct { VALUE *list; diff --git a/eval.c b/eval.c index c70b24384d..d791b31f86 100644 --- a/eval.c +++ b/eval.c @@ -8455,8 +8455,7 @@ rb_thread_start_0(fn, arg, th_arg) rb_thread_raise(1, &ruby_errinfo, main_thread); } } - else if (th->safe < 4 && - (thread_abort || th->abort || RTEST(ruby_debug))) { + else if (th->safe < 4 && (thread_abort || th->abort || RTEST(ruby_debug))) { VALUE err = rb_exc_new(rb_eSystemExit, 0, 0); error_print(); /* exit on main_thread */ diff --git a/gc.c b/gc.c index 573a6e34f9..5c474d3b81 100644 --- a/gc.c +++ b/gc.c @@ -105,7 +105,7 @@ ruby_xmalloc(size) RUBY_CRITICAL(mem = malloc(size)); if (!mem) { if (size >= 10 * 1024 * 1024) { - rb_raise(rb_eNoMemError, "tried to allocate too big memory"); + mem_error("tried to allocate too big memory"); } mem_error("failed to allocate memory"); } diff --git a/intern.h b/intern.h index 4f7338115f..16436a46cb 100644 --- a/intern.h +++ b/intern.h @@ -114,6 +114,7 @@ VALUE rb_exc_new2 _((VALUE, const char*)); VALUE rb_exc_new3 _((VALUE, VALUE)); NORETURN(void rb_loaderror __((const char*, ...))); NORETURN(void rb_name_error __((VALUE id, const char*, ...))); +NORETURN(void rb_invalid_str _((const char*, const char*))); void rb_compile_error __((const char*, ...)); void rb_compile_error_append __((const char*, ...)); NORETURN(void rb_load_fail _((char*))); diff --git a/io.c b/io.c index b99580f0a3..48a23c927c 100644 --- a/io.c +++ b/io.c @@ -55,9 +55,6 @@ struct timeval { }; #endif #endif -#ifdef HAVE_VFORK_H -#include -#endif #include @@ -1686,7 +1683,7 @@ pipe_open(pname, mode) } retry: - switch (pid = (doexec?vfork():fork())) { + switch ((pid = fork())) { case 0: /* child */ if (modef & FMODE_READABLE) { close(pr[0]); diff --git a/lib/debug.rb b/lib/debug.rb index 7b95475dce..6c4d80e5a7 100644 --- a/lib/debug.rb +++ b/lib/debug.rb @@ -7,6 +7,7 @@ if $SAFE > 0 end require 'tracer' +require 'pp' class Tracer def Tracer.trace_func(*vars) @@ -510,6 +511,9 @@ class DEBUGGER__ prompt = false end + when /^\s*pp\s+/ + PP.pp(debug_eval($', binding), 79, stdout) + when /^\s*p\s+/ stdout.printf "%s\n", debug_eval($', binding).inspect diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el index 09df43dff0..a3bd3bea9a 100644 --- a/misc/ruby-mode.el +++ b/misc/ruby-mode.el @@ -270,7 +270,7 @@ The variable ruby-indent-level controls the amount of indentation. (while (and (> indent-point (point)) (re-search-forward ruby-delimiter indent-point t)) (or depth (setq depth 0)) - (let ((pnt (point)) w) + (let ((pnt (point)) w re) (goto-char (match-beginning 0)) (cond ((or (looking-at "\"") ;skip string @@ -302,17 +302,27 @@ The variable ruby-indent-level controls the amount of indentation. (setq w (buffer-substring (match-beginning 1) (match-end 1))) (cond - ((string= w "[") (setq w "\\]")) - ((string= w "{") (setq w "}")) - ((string= w "(") (setq w ")")) - ((string= w "<") (setq w ">")) + ((string= w "[") (setq re "][")) + ((string= w "{") (setq re "}{")) + ((string= w "(") (setq re ")(")) + ((string= w "<") (setq re "><")) ((member w '("*" "." "+" "?" "^" "$")) (setq w (concat "\\" w)))) - (if (re-search-forward - (if (string= w "\\") - "\\\\[^\\]*\\\\" - (concat "[^\\]\\(\\\\\\\\\\)*" w)) - indent-point t) + (if (if re + (let ((n 1)) + (setq re (concat "[^\\]\\(\\\\\\\\\\)*[" re "]")) + (while (and (re-search-forward re indent-point t) + (> (setq n (if (eq (char-before (point)) + (string-to-char w)) + (1+ n) (1- n))) + 0)) + (forward-char -1)) + (zerop n)) + (re-search-forward + (if (string= w "\\") + "\\\\[^\\]*\\\\" + (concat "[^\\]\\(\\\\\\\\\\)*" w)) + indent-point t)) nil (setq in-string (point)) (goto-char indent-point))) @@ -674,8 +684,8 @@ An end of a defun is found by moving forward from the beginning of one." (add-hook 'ruby-mode-hook '(lambda () - (make-local-variable 'font-lock-syntactic-keywords) - (setq font-lock-syntactic-keywords + (make-local-variable 'ruby-font-lock-syntactic-keywords) + (setq ruby-font-lock-syntactic-keywords '( ;; #{ }, #$hoge, #@foo are not comments ("\\(#\\)[{$@]" 1 (1 . nil)) diff --git a/object.c b/object.c index f77d3edc1d..ea3eec7dae 100644 --- a/object.c +++ b/object.c @@ -836,26 +836,33 @@ rb_obj_private_methods(obj) struct arg_to { VALUE val; const char *s; + ID m; }; static VALUE -to_type(arg) - struct arg_to *arg; +convert_type(val, tname, method, raise) + VALUE val; + const char *tname, *method; + int raise; { - return rb_funcall(arg->val, rb_intern(arg->s), 0); -} + struct arg_to arg1, arg2; + ID m; -static VALUE -fail_to_type(arg) - struct arg_to *arg; -{ - rb_raise(rb_eTypeError, "failed to convert %s into %s", - NIL_P(arg->val) ? "nil" : - arg->val == Qtrue ? "true" : - arg->val == Qfalse ? "false" : - rb_class2name(CLASS_OF(arg->val)), - arg->s); - return Qnil; /* not reached */ + m = rb_intern(method); + if (!rb_respond_to(val, m)) { + if (raise) { + rb_raise(rb_eTypeError, "failed to convert %s into %s", + NIL_P(val) ? "nil" : + val == Qtrue ? "true" : + val == Qfalse ? "false" : + rb_class2name(CLASS_OF(val)), + tname); + } + else { + return Qnil; + } + } + return rb_funcall(val, m, 0); } VALUE @@ -864,18 +871,15 @@ rb_convert_type(val, type, tname, method) int type; const char *tname, *method; { - struct arg_to arg1, arg2; + VALUE v; if (TYPE(val) == type) return val; - arg1.val = arg2.val = val; - arg1.s = method; - arg2.s = tname; - val = rb_rescue(to_type, (VALUE)&arg1, fail_to_type, (VALUE)&arg2); - if (TYPE(val) != type) { + v = convert_type(val, tname, method, Qtrue); + if (TYPE(v) != type) { rb_raise(rb_eTypeError, "%s#%s should return %s", - rb_class2name(CLASS_OF(arg1.val)), method, tname); + rb_class2name(CLASS_OF(val)), method, tname); } - return val; + return v; } VALUE @@ -884,18 +888,16 @@ rb_check_convert_type(val, type, tname, method) int type; const char *tname, *method; { - struct arg_to arg1, arg2; + VALUE v; if (TYPE(val) == type) return val; - arg1.val = arg2.val = val; - arg1.s = method; - arg2.s = tname; - val = rb_rescue(to_type, (VALUE)&arg1, 0, 0); - if (!NIL_P(val) && TYPE(val) != type) { + v = convert_type(val, tname, method, Qfalse); + if (NIL_P(v)) return Qnil; + if (TYPE(v) != type) { rb_raise(rb_eTypeError, "%s#%s should return %s", - rb_class2name(CLASS_OF(arg1.val)), method, tname); + rb_class2name(CLASS_OF(val)), method, tname); } - return val; + return v; } static VALUE @@ -903,18 +905,12 @@ rb_to_integer(val, method) VALUE val; char *method; { - struct arg_to arg1, arg2; - - - arg1.val = arg2.val = val; - arg1.s = method; - arg2.s = "Integer"; - val = rb_rescue(to_type, (VALUE)&arg1, fail_to_type, (VALUE)&arg2); - if (!rb_obj_is_kind_of(val, rb_cInteger)) { + VALUE v = convert_type(val, "Integer", method, Qtrue); + if (!rb_obj_is_kind_of(v, rb_cInteger)) { rb_raise(rb_eTypeError, "%s#%s should return Integer", - rb_class2name(CLASS_OF(arg1.val)), method); + rb_class2name(CLASS_OF(val)), method); } - return val; + return v; } VALUE @@ -983,7 +979,7 @@ rb_Float(val) d = strtod(p, &end); if (p == end) { bad: - rb_raise(rb_eArgError, "invalid value for Float(): \"%s\"", q); + rb_invalid_str(q, "Float()"); } if (*end) { if (*end == '_') { diff --git a/parse.y b/parse.y index d79dc67445..c3c9b8482a 100644 --- a/parse.y +++ b/parse.y @@ -2145,7 +2145,7 @@ yycompile(f, line) ruby__end__seen = 0; ruby_eval_tree = 0; heredoc_end = 0; - ruby_sourcefile = f; + ruby_sourcefile = strdup(f); ruby_in_compile = 1; n = yyparse(); ruby_debug_lines = 0; diff --git a/process.c b/process.c index 81685d0c1d..67437d72cc 100644 --- a/process.c +++ b/process.c @@ -40,9 +40,6 @@ struct timeval rb_time_interval _((VALUE)); #ifdef HAVE_GETPRIORITY # include #endif -#ifdef HAVE_VFORK_H -#include -#endif #include "st.h" #ifdef __EMX__ @@ -908,7 +905,7 @@ rb_f_system(argc, argv) SafeStringValue(argv[i]); } retry: - switch (pid = vfork()) { + switch (pid = fork()) { case 0: if (argc == 1 && prog == 0) { rb_proc_exec(RSTRING(argv[0])->ptr); diff --git a/re.c b/re.c index d6f860b86f..91d920bfdb 100644 --- a/re.c +++ b/re.c @@ -649,6 +649,13 @@ rb_reg_search(re, str, pos, reverse) if (NIL_P(match) || FL_TEST(match, MATCH_BUSY)) { match = match_alloc(); } + else { + if (rb_safe_level() >= 3) + OBJ_TAINT(match); + else + FL_UNSET(match, FL_TAINT); + } + re_copy_registers(RMATCH(match)->regs, ®s); RMATCH(match)->str = rb_str_new4(str); rb_backref_set(match); diff --git a/regex.c b/regex.c index b88bfffa4b..4b99d90317 100644 --- a/regex.c +++ b/regex.c @@ -1264,7 +1264,6 @@ re_compile_pattern(pattern, size, bufp) bufp->fastmap_accurate = 0; bufp->must = 0; bufp->must_skip = 0; - bufp->stclass = 0; /* Initialize the syntax table. */ init_syntax_once(); @@ -2389,9 +2388,6 @@ re_compile_pattern(pattern, size, bufp) p0 += mcnt+1; mcnt = EXTRACT_UNSIGNED_AND_INCR(p0); p0 += 8*mcnt; - if (*p0 == maybe_finalize_jump) { - bufp->stclass = laststart; - } } } } @@ -3285,30 +3281,6 @@ re_search(bufp, string, size, startpos, range, regs) startpos++; } } - else if (fastmap && (bufp->stclass)) { - register unsigned char *p; - unsigned long c; - int irange = range; - - p = (unsigned char*)string+startpos; - while (range > 0) { - c = *p++; - if (ismbchar(c) && fastmap[c] != 2) { - MBC2WC(c, p); - } - else if (MAY_TRANSLATE()) - c = translate[c]; - if (*bufp->stclass == charset) { - if (!is_in_list(c, bufp->stclass+1)) break; - } - else { - if (is_in_list(c, bufp->stclass+1)) break; - } - range--; - if (c > 256) range--; - } - startpos += irange - range; - } } advance: diff --git a/regex.h b/regex.h index a0758fc7aa..d5eb01d235 100644 --- a/regex.h +++ b/regex.h @@ -132,7 +132,6 @@ struct re_pattern_buffer char *must; /* Pointer to exact pattern which strings should have to be matched. */ int *must_skip; /* Pointer to exact pattern skip table for bm_search */ - char *stclass; /* Pointer to character class list at top */ long options; /* Flags for options such as extended_pattern. */ long re_nsub; /* Number of subexpressions found by the compiler. */ char fastmap_accurate;