diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-01-04 14:15:33 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-01-04 14:15:33 +0000 |
commit | 459031e5d94baf72c8e30a48922d57c6cff5a2ae (patch) | |
tree | 01f71e4415d55f655c744e1c2289219e46e038d6 | |
parent | a7685a6b877631dbb4ea9538311c124b5822677a (diff) |
* process.c (rb_f_system): abandon vfork.
* io.c (pipe_open): ditto.
* defines.h: sparc linux needs different FLUSH_REGISTER_WINDOWS
* regex.c (re_search): abandon stclass optimization.
* bignum.c (rb_cstr2inum): deny "0_".
* bignum.c (rb_cstr2inum): allow "0\n" and so on.
* error.c (rb_invalid_str): utility function to show inspect()'ed
string.
* bignum.c (rb_cstr2inum): prints invalid strings in inspect()'ed
format.
* object.c (rb_Float): ditto.
* object.c (rb_convert_type): no longer use rb_rescue().
* re.c (rb_reg_search): initialize taint status of match object.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | bignum.c | 4 | ||||
-rw-r--r-- | configure.in | 1 | ||||
-rw-r--r-- | defines.h | 14 | ||||
-rw-r--r-- | error.c | 9 | ||||
-rw-r--r-- | eval.c | 3 | ||||
-rw-r--r-- | gc.c | 2 | ||||
-rw-r--r-- | intern.h | 1 | ||||
-rw-r--r-- | io.c | 5 | ||||
-rw-r--r-- | lib/debug.rb | 4 | ||||
-rw-r--r-- | misc/ruby-mode.el | 34 | ||||
-rw-r--r-- | object.c | 82 | ||||
-rw-r--r-- | parse.y | 2 | ||||
-rw-r--r-- | process.c | 5 | ||||
-rw-r--r-- | re.c | 7 | ||||
-rw-r--r-- | regex.c | 28 | ||||
-rw-r--r-- | regex.h | 1 |
16 files changed, 98 insertions, 104 deletions
@@ -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\ @@ -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 @@ -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; @@ -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 */ @@ -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"); } @@ -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*))); @@ -55,9 +55,6 @@ struct timeval { }; #endif #endif -#ifdef HAVE_VFORK_H -#include <vfork.h> -#endif #include <sys/stat.h> @@ -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)) @@ -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; -{ - return rb_funcall(arg->val, rb_intern(arg->s), 0); -} - -static VALUE -fail_to_type(arg) - struct arg_to *arg; +convert_type(val, tname, method, raise) + VALUE val; + const char *tname, *method; + int raise; { - 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 */ + struct arg_to arg1, arg2; + ID m; + + 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 == '_') { @@ -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; @@ -40,9 +40,6 @@ struct timeval rb_time_interval _((VALUE)); #ifdef HAVE_GETPRIORITY # include <sys/resource.h> #endif -#ifdef HAVE_VFORK_H -#include <vfork.h> -#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); @@ -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); @@ -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: @@ -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; |