1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2000-09-25 09:15:08 +00:00
parent 40412b7730
commit b9228a014b
7 changed files with 50 additions and 32 deletions

View file

@ -1,3 +1,8 @@
Mon Sep 25 18:13:07 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_add_method): cache mismatch by method
definition. need to clear_cache_by_id every time.
Mon Sep 25 13:31:45 2000 WATANABE Hirofumi <eban@os.rim.or.jp> Mon Sep 25 13:31:45 2000 WATANABE Hirofumi <eban@os.rim.or.jp>
* win32/win32.c (NtCmdGlob): substitute '\\' with '/'. * win32/win32.c (NtCmdGlob): substitute '\\' with '/'.
@ -10,6 +15,11 @@ Sun Sep 24 03:01:53 2000 Minero Aoki <aamine@dp.u-netsurf.ne.jp>
* lib/net/protocol.rb, http.rb: typo. * lib/net/protocol.rb, http.rb: typo.
Sat Sep 23 07:33:20 2000 Aleksi Niemela <aleksi.niemela@cinnober.com>
* regex.c (re_compile_pattern): nicer regexp error messages for
invalid patterns.
Sat Sep 23 03:06:25 2000 Yukihiro Matsumoto <matz@ruby-lang.org> Sat Sep 23 03:06:25 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
* variable.c (rb_autoload_load): should not require already * variable.c (rb_autoload_load): should not require already

11
eval.c
View file

@ -238,6 +238,7 @@ rb_add_method(klass, mid, node, noex)
if (OBJ_FROZEN(klass)) rb_error_frozen("class/module"); if (OBJ_FROZEN(klass)) rb_error_frozen("class/module");
body = NEW_METHOD(node, noex); body = NEW_METHOD(node, noex);
st_insert(RCLASS(klass)->m_tbl, mid, body); st_insert(RCLASS(klass)->m_tbl, mid, body);
rb_clear_cache_by_id(mid);
} }
static NODE* static NODE*
@ -358,7 +359,6 @@ rb_disable_super(klass, name)
body->nd_noex |= NOEX_UNDEF; body->nd_noex |= NOEX_UNDEF;
} }
else { else {
rb_clear_cache_by_id(mid);
rb_add_method(klass, mid, 0, NOEX_UNDEF); rb_add_method(klass, mid, 0, NOEX_UNDEF);
} }
} }
@ -408,7 +408,6 @@ rb_export_method(klass, name, noex)
body->nd_noex = noex; body->nd_noex = noex;
} }
else { else {
rb_clear_cache_by_id(name);
rb_add_method(klass, name, NEW_ZSUPER(), noex); rb_add_method(klass, name, NEW_ZSUPER(), noex);
} }
} }
@ -1495,7 +1494,6 @@ rb_undef(klass, id)
rb_id2name(id),s0,rb_class2name(c)); rb_id2name(id),s0,rb_class2name(c));
} }
rb_add_method(klass, id, 0, NOEX_PUBLIC); rb_add_method(klass, id, 0, NOEX_PUBLIC);
rb_clear_cache_by_id(id);
} }
static VALUE static VALUE
@ -2825,7 +2823,6 @@ rb_eval(self, n)
if (RTEST(ruby_verbose) && ruby_class == origin && body->nd_cnt == 0) { if (RTEST(ruby_verbose) && ruby_class == origin && body->nd_cnt == 0) {
rb_warning("discarding old %s", rb_id2name(node->nd_mid)); rb_warning("discarding old %s", rb_id2name(node->nd_mid));
} }
rb_clear_cache_by_id(node->nd_mid);
if (node->nd_noex) { /* toplevel */ if (node->nd_noex) { /* toplevel */
/* should upgrade to rb_warn() if no super was called inside? */ /* should upgrade to rb_warn() if no super was called inside? */
rb_warning("overriding global function `%s'", rb_warning("overriding global function `%s'",
@ -2891,7 +2888,6 @@ rb_eval(self, n)
rb_warning("redefine %s", rb_id2name(node->nd_mid)); rb_warning("redefine %s", rb_id2name(node->nd_mid));
} }
} }
rb_clear_cache_by_id(node->nd_mid);
rb_add_method(klass, node->nd_mid, node->nd_defn, rb_add_method(klass, node->nd_mid, node->nd_defn,
NOEX_PUBLIC|(body?body->nd_noex&NOEX_UNDEF:0)); NOEX_PUBLIC|(body?body->nd_noex&NOEX_UNDEF:0));
rb_funcall(recv, singleton_added, 1, ID2SYM(node->nd_mid)); rb_funcall(recv, singleton_added, 1, ID2SYM(node->nd_mid));
@ -5040,8 +5036,8 @@ rb_feature_p(feature, wait)
if (strcmp(f, feature) == 0) { if (strcmp(f, feature) == 0) {
goto load_wait; goto load_wait;
} }
len = strlen(feature); len = strlen(f);
if (strncmp(f, feature, len) == 0) { if (strncmp(f, feature, strlen(feature)) == 0) {
if (strcmp(f+len, ".so") == 0) { if (strcmp(f+len, ".so") == 0) {
return Qtrue; return Qtrue;
} }
@ -5348,7 +5344,6 @@ rb_mod_modfunc(argc, argv, module)
if (body == 0 || body->nd_body == 0) { if (body == 0 || body->nd_body == 0) {
rb_bug("undefined method `%s'; can't happen", rb_id2name(id)); rb_bug("undefined method `%s'; can't happen", rb_id2name(id));
} }
rb_clear_cache_by_id(id);
rb_add_method(rb_singleton_class(module), id, body->nd_body, NOEX_PUBLIC); rb_add_method(rb_singleton_class(module), id, body->nd_body, NOEX_PUBLIC);
rb_funcall(module, singleton_added, 1, ID2SYM(id)); rb_funcall(module, singleton_added, 1, ID2SYM(id));
} }

