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@975 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2000-09-26 07:07:13 +00:00
parent 684a768ef5
commit c7a316947f
3 changed files with 34 additions and 53 deletions

View file

@ -1,3 +1,8 @@
Tue Sep 26 15:59:50 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
* object.c (rb_mod_dup): metaclasses of class/module should not be
cleared by rb_obj_dup.
Tue Sep 26 02:44:54 2000 Yukihiro Matsumoto <matz@ruby-lang.org> Tue Sep 26 02:44:54 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
* gc.c (GC_MALLOC_LIMIT): size extended. * gc.c (GC_MALLOC_LIMIT): size extended.

View file

@ -113,7 +113,6 @@ rb_obj_dup(obj)
} }
if (!SPECIAL_CONST_P(dup)) { if (!SPECIAL_CONST_P(dup)) {
OBJSETUP(dup, rb_obj_type(obj), BUILTIN_TYPE(obj)); OBJSETUP(dup, rb_obj_type(obj), BUILTIN_TYPE(obj));
OBJ_INFECT(dup, obj);
} }
return dup; return dup;
} }
@ -471,7 +470,6 @@ rb_obj_alloc(klass)
{ {
NEWOBJ(obj, struct RObject); NEWOBJ(obj, struct RObject);
OBJSETUP(obj, klass, T_OBJECT); OBJSETUP(obj, klass, T_OBJECT);
obj->iv_tbl = 0;
return (VALUE)obj; return (VALUE)obj;
} }
@ -530,6 +528,15 @@ rb_mod_clone(module)
return (VALUE)clone; return (VALUE)clone;
} }
static VALUE
rb_mod_dup(module)
VALUE module;
{
VALUE dup = rb_mod_clone(module);
OBJSETUP(dup, RBASIC(module)->klass, BUILTIN_TYPE(module));
return dup;
}
static VALUE static VALUE
rb_mod_to_s(klass) rb_mod_to_s(klass)
VALUE klass; VALUE klass;
@ -1153,6 +1160,7 @@ Init_Object()
rb_define_method(rb_cModule, ">", rb_mod_gt, 1); rb_define_method(rb_cModule, ">", rb_mod_gt, 1);
rb_define_method(rb_cModule, ">=", rb_mod_ge, 1); rb_define_method(rb_cModule, ">=", rb_mod_ge, 1);
rb_define_method(rb_cModule, "clone", rb_mod_clone, 0); rb_define_method(rb_cModule, "clone", rb_mod_clone, 0);
rb_define_method(rb_cModule, "dup", rb_mod_dup, 0);
rb_define_method(rb_cModule, "to_s", rb_mod_to_s, 0); rb_define_method(rb_cModule, "to_s", rb_mod_to_s, 0);
rb_define_method(rb_cModule, "included_modules", rb_mod_included_modules, 0); rb_define_method(rb_cModule, "included_modules", rb_mod_included_modules, 0);
rb_define_method(rb_cModule, "name", rb_mod_name, 0); rb_define_method(rb_cModule, "name", rb_mod_name, 0);

70
regex.c
View file

