1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
matz 2002-01-04 14:15:33 +00:00
parent a7685a6b87
commit 459031e5d9
16 changed files with 97 additions and 103 deletions

View file

@ -252,11 +252,11 @@ rb_cstr2inum(str, base)
if (*end == '_') goto bigparse; if (*end == '_') goto bigparse;
if (badcheck) { if (badcheck) {
if (end == str) goto bad; /* no number */
while (*end && ISSPACE(*end)) end++; while (*end && ISSPACE(*end)) end++;
if (end == str) goto bad; /* no number */
if (*end) { /* trailing garbage */ if (*end) { /* trailing garbage */
bad: bad:
rb_raise(rb_eArgError, "invalid value for Integer: \"%s\"", s); rb_invalid_str(s, "Integer");
} }
} }

View file

@ -290,7 +290,6 @@ dnl Checks for library functions.
AC_TYPE_GETGROUPS AC_TYPE_GETGROUPS
AC_TYPE_SIGNAL AC_TYPE_SIGNAL
AC_FUNC_ALLOCA AC_FUNC_ALLOCA
AC_FUNC_VFORK
AC_FUNC_MEMCMP AC_FUNC_MEMCMP
AC_REPLACE_FUNCS(dup2 memmove mkdir strcasecmp strncasecmp strerror strftime\ AC_REPLACE_FUNCS(dup2 memmove mkdir strcasecmp strncasecmp strerror strftime\
strchr strstr strtoul crypt flock vsnprintf\ strchr strstr strtoul crypt flock vsnprintf\

View file

@ -59,11 +59,15 @@
#define EXTERN extern #define EXTERN extern
#endif #endif
#ifdef sparc #if defined(sparc) || defined(__sparc__)
#define FLUSH_REGISTER_WINDOWS asm("ta 3") # if defined(linux) || defined(__linux__)
#else #define FLUSH_REGISTER_WINDOWS asm("ta 0x83")
#define FLUSH_REGISTER_WINDOWS /* empty */ # else /* Solaris, not sparc linux */
#endif #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__) #if defined(MSDOS) || defined(_WIN32) || defined(__human68k__) || defined(__EMX__)
#define DOSISH 1 #define DOSISH 1

View file

@ -447,6 +447,15 @@ nometh_args(self)
return rb_iv_get(self, "args"); 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__ #ifdef __BEOS__
typedef struct { typedef struct {
VALUE *list; VALUE *list;

3
eval.c
View file

@ -8455,8 +8455,7 @@ rb_thread_start_0(fn, arg, th_arg)
rb_thread_raise(1, &ruby_errinfo, main_thread); rb_thread_raise(1, &ruby_errinfo, main_thread);
} }
} }
else if (th->safe < 4 && else if (th->safe < 4 && (thread_abort || th->abort || RTEST(ruby_debug))) {
(thread_abort || th->abort || RTEST(ruby_debug))) {
VALUE err = rb_exc_new(rb_eSystemExit, 0, 0); VALUE err = rb_exc_new(rb_eSystemExit, 0, 0);
error_print(); error_print();
/* exit on main_thread */ /* exit on main_thread */

2
gc.c
View file

@ -105,7 +105,7 @@ ruby_xmalloc(size)
RUBY_CRITICAL(mem = malloc(size)); RUBY_CRITICAL(mem = malloc(size));
if (!mem) { if (!mem) {
if (size >= 10 * 1024 * 1024) { 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"); mem_error("failed to allocate memory");
} }

View file

@ -114,6 +114,7 @@ VALUE rb_exc_new2 _((VALUE, const char*));
VALUE rb_exc_new3 _((VALUE, VALUE)); VALUE rb_exc_new3 _((VALUE, VALUE));
NORETURN(void rb_loaderror __((const char*, ...))); NORETURN(void rb_loaderror __((const char*, ...)));
NORETURN(void rb_name_error __((VALUE id, 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 __((const char*, ...));
void rb_compile_error_append __((const char*, ...)); void rb_compile_error_append __((const char*, ...));
NORETURN(void rb_load_fail _((char*))); NORETURN(void rb_load_fail _((char*)));

5
io.c
View file

@ -55,9 +55,6 @@ struct timeval {
}; };
#endif #endif
#endif #endif
#ifdef HAVE_VFORK_H
#include <vfork.h>
#endif
#include <sys/stat.h> #include <sys/stat.h>
@ -1686,7 +1683,7 @@ pipe_open(pname, mode)
} }
retry: retry:
switch (pid = (doexec?vfork():fork())) { switch ((pid = fork())) {
case 0: /* child */ case 0: /* child */
if (modef & FMODE_READABLE) { if (modef & FMODE_READABLE) {
close(pr[0]); close(pr[0]);

View file

@ -7,6 +7,7 @@ if $SAFE > 0
end end
require 'tracer' require 'tracer'
require 'pp'
class Tracer class Tracer
def Tracer.trace_func(*vars) def Tracer.trace_func(*vars)
@ -510,6 +511,9 @@ class DEBUGGER__
prompt = false prompt = false
end end
when /^\s*pp\s+/
PP.pp(debug_eval($', binding), 79, stdout)
when /^\s*p\s+/ when /^\s*p\s+/
stdout.printf "%s\n", debug_eval($', binding).inspect stdout.printf "%s\n", debug_eval($', binding).inspect

View file

@ -270,7 +270,7 @@ The variable ruby-indent-level controls the amount of indentation.
(while (and (> indent-point (point)) (while (and (> indent-point (point))
(re-search-forward ruby-delimiter indent-point t)) (re-search-forward ruby-delimiter indent-point t))
(or depth (setq depth 0)) (or depth (setq depth 0))
(let ((pnt (point)) w) (let ((pnt (point)) w re)
(goto-char (match-beginning 0)) (goto-char (match-beginning 0))
(cond (cond
((or (looking-at "\"") ;skip string ((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) (setq w (buffer-substring (match-beginning 1)
(match-end 1))) (match-end 1)))
(cond (cond
((string= w "[") (setq w "\\]")) ((string= w "[") (setq re "]["))
((string= w "{") (setq w "}")) ((string= w "{") (setq re "}{"))
((string= w "(") (setq w ")")) ((string= w "(") (setq re ")("))
((string= w "<") (setq w ">")) ((string= w "<") (setq re "><"))
((member w '("*" "." "+" "?" "^" "$")) ((member w '("*" "." "+" "?" "^" "$"))
(setq w (concat "\\" w)))) (setq w (concat "\\" w))))
(if (re-search-forward (if (if re
(if (string= w "\\") (let ((n 1))
"\\\\[^\\]*\\\\" (setq re (concat "[^\\]\\(\\\\\\\\\\)*[" re "]"))
(concat "[^\\]\\(\\\\\\\\\\)*" w)) (while (and (re-search-forward re indent-point t)
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 nil
(setq in-string (point)) (setq in-string (point))
(goto-char indent-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 (add-hook 'ruby-mode-hook
'(lambda () '(lambda ()
(make-local-variable 'font-lock-syntactic-keywords) (make-local-variable 'ruby-font-lock-syntactic-keywords)
(setq font-lock-syntactic-keywords (setq ruby-font-lock-syntactic-keywords
'( '(
;; #{ }, #$hoge, #@foo are not comments ;; #{ }, #$hoge, #@foo are not comments
("\\(#\\)[{$@]" 1 (1 . nil)) ("\\(#\\)[{$@]" 1 (1 . nil))

View file

@ -836,26 +836,33 @@ rb_obj_private_methods(obj)
struct arg_to { struct arg_to {
VALUE val; VALUE val;
const char *s; const char *s;
ID m;
}; };
static VALUE static VALUE
to_type(arg) convert_type(val, tname, method, raise)
struct arg_to *arg; 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 m = rb_intern(method);
fail_to_type(arg) if (!rb_respond_to(val, m)) {
struct arg_to *arg; if (raise) {
{ rb_raise(rb_eTypeError, "failed to convert %s into %s",
rb_raise(rb_eTypeError, "failed to convert %s into %s", NIL_P(val) ? "nil" :
NIL_P(arg->val) ? "nil" : val == Qtrue ? "true" :
arg->val == Qtrue ? "true" : val == Qfalse ? "false" :
arg->val == Qfalse ? "false" : rb_class2name(CLASS_OF(val)),
rb_class2name(CLASS_OF(arg->val)), tname);
arg->s); }
return Qnil; /* not reached */ else {
return Qnil;
}
}
return rb_funcall(val, m, 0);
} }
VALUE VALUE
@ -864,18 +871,15 @@ rb_convert_type(val, type, tname, method)
int type; int type;
const char *tname, *method; const char *tname, *method;
{ {
struct arg_to arg1, arg2; VALUE v;
if (TYPE(val) == type) return val; if (TYPE(val) == type) return val;
arg1.val = arg2.val = val; v = convert_type(val, tname, method, Qtrue);
arg1.s = method; if (TYPE(v) != type) {
arg2.s = tname;
val = rb_rescue(to_type, (VALUE)&arg1, fail_to_type, (VALUE)&arg2);
if (TYPE(val) != type) {
rb_raise(rb_eTypeError, "%s#%s should return %s", 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 VALUE
@ -884,18 +888,16 @@ rb_check_convert_type(val, type, tname, method)
int type; int type;
const char *tname, *method; const char *tname, *method;
{ {
struct arg_to arg1, arg2; VALUE v;
if (TYPE(val) == type) return val; if (TYPE(val) == type) return val;
arg1.val = arg2.val = val; v = convert_type(val, tname, method, Qfalse);
arg1.s = method; if (NIL_P(v)) return Qnil;
arg2.s = tname; if (TYPE(v) != type) {
val = rb_rescue(to_type, (VALUE)&arg1, 0, 0);
if (!NIL_P(val) && TYPE(val) != type) {
rb_raise(rb_eTypeError, "%s#%s should return %s", 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 static VALUE
@ -903,18 +905,12 @@ rb_to_integer(val, method)
VALUE val; VALUE val;
char *method; char *method;
{ {
struct arg_to arg1, arg2; VALUE v = convert_type(val, "Integer", method, Qtrue);
if (!rb_obj_is_kind_of(v, rb_cInteger)) {
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)) {
rb_raise(rb_eTypeError, "%s#%s should return Integer", 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 VALUE
@ -983,7 +979,7 @@ rb_Float(val)
d = strtod(p, &end); d = strtod(p, &end);
if (p == end) { if (p == end) {
bad: bad:
rb_raise(rb_eArgError, "invalid value for Float(): \"%s\"", q); rb_invalid_str(q, "Float()");
} }
if (*end) { if (*end) {
if (*end == '_') { if (*end == '_') {

View file

@ -2145,7 +2145,7 @@ yycompile(f, line)
ruby__end__seen = 0; ruby__end__seen = 0;
ruby_eval_tree = 0; ruby_eval_tree = 0;
heredoc_end = 0; heredoc_end = 0;
ruby_sourcefile = f; ruby_sourcefile = strdup(f);
ruby_in_compile = 1; ruby_in_compile = 1;
n = yyparse(); n = yyparse();
ruby_debug_lines = 0; ruby_debug_lines = 0;

View file

@ -40,9 +40,6 @@ struct timeval rb_time_interval _((VALUE));
#ifdef HAVE_GETPRIORITY #ifdef HAVE_GETPRIORITY
# include <sys/resource.h> # include <sys/resource.h>
#endif #endif
#ifdef HAVE_VFORK_H
#include <vfork.h>
#endif
#include "st.h" #include "st.h"
#ifdef __EMX__ #ifdef __EMX__
@ -908,7 +905,7 @@ rb_f_system(argc, argv)
SafeStringValue(argv[i]); SafeStringValue(argv[i]);
} }
retry: retry:
switch (pid = vfork()) { switch (pid = fork()) {
case 0: case 0:
if (argc == 1 && prog == 0) { if (argc == 1 && prog == 0) {
rb_proc_exec(RSTRING(argv[0])->ptr); rb_proc_exec(RSTRING(argv[0])->ptr);

7
re.c
View file

@ -649,6 +649,13 @@ rb_reg_search(re, str, pos, reverse)
if (NIL_P(match) || FL_TEST(match, MATCH_BUSY)) { if (NIL_P(match) || FL_TEST(match, MATCH_BUSY)) {
match = match_alloc(); match = match_alloc();
} }
else {
if (rb_safe_level() >= 3)
OBJ_TAINT(match);
else
FL_UNSET(match, FL_TAINT);
}
re_copy_registers(RMATCH(match)->regs, &regs); re_copy_registers(RMATCH(match)->regs, &regs);
RMATCH(match)->str = rb_str_new4(str); RMATCH(match)->str = rb_str_new4(str);
rb_backref_set(match); rb_backref_set(match);

28
regex.c
View file

@ -1264,7 +1264,6 @@ re_compile_pattern(pattern, size, bufp)
bufp->fastmap_accurate = 0; bufp->fastmap_accurate = 0;
bufp->must = 0; bufp->must = 0;
bufp->must_skip = 0; bufp->must_skip = 0;
bufp->stclass = 0;
/* Initialize the syntax table. */ /* Initialize the syntax table. */
init_syntax_once(); init_syntax_once();
@ -2389,9 +2388,6 @@ re_compile_pattern(pattern, size, bufp)
p0 += mcnt+1; p0 += mcnt+1;
mcnt = EXTRACT_UNSIGNED_AND_INCR(p0); mcnt = EXTRACT_UNSIGNED_AND_INCR(p0);
p0 += 8*mcnt; p0 += 8*mcnt;
if (*p0 == maybe_finalize_jump) {
bufp->stclass = laststart;
}
} }
} }
} }
@ -3285,30 +3281,6 @@ re_search(bufp, string, size, startpos, range, regs)
startpos++; 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: advance:

View file

@ -132,7 +132,6 @@ struct re_pattern_buffer
char *must; /* Pointer to exact pattern which strings should have char *must; /* Pointer to exact pattern which strings should have
to be matched. */ to be matched. */
int *must_skip; /* Pointer to exact pattern skip table for bm_search */ 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 options; /* Flags for options such as extended_pattern. */
long re_nsub; /* Number of subexpressions found by the compiler. */ long re_nsub; /* Number of subexpressions found by the compiler. */
char fastmap_accurate; char fastmap_accurate;