Skip to content

Commit

Permalink
* process.c (rb_f_system): abandon vfork.
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
matz committed Jan 4, 2002
1 parent a7685a6 commit 459031e
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 104 deletions.
4 changes: 2 additions & 2 deletions bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down
1 change: 0 additions & 1 deletion configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand Down
14 changes: 9 additions & 5 deletions defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions error.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
1 change: 1 addition & 0 deletions intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*)));
Expand Down
5 changes: 1 addition & 4 deletions io.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ struct timeval {
};
#endif
#endif
#ifdef HAVE_VFORK_H
#include <vfork.h>
#endif

#include <sys/stat.h>

Expand Down Expand Up @@ -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]);
Expand Down
4 changes: 4 additions & 0 deletions lib/debug.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
end

require 'tracer'
require 'pp'

class Tracer
def Tracer.trace_func(*vars)
Expand Down Expand Up @@ -510,6 +511,9 @@ def debug_command(file, line, id, binding)
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

Expand Down
34 changes: 22 additions & 12 deletions misc/ruby-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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))
Expand Down
82 changes: 39 additions & 43 deletions object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -884,37 +888,29 @@ 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
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
Expand Down Expand Up @@ -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 == '_') {
Expand Down
2 changes: 1 addition & 1 deletion parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions process.c
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions re.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, &regs);
RMATCH(match)->str = rb_str_new4(str);
rb_backref_set(match);
Expand Down
Loading

0 comments on commit 459031e

Please sign in to comment.