8
file.c
View file

@ -1980,15 +1980,14 @@ rb_stat_sticky(obj)
return Qfalse; return Qfalse;
} }
static VALUE rb_mConst; static VALUE rb_mFConst;
void void
rb_file_const(name, value) rb_file_const(name, value)
const char *name; const char *name;
VALUE value; VALUE value;
{ {
rb_define_const(rb_cFile, name, value); rb_define_const(rb_mFConst, name, value);
rb_define_const(rb_mConst, name, value);
} }
static int static int
@ -2240,7 +2239,8 @@ Init_File()
rb_define_method(rb_cFile, "flock", rb_file_flock, 1); rb_define_method(rb_cFile, "flock", rb_file_flock, 1);
rb_mConst = rb_define_module_under(rb_cFile, "Constants"); rb_mFConst = rb_define_module_under(rb_cFile, "Constants");
rb_include_module(rb_cFile, rb_mFConst);
rb_file_const("LOCK_SH", INT2FIX(LOCK_SH)); rb_file_const("LOCK_SH", INT2FIX(LOCK_SH));
rb_file_const("LOCK_EX", INT2FIX(LOCK_EX)); rb_file_const("LOCK_EX", INT2FIX(LOCK_EX));
rb_file_const("LOCK_UN", INT2FIX(LOCK_UN)); rb_file_const("LOCK_UN", INT2FIX(LOCK_UN));

1
gc.c
View file

@ -1298,4 +1298,3 @@ xfree(ptr)
{ {
ruby_xfree(ptr); ruby_xfree(ptr);
} }

View file

@ -44,13 +44,12 @@ class ThreadsWait
Exception2MessageMapper.extend_to(binding) Exception2MessageMapper.extend_to(binding)
def_exception("ErrNoWaitingThread", "No threads for waiting.") def_exception("ErrNoWaitingThread", "No threads for waiting.")
def_exception("ErrNoFinshedThread", "No finished threads.") def_exception("ErrNoFinishedThread", "No finished threads.")
def ThreadsWait.all_waits(*threads) def ThreadsWait.all_waits(*threads)
tw = ThreadsWait.new(*threads) tw = ThreadsWait.new(*threads)
if block_given? if block_given?
tw.all_waits do tw.all_waits do |th|
|th|
yield th yield th
end end
else else
@ -96,11 +95,12 @@ class ThreadsWait
# adds thread(s) to join, no wait. # adds thread(s) to join, no wait.
def join_nowait(*threads) def join_nowait(*threads)
@threads.concat threads.flatten threads.flatten!
@threads.concat threads
for th in threads for th in threads
Thread.start do Thread.start(th) do |t|
th = th.join t.join
@wait_queue.push th @wait_queue.push t
end end
end end
end end

36
regex.c
View file

