git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@545 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 1999-10-16 10:33:06 +00:00
parent 3196645aee
commit 40a3f601e4
6 changed files with 53 additions and 28 deletions

View File

@ -1,5 +1,7 @@
Fri Oct 15 01:32:31 1999 WATANABE Hirofumi <eban@os.rim.or.jp> Fri Oct 15 01:32:31 1999 WATANABE Hirofumi <eban@os.rim.or.jp>
* io.c (rb_io_ctl) :need to use NUM2ULONG, not NUM2INT.
* ext/Win32API/Win32API.c (Win32API_Call): need to use NUM2ULONG, * ext/Win32API/Win32API.c (Win32API_Call): need to use NUM2ULONG,
not NUM2INT. not NUM2INT.
@ -20,6 +22,12 @@ Thu Oct 14 02:00:10 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
* parse.y (string): compile time string concatenation. * parse.y (string): compile time string concatenation.
Wed Oct 13 02:17:05 1999 EGUCHI Osamu <eguchi@shizuokanet.ne.jp>
* array.c (rb_ary_plus): remove recursion.
* array.c (rb_ary_sort_bang): detect modify attempt.
Wed Oct 13 02:17:05 1999 Yukihiro Matsumoto <matz@netlab.co.jp> Wed Oct 13 02:17:05 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
* eval.c (block_pass): should copy block to prevent modifications. * eval.c (block_pass): should copy block to prevent modifications.

12
array.c
View File