@ -84,8 +84,6 @@ void *xrealloc _((void*,size_t));
void xfree _((void*)); void xfree _((void*));
#endif #endif
#define NO_ALLOCA /* try it out for now */
#ifndef NO_ALLOCA
/* Make alloca work the best possible way. */ /* Make alloca work the best possible way. */
#ifdef __GNUC__ #ifdef __GNUC__
# ifndef atarist # ifndef atarist
@ -111,73 +109,55 @@ char *alloca();
# include <strings.h> # include <strings.h>
#endif #endif
#define RE_ALLOCATE alloca
#ifdef C_ALLOCA #ifdef C_ALLOCA
#define FREE_VARIABLES() alloca(0) #define FREE_VARIABLES() alloca(0)
#else #else
#define FREE_VARIABLES() #define FREE_VARIABLES()
#endif #endif
#define FREE_AND_RETURN_VOID(stackb) return
#define FREE_AND_RETURN(stackb,val) return(val)
#define DOUBLE_STACK(stackx,stackb,len,type) \
(stackx = (type*)alloca(2 * len * sizeof(type)), \
/* Only copy what is in use. */ \
(type*)memcpy(stackx, stackb, len * sizeof (type)))
#else /* NO_ALLOCA defined */
#define RE_ALLOCATE xmalloc
#define FREE_VARIABLES()
#define FREE_AND_RETURN_VOID(stackb) do { \ #define FREE_AND_RETURN_VOID(stackb) do { \
FREE_VARIABLES(); \
if (stackb != stacka) xfree(stackb); \ if (stackb != stacka) xfree(stackb); \
return; \ return; \
} while(0) } while(0)
#define FREE_AND_RETURN(stackb,val) do { \ #define FREE_AND_RETURN(stackb,val) do { \
FREE_VARIABLES(); \
if (stackb != stacka) xfree(stackb); \ if (stackb != stacka) xfree(stackb); \
return(val); \ return(val); \
} while(0) } while(0)
#define DOUBLE_STACK(stackx,stackb,len,type) do { \ #define DOUBLE_STACK(type) do { \
type *stackx; \
unsigned int xlen = stacke - stackb; \
if (stackb == stacka) { \ if (stackb == stacka) { \
stackx = (type*)xmalloc(2*len*sizeof(type)); \ stackx = (type*)xmalloc(2 * xlen * sizeof(type)); \
memcpy(stackx, stackb, xlen * sizeof (type)); \
} \ } \
else { \ else { \
stackx = (type*)xrealloc(stackb, 2 * len * sizeof(type)); \ stackx = (type*)xrealloc(stackb, 2 * xlen * sizeof(type)); \
} \ } \
/* Rearrange the pointers. */ \
stackp = stackx + (stackp - stackb); \
stackb = stackx; \
stacke = stackb + 2 * xlen; \
} while (0) } while (0)
#endif /* NO_ALLOCA */ #define RE_TALLOC(n,t) ((t*)alloca((n)*sizeof(t)))
#define RE_TALLOC(n,t) ((t*)RE_ALLOCATE((n)*sizeof(t)))
#define TMALLOC(n,t) ((t*)xmalloc((n)*sizeof(t))) #define TMALLOC(n,t) ((t*)xmalloc((n)*sizeof(t)))
#define TREALLOC(s,n,t) (s=((t*)xrealloc(s,(n)*sizeof(t)))) #define TREALLOC(s,n,t) (s=((t*)xrealloc(s,(n)*sizeof(t))))
#define EXPAND_FAIL_STACK(stackx,stackb,len) \ #define EXPAND_FAIL_STACK() DOUBLE_STACK(unsigned char*)
do { \
/* Roughly double the size of the stack. */ \
DOUBLE_STACK(stackx,stackb,len,unsigned char*); \
/* Rearrange the pointers. */ \
stackp = stackx + (stackp - stackb); \
stackb = stackx; \
stacke = stackb + 2 * len; \
} while (0)
#define ENSURE_FAIL_STACK(n) \ #define ENSURE_FAIL_STACK(n) \
do { \ do { \
if (stacke - stackp <= (n)) { \ if (stacke - stackp <= (n)) { \
unsigned char **stackx; \
unsigned int len = stacke - stackb; \
/* if (len > re_max_failures * MAX_NUM_FAILURE_ITEMS) \ /* if (len > re_max_failures * MAX_NUM_FAILURE_ITEMS) \
{ \ { \
FREE_VARIABLES(); \
FREE_AND_RETURN(stackb,(-2)); \ FREE_AND_RETURN(stackb,(-2)); \
}*/ \ }*/ \
\ \
/* Roughly double the size of the stack. */ \ /* Roughly double the size of the stack. */ \
EXPAND_FAIL_STACK(stackx, stackb, len); \ EXPAND_FAIL_STACK(); \
} \ } \
} while (0) } while (0)
@ -1794,14 +1774,7 @@ re_compile_pattern(pattern, size, bufp)
} }
if (c == '#') break; if (c == '#') break;
if (stackp+8 >= stacke) { if (stackp+8 >= stacke) {
int *stackx; DOUBLE_STACK(int);
unsigned int len = stacke - stackb;
DOUBLE_STACK(stackx,stackb,len,int);
/* Rearrange the pointers. */
stackp = stackx + (stackp - stackb);
stackb = stackx;
stacke = stackb + 2 * len;
} }
/* Laststart should point to the start_memory that we are about /* Laststart should point to the start_memory that we are about
@ -2891,10 +2864,7 @@ re_compile_fastmap(bufp)
EXTRACT_NUMBER_AND_INCR(j, p); EXTRACT_NUMBER_AND_INCR(j, p);
if (p + j < pend) { if (p + j < pend) {
if (stackp == stacke) { if (stackp == stacke) {
unsigned char **stackx; EXPAND_FAIL_STACK();
unsigned int len = stacke - stackb;
EXPAND_FAIL_STACK(stackx, stackb, len);
} }
*++stackp = p + j; /* push */ *++stackp = p + j; /* push */
} }
@ -3564,7 +3534,7 @@ re_match(bufp, string_arg, size, pos, regs)
``dummy''; if a failure happens and the failure point is a dummy, it ``dummy''; if a failure happens and the failure point is a dummy, it
gets discarded and the next next one is tried. */ gets discarded and the next next one is tried. */
unsigned char *stacka[MAX_NUM_FAILURE_ITEMS * NFAILURES]; unsigned char **stacka;
unsigned char **stackb; unsigned char **stackb;
unsigned char **stackp; unsigned char **stackp;
unsigned char **stacke; unsigned char **stacke;
@ -3613,6 +3583,7 @@ re_match(bufp, string_arg, size, pos, regs)
} }
/* Initialize the stack. */ /* Initialize the stack. */
stacka = RE_TALLOC(MAX_NUM_FAILURE_ITEMS * NFAILURES, unsigned char*);
stackb = stacka; stackb = stacka;
stackp = stackb; stackp = stackb;
stacke = &stackb[MAX_NUM_FAILURE_ITEMS * NFAILURES]; stacke = &stackb[MAX_NUM_FAILURE_ITEMS * NFAILURES];
@ -3714,7 +3685,6 @@ re_match(bufp, string_arg, size, pos, regs)
regs->end[mcnt] = regend[mcnt] - string; regs->end[mcnt] = regend[mcnt] - string;
} }
} }
FREE_VARIABLES();
FREE_AND_RETURN(stackb, (d - pos - string)); FREE_AND_RETURN(stackb, (d - pos - string));
} }
@ -3797,7 +3767,6 @@ re_match(bufp, string_arg, size, pos, regs)
case start_nowidth: case start_nowidth:
PUSH_FAILURE_POINT(0, d); PUSH_FAILURE_POINT(0, d);
if (stackp - stackb > RE_DUP_MAX) { if (stackp - stackb > RE_DUP_MAX) {
FREE_VARIABLES();
FREE_AND_RETURN(stackb,(-2)); FREE_AND_RETURN(stackb,(-2));
} }
EXTRACT_NUMBER_AND_INCR(mcnt, p); EXTRACT_NUMBER_AND_INCR(mcnt, p);
@ -4375,7 +4344,6 @@ re_match(bufp, string_arg, size, pos, regs)
if (best_regs_set) if (best_regs_set)
goto restore_best_regs; goto restore_best_regs;
FREE_VARIABLES();
FREE_AND_RETURN(stackb,(-1)); /* Failure to match. */ FREE_AND_RETURN(stackb,(-1)); /* Failure to match. */
} }