@ -1190,6 +1190,8 @@ re_compile_pattern(pattern, size, bufp)
register unsigned int c, c1; register unsigned int c, c1;
const char *p0; const char *p0;
int numlen; int numlen;
#define ERROR_MSG_MAX_SIZE 200
static char error_msg[ERROR_MSG_MAX_SIZE+1];
/* Address of the count-byte of the most recently inserted `exactn' /* Address of the count-byte of the most recently inserted `exactn'
command. This makes it possible to tell whether a new exact-match command. This makes it possible to tell whether a new exact-match
@ -1318,7 +1320,10 @@ re_compile_pattern(pattern, size, bufp)
case '*': case '*':
/* If there is no previous pattern, char not special. */ /* If there is no previous pattern, char not special. */
if (!laststart) { if (!laststart) {
goto invalid_pattern; snprintf(error_msg, ERROR_MSG_MAX_SIZE,
"invalid regular expression; there's no previous pattern, to which '%c' would define cardinality at %d",
c, p-pattern);
FREE_AND_RETURN(stackb, error_msg);
} }
/* If there is a sequence of repetition chars, /* If there is a sequence of repetition chars,
collapse it down to just one. */ collapse it down to just one. */
@ -1400,7 +1405,7 @@ re_compile_pattern(pattern, size, bufp)
case '[': case '[':
if (p == pend) if (p == pend)
goto invalid_pattern; FREE_AND_RETURN(stackb, "invalid regular expression; '[' can't be the last character ie. can't start range at the end of pattern");
while ((b - bufp->buffer + 9 + (1 << BYTEWIDTH) / BYTEWIDTH) while ((b - bufp->buffer + 9 + (1 << BYTEWIDTH) / BYTEWIDTH)
> bufp->allocated) > bufp->allocated)
EXTEND_BUFFER; EXTEND_BUFFER;
@ -1441,7 +1446,7 @@ re_compile_pattern(pattern, size, bufp)
if (c == ']') { if (c == ']') {
if (p == p0 + 1) { if (p == p0 + 1) {
if (p == pend) if (p == pend)
goto invalid_pattern; FREE_AND_RETURN(stackb, "invalid regular expression; empty character class");
} }
else else
/* Stop if this isn't merely a ] inside a bracket /* Stop if this isn't merely a ] inside a bracket
@ -1452,7 +1457,7 @@ re_compile_pattern(pattern, size, bufp)
/* Look ahead to see if it's a range when the last thing /* Look ahead to see if it's a range when the last thing
was a character class. */ was a character class. */
if (had_char_class && c == '-' && *p != ']') if (had_char_class && c == '-' && *p != ']')
goto invalid_pattern; FREE_AND_RETURN(stackb, "invalid regular expression; can't use character class as a start value of range");
if (ismbchar(c)) { if (ismbchar(c)) {
PATFETCH_MBC(c); PATFETCH_MBC(c);
had_mbchar++; had_mbchar++;
@ -1582,7 +1587,7 @@ re_compile_pattern(pattern, size, bufp)
/* If pattern is `[[:'. */ /* If pattern is `[[:'. */
if (p == pend) if (p == pend)
goto invalid_pattern; FREE_AND_RETURN(stackb, "invalid regular expression; re can't end '[[:'");
for (;;) { for (;;) {
PATFETCH (c); PATFETCH (c);
@ -1611,14 +1616,17 @@ re_compile_pattern(pattern, size, bufp)
char is_upper = STREQ(str, "upper"); char is_upper = STREQ(str, "upper");
char is_xdigit = STREQ(str, "xdigit"); char is_xdigit = STREQ(str, "xdigit");
if (!IS_CHAR_CLASS(str)) if (!IS_CHAR_CLASS(str)){
goto invalid_pattern; snprintf(error_msg, ERROR_MSG_MAX_SIZE,
"invalid regular expression; [:%s:] is not a character class", str);
FREE_AND_RETURN(stackb, error_msg);
}
/* Throw away the ] at the end of the character class. */ /* Throw away the ] at the end of the character class. */
PATFETCH(c); PATFETCH(c);
if (p == pend) if (p == pend)
goto invalid_pattern; FREE_AND_RETURN(stackb, "invalid regular expression; range doesn't have ending ']' after a character class");
for (ch = 0; ch < 1 << BYTEWIDTH; ch++) { for (ch = 0; ch < 1 << BYTEWIDTH; ch++) {
if ( (is_alnum && ISALNUM(ch)) if ( (is_alnum && ISALNUM(ch))
@ -1938,9 +1946,14 @@ re_compile_pattern(pattern, size, bufp)
case '{': case '{':
/* If there is no previous pattern, this is an invalid pattern. */ /* If there is no previous pattern, this is an invalid pattern. */
if (!laststart || p == pend) { if (!laststart) {
goto invalid_pattern; snprintf(error_msg, ERROR_MSG_MAX_SIZE,
"invalid regular expression; there's no previous pattern, to which '{' would define cardinality at %d",
p-pattern);
FREE_AND_RETURN(stackb, error_msg);
} }
if( p == pend)
FREE_AND_RETURN(stackb, "invalid regular expression; '{' can't be last character" );
beg_interval = p - 1; beg_interval = p - 1;
@ -2119,7 +2132,8 @@ re_compile_pattern(pattern, size, bufp)
goto normal_char; goto normal_char;
case '\\': case '\\':
if (p == pend) goto invalid_pattern; if (p == pend)
FREE_AND_RETURN(stackb, "invalid regular expression; '\\' can't be last character");
/* Do not translate the character after the \, so that we can /* Do not translate the character after the \, so that we can
distinguish, e.g., \B from \b, even if we normally would distinguish, e.g., \B from \b, even if we normally would
translate, e.g., B to b. */ translate, e.g., B to b. */

2
ruby.h
View file

@ -136,7 +136,7 @@ VALUE rb_uint2inum _((unsigned long));
#define Qnil 4 #define Qnil 4
#define Qundef 6 /* undefined value for placeholder */ #define Qundef 6 /* undefined value for placeholder */
#define RTEST(v) ((VALUE)(v) & ~Qnil) #define RTEST(v) (((VALUE)(v) & ~Qnil) != 0)
#define NIL_P(v) ((VALUE)(v) == Qnil) #define NIL_P(v) ((VALUE)(v) == Qnil)
#define CLASS_OF(v) rb_class_of((VALUE)(v)) #define CLASS_OF(v) rb_class_of((VALUE)(v))