@ -914,9 +914,9 @@ VALUE
rb_ary_sort_bang(ary) rb_ary_sort_bang(ary)
VALUE ary; VALUE ary;
{ {
rb_ary_modify(ary);
if (RARRAY(ary)->len <= 1) return ary; if (RARRAY(ary)->len <= 1) return ary;
rb_ary_modify(ary);
FL_SET(ary, ARY_TMPLOCK); /* prohibit modification during sort */ FL_SET(ary, ARY_TMPLOCK); /* prohibit modification during sort */
rb_ensure(sort_internal, ary, sort_unlock, ary); rb_ensure(sort_internal, ary, sort_unlock, ary);
return ary; return ary;
@ -926,8 +926,9 @@ VALUE
rb_ary_sort(ary) rb_ary_sort(ary)
VALUE ary; VALUE ary;
{ {
ary = rb_ary_dup(ary);
if (RARRAY(ary)->len == 0) return ary; if (RARRAY(ary)->len == 0) return ary;
return rb_ary_sort_bang(rb_ary_dup(ary)); return rb_ary_sort_bang(ary);
} }
VALUE VALUE
@ -966,11 +967,11 @@ rb_ary_delete_at(ary, at)
long i, pos = NUM2LONG(at), len = RARRAY(ary)->len; long i, pos = NUM2LONG(at), len = RARRAY(ary)->len;
VALUE del = Qnil; VALUE del = Qnil;
rb_ary_modify(ary);
if (pos >= len) return Qnil; if (pos >= len) return Qnil;
if (pos < 0) pos += len; if (pos < 0) pos += len;
if (pos < 0) return Qnil; if (pos < 0) return Qnil;
rb_ary_modify(ary);
del = RARRAY(ary)->ptr[pos]; del = RARRAY(ary)->ptr[pos];
for (i = pos + 1; i < len; i++, pos++) { for (i = pos + 1; i < len; i++, pos++) {
RARRAY(ary)->ptr[pos] = RARRAY(ary)->ptr[i]; RARRAY(ary)->ptr[pos] = RARRAY(ary)->ptr[i];
@ -1090,7 +1091,7 @@ rb_ary_plus(x, y)
VALUE z; VALUE z;
if (TYPE(y) != T_ARRAY) { if (TYPE(y) != T_ARRAY) {
return rb_ary_plus(x, rb_Array(y)); y = rb_Array(y);
} }
z = rb_ary_new2(RARRAY(x)->len + RARRAY(y)->len); z = rb_ary_new2(RARRAY(x)->len + RARRAY(y)->len);
@ -1106,8 +1107,9 @@ rb_ary_concat(x, y)
{ {
VALUE *p, *pend; VALUE *p, *pend;
rb_ary_modify(x);
if (TYPE(y) != T_ARRAY) { if (TYPE(y) != T_ARRAY) {
return rb_ary_concat(x, rb_Array(y)); y = rb_Array(y);
} }
p = RARRAY(y)->ptr; p = RARRAY(y)->ptr;

14
error.c
View File

@ -34,14 +34,20 @@ err_snprintf(buf, len, fmt, args)
int len; int len;
va_list args; va_list args;
{ {
int n;
if (!ruby_sourcefile) { if (!ruby_sourcefile) {
vsnprintf(buf, len, fmt, args); vsnprintf(buf, len, fmt, args);
return;
}
else if (ruby_sourceline == 0) {
n = snprintf(buf, len, "%s: ", ruby_sourcefile);
} }
else { else {
int n = snprintf(buf, len, "%s:%d: ", ruby_sourcefile, ruby_sourceline); n = snprintf(buf, len, "%s:%d: ", ruby_sourcefile, ruby_sourceline);
if (len > n) { }
vsnprintf((char*)buf+n, len-n, fmt, args); if (len > n) {
} vsnprintf((char*)buf+n, len-n, fmt, args);
} }
} }

6
eval.c
View File

@ -793,6 +793,9 @@ error_pos()
fprintf(stderr, "%s:%d:in `%s'", ruby_sourcefile, ruby_sourceline, fprintf(stderr, "%s:%d:in `%s'", ruby_sourcefile, ruby_sourceline,
rb_id2name(ruby_frame->last_func)); rb_id2name(ruby_frame->last_func));
} }
else if (ruby_sourceline == 0) {
fprintf(stderr, "%s", ruby_sourcefile);
}
else { else {
fprintf(stderr, "%s:%d", ruby_sourcefile, ruby_sourceline); fprintf(stderr, "%s:%d", ruby_sourcefile, ruby_sourceline);
} }
@ -4149,6 +4152,9 @@ backtrace(lev)
ruby_sourcefile, ruby_sourceline, ruby_sourcefile, ruby_sourceline,
rb_id2name(frame->last_func)); rb_id2name(frame->last_func));
} }
else if (ruby_sourceline == 0) {
snprintf(buf, BUFSIZ, "%s", ruby_sourcefile);
}
else { else {
snprintf(buf, BUFSIZ, "%s:%d", ruby_sourcefile, ruby_sourceline); snprintf(buf, BUFSIZ, "%s:%d", ruby_sourcefile, ruby_sourceline);
} }

2
io.c
View File

@ -2627,7 +2627,7 @@ rb_io_ctl(io, req, arg, io_p)
int io_p; int io_p;
{ {
#if !defined(MSDOS) && !defined(__human68k__) #if !defined(MSDOS) && !defined(__human68k__)
int cmd = NUM2INT(req); int cmd = NUM2ULONG(req);
OpenFile *fptr; OpenFile *fptr;
int len = 0; int len = 0;
int fd; int fd;

39
ruby.c
View File

@ -44,20 +44,17 @@ char *strstr _((const char*,const char*));
char *getenv(); char *getenv();
#endif #endif
static int version, copyright;
VALUE ruby_debug = Qfalse; VALUE ruby_debug = Qfalse;
VALUE ruby_verbose = Qfalse; VALUE ruby_verbose = Qfalse;
static int sflag = Qfalse; static int sflag = 0;
static int xflag = 0;
extern int yydebug;
char *ruby_inplace_mode = Qfalse; char *ruby_inplace_mode = Qfalse;
# ifndef strdup # ifndef strdup
char *strdup(); char *strdup();
# endif # endif
extern int yydebug;
static int xflag = Qfalse;
static void load_stdin _((void)); static void load_stdin _((void));
static void load_file _((char *, int)); static void load_file _((char *, int));
static void forbid_setid _((const char *)); static void forbid_setid _((const char *));
@ -242,6 +239,7 @@ void
require_libraries() require_libraries()
{ {
extern NODE *ruby_eval_tree; extern NODE *ruby_eval_tree;
char *orig_sourcefile = ruby_sourcefile;
NODE *save; NODE *save;
struct req_list *list = req_list_head.next; struct req_list *list = req_list_head.next;
struct req_list *tmp; struct req_list *tmp;
@ -256,6 +254,7 @@ require_libraries()
list = tmp; list = tmp;
} }
ruby_eval_tree = save; ruby_eval_tree = save;
ruby_sourcefile = orig_sourcefile;
} }
extern void Init_ext _((void)); extern void Init_ext _((void));
@ -302,6 +301,10 @@ proc_options(argc, argv)
int do_search; int do_search;
char *s; char *s;
int version = 0;
int copyright = 0;
int verbose = 0;
if (argc == 0) return; if (argc == 0) return;
version = Qfalse; version = Qfalse;
@ -328,7 +331,7 @@ proc_options(argc, argv)
case 'd': case 'd':
ruby_debug = Qtrue; ruby_debug = Qtrue;
ruby_verbose |= 1; ruby_verbose = Qtrue;
s++; s++;
goto reswitch; goto reswitch;
@ -339,9 +342,9 @@ proc_options(argc, argv)
case 'v': case 'v':
ruby_show_version(); ruby_show_version();
ruby_verbose = 2; verbose = 1;
case 'w': case 'w':
ruby_verbose |= 1; ruby_verbose = Qtrue;
s++; s++;
goto reswitch; goto reswitch;
@ -352,7 +355,7 @@ proc_options(argc, argv)
case 's': case 's':
forbid_setid("-s"); forbid_setid("-s");
sflag = Qtrue; sflag = 1;
s++; s++;
goto reswitch; goto reswitch;
@ -490,8 +493,10 @@ proc_options(argc, argv)
ruby_debug = 1; ruby_debug = 1;
else if (strcmp("version", s) == 0) else if (strcmp("version", s) == 0)
version = 1; version = 1;
else if (strcmp("verbose", s) == 0) else if (strcmp("verbose", s) == 0) {
ruby_verbose = 2; verbose = 1;
ruby_verbose = Qtrue;
}
else if (strcmp("yydebug", s) == 0) else if (strcmp("yydebug", s) == 0)
yydebug = 1; yydebug = 1;
else if (strcmp("help", s) == 0) { else if (strcmp("help", s) == 0) {
@ -536,11 +541,8 @@ proc_options(argc, argv)
ruby_show_copyright(); ruby_show_copyright();
} }
if (ruby_verbose) ruby_verbose = Qtrue;
if (ruby_debug) ruby_debug = Qtrue;
if (!e_script && argc == 0) { /* no more args */ if (!e_script && argc == 0) { /* no more args */
if (ruby_verbose == 3) exit(0); if (verbose) exit(0);
script = "-"; script = "-";
} }
else { else {
@ -572,6 +574,7 @@ proc_options(argc, argv)
Init_ext(); /* should be called here for some reason :-( */ Init_ext(); /* should be called here for some reason :-( */
require_libraries(); require_libraries();
ruby_sourcefile = argv0;
if (e_script) { if (e_script) {
rb_compile_string(script, e_script, 1); rb_compile_string(script, e_script, 1);
} }
@ -583,8 +586,8 @@ proc_options(argc, argv)
} }
process_sflag(); process_sflag();
sflag = Qfalse; sflag = 0;
xflag = Qfalse; xflag = 0;
} }
extern int ruby__end__seen; extern int ruby__end__seen;