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

* bignum.c (bigdivrem): access boundary bug.

* marshal.c (w_object): prohibit dumping out singleton classes.

* object.c (rb_mod_to_s): distinguish singleton classes.

* variable.c (rb_class2name): it's ok to reveal NilClass,
  TrueClass, FalseClass.

* eval.c (rb_yield_0): preserve and restore ruby_cref as well.

* eval.c (is_defined): core dumped during instance_eval for
  special constants.

* eval.c (rb_eval): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1389 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2001-05-11 05:24:59 +00:00
parent 076ef717ac
commit cc043890f8
15 changed files with 133 additions and 58 deletions

View file

@ -1,3 +1,27 @@
Fri May 11 02:00:44 2001 Ryo HAYASAKA <ryoh@jaist.ac.jp>
* bignum.c (bigdivrem): access boundary bug.
Thu May 10 02:40:47 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* marshal.c (w_object): prohibit dumping out singleton classes.
* object.c (rb_mod_to_s): distinguish singleton classes.
* variable.c (rb_class2name): it's ok to reveal NilClass,
TrueClass, FalseClass.
Wed May 9 14:38:33 2001 K.Kosako <kosako@sofnec.co.jp>
* eval.c (rb_yield_0): preserve and restore ruby_cref as well.
Tue May 8 17:12:43 2001 K.Kosako <kosako@sofnec.co.jp>
* eval.c (is_defined): core dumped during instance_eval for
special constants.
* eval.c (rb_eval): ditto.
Mon May 7 15:58:45 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (arg): "||=" should not warn for uninitialized instance

2
ToDo
View file

@ -26,7 +26,6 @@ Language Spec.
* to_i returns nil if str contains no digit.
* raise exception by `` error
* jar like combined library package.
* "@foo ||= 44" should not warn you.
Hacking Interpreter
@ -83,6 +82,7 @@ Standard Libraries
* warn, warning for Ruby level
* hash etc. should handle self referenceing array/hash
* move NameError under StandardError.
* library to load per-user profile seeking .ruby_profile or ruby.ini file.
Extension Libraries

View file

@ -920,7 +920,7 @@ bigdivrem(x, y, divp, modp)
if (modp) { /* just normalize remainder */
*modp = rb_big_clone(z);
zds = BDIGITS(*modp);
while (!zds[ny-1]) ny--;
while (ny-- && !zds[ny]); ++ny;
if (dd) {
t2 = 0; i = ny;
while(i--) {

View file

@ -596,6 +596,8 @@ if test "$with_dln_a_out" != yes; then
rb_cv_dlopen=yes;;
sysv4*) LDSHARED='ld -G'
rb_cv_dlopen=yes;;
nto-qnx*) LDSHARED="qcc -shared"
rb_cv_dlopen=yes ;;
esix*|uxpds*) LDSHARED="ld -G"
rb_cv_dlopen=yes ;;
osf*) LDSHARED="$CC -shared"

6
dir.c
View file

@ -134,13 +134,13 @@ range(pat, test, flags)
((s) == string || pathname && isdirsep(*(s))))
static int
fnmatch(pat, string, flags)
char *pat;
char *string;
const char *pat;
const char *string;
int flags;
{
int c;
int test;
char *s = string;
const char *s = string;
int escape = !(flags & FNM_NOESCAPE);
int pathname = flags & FNM_PATHNAME;
int period = flags & FNM_PERIOD;

80
eval.c
View file

@ -173,6 +173,8 @@ print_undef(klass, id)
rb_class2name(klass));
}
static ID removed, singleton_removed, undefined, singleton_undefined;
#define CACHE_SIZE 0x800
#define CACHE_MASK 0x7ff
#define EXPR1(c,m) ((((c)>>3)^(m))&CACHE_MASK)
@ -319,6 +321,13 @@ remove_method(klass, mid)
rb_id2name(mid), rb_class2name(klass));
}
rb_clear_cache_by_id(mid);
if (FL_TEST(klass, FL_SINGLETON)) {
rb_funcall(rb_iv_get(klass, "__attached__"),
singleton_removed, 1, ID2SYM(mid));
}
else {
rb_funcall(klass, removed, 1, ID2SYM(mid));
}
}
void
@ -435,8 +444,8 @@ rb_method_boundp(klass, id, ex)
return Qfalse;
}
static ID init, eqq, each, aref, aset, match, to_ary;
static ID missing, added, singleton_added;
static ID init, eqq, each, aref, aset, match, to_ary, missing;
static ID added, singleton_added;
static ID __id__, __send__;
void
@ -1539,6 +1548,13 @@ rb_undef(klass, id)
}
rb_add_method(klass, id, 0, NOEX_PUBLIC);
rb_clear_cache_by_id(id);
if (FL_TEST(klass, FL_SINGLETON)) {
rb_funcall(rb_iv_get(klass, "__attached__"),
singleton_undefined, 1, ID2SYM(id));
}
else {
rb_funcall(klass, undefined, 1, ID2SYM(id));
}
}
static VALUE
@ -1582,6 +1598,13 @@ rb_alias(klass, name, def)
st_insert(RCLASS(klass)->m_tbl, name,
NEW_METHOD(NEW_FBODY(body, def, origin), orig->nd_noex));
rb_clear_cache_by_id(name);
if (FL_TEST(klass, FL_SINGLETON)) {
rb_funcall(rb_iv_get(klass, "__attached__"),
singleton_added, 1, ID2SYM(name));
}
else {
rb_funcall(klass, added, 1, ID2SYM(name));
}
}
static VALUE
@ -1808,6 +1831,12 @@ is_defined(self, node, buf)
break;
case NODE_CVAR:
if (NIL_P(ruby_cbase)) {
if (rb_cvar_defined(CLASS_OF(self), node->nd_vid)) {
return "class variable";
}
break;
}
if (!FL_TEST(ruby_cbase, FL_SINGLETON)) {
if (rb_cvar_defined(ruby_cbase, node->nd_vid)) {
return "class variable";
@ -2725,6 +2754,10 @@ rb_eval(self, n)
break;
case NODE_CVAR: /* normal method */
if (NIL_P(ruby_cbase)) {
result = rb_cvar_get(CLASS_OF(self), node->nd_vid);
break;
}
if (!FL_TEST(ruby_cbase, FL_SINGLETON)) {
result = rb_cvar_get(ruby_cbase, node->nd_vid);
break;
@ -3022,7 +3055,6 @@ rb_eval(self, n)
rb_raise(rb_eTypeError, "no class to make alias");
}
rb_alias(ruby_class, node->nd_new, node->nd_old);
rb_funcall(ruby_class, added, 1, ID2SYM(node->nd_mid));
result = Qnil;
break;
@ -3498,6 +3530,7 @@ rb_yield_0(val, self, klass, acheck)
{
NODE *node;
volatile VALUE result = Qnil;
volatile VALUE old_cref;
struct BLOCK *block;
struct SCOPE *old_scope;
struct FRAME frame;
@ -3514,6 +3547,8 @@ rb_yield_0(val, self, klass, acheck)
frame = block->frame;
frame.prev = ruby_frame;
ruby_frame = &(frame);
old_cref = (VALUE)ruby_cref;
ruby_cref = (NODE*)ruby_frame->cbase;
old_scope = ruby_scope;
ruby_scope = block->scope;
ruby_block = block->prev;
@ -3612,6 +3647,7 @@ rb_yield_0(val, self, klass, acheck)
POP_VARS();
ruby_block = block;
ruby_frame = ruby_frame->prev;
ruby_cref = (NODE*)old_cref;
if (ruby_scope->flags & SCOPE_DONT_RECYCLE)
scope_dup(old_scope);
ruby_scope = old_scope;
@ -4876,6 +4912,12 @@ rb_f_eval(argc, argv, self)
int line = 1;
rb_scan_args(argc, argv, "13", &src, &scope, &vfile, &vline);
if (ruby_safe_level >= 4) {
StringValue(src);
}
else {
SafeStringValue(src);
}
if (argc >= 3) {
file = StringValuePtr(vfile);
}
@ -4883,12 +4925,6 @@ rb_f_eval(argc, argv, self)
line = NUM2INT(vline);
}
if (ruby_safe_level >= 4) {
StringValue(src);
}
else {
SafeStringValue(src);
}
if (NIL_P(scope) && ruby_frame->prev) {
struct FRAME *prev;
VALUE val;
@ -5206,19 +5242,16 @@ rb_feature_p(feature, wait)
const char *feature;
int wait;
{
VALUE *p, *pend;
VALUE v;
char *f;
int len;
int i, len = strlen(feature);
p = RARRAY(rb_features)->ptr;
pend = p + RARRAY(rb_features)->len;
while (p < pend) {
VALUE v = *p;
for (i = 0; i < RARRAY(rb_features)->len; ++i) {
v = RARRAY(rb_features)->ptr[i];
f = StringValuePtr(v);
if (strcmp(f, feature) == 0) {
goto load_wait;
}
len = strlen(feature);
if (strncmp(f, feature, len) == 0) {
if (strcmp(f+len, ".so") == 0) {
return Qtrue;
@ -5228,7 +5261,6 @@ rb_feature_p(feature, wait)
return Qtrue;
}
}
p++;
}
return Qfalse;
@ -5550,13 +5582,6 @@ rb_mod_modfunc(argc, argv, module)
return module;
}
static VALUE
rb_mod_included(module, include)
VALUE module, include;
{
return Qnil;
}
static VALUE
rb_mod_append_features(module, include)
VALUE module, include;
@ -5841,6 +5866,10 @@ Init_eval()
missing = rb_intern("method_missing");
added = rb_intern("method_added");
singleton_added = rb_intern("singleton_method_added");
removed = rb_intern("method_removed");
singleton_removed = rb_intern("singleton_method_removed");
undefined = rb_intern("method_undefined");
singleton_undefined = rb_intern("singleton_method_undefined");
__id__ = rb_intern("__id__");
__send__ = rb_intern("__send__");
@ -5884,7 +5913,6 @@ Init_eval()
rb_define_private_method(rb_cModule, "append_features", rb_mod_append_features, 1);
rb_define_private_method(rb_cModule, "extend_object", rb_mod_extend_object, 1);
rb_define_private_method(rb_cModule, "include", rb_mod_include, -1);
rb_define_private_method(rb_cModule, "included", rb_mod_included, 1);
rb_define_private_method(rb_cModule, "public", rb_mod_public, -1);
rb_define_private_method(rb_cModule, "protected", rb_mod_protected, -1);
rb_define_private_method(rb_cModule, "private", rb_mod_private, -1);
@ -6381,7 +6409,7 @@ proc_to_s(self, other)
VALUE str;
Data_Get_Struct(self, struct BLOCK, data);
str = rb_str_new(0, strlen(cname)+6+16+1); /* 6:tags 16:addr 1:eos */
str = rb_str_new(0, strlen(cname)+6+16+1); /* 6:tags 16:addr 1:nul */
sprintf(RSTRING(str)->ptr, "#<%s:0x%lx>", cname, data->tag);
RSTRING(str)->len = strlen(RSTRING(str)->ptr);
if (OBJ_TAINTED(self)) OBJ_TAINT(str);

View file

@ -372,9 +372,9 @@ ip_invoke_real(argc, argv, obj)
/* object interface */
ov = (Tcl_Obj **)ALLOCA_N(Tcl_Obj *, argc+1);
for (i = 0; i < argc; ++i) {
VALUE v = argv[i];
v = argv[i];
s = StringValuePtr(v);
ov[i] = Tcl_NewStringObj(s, RSTRING(s)->len);
ov[i] = Tcl_NewStringObj(s, RSTRING(v)->len);
Tcl_IncrRefCount(ov[i]);
}
ov[argc] = (Tcl_Obj *)NULL;

5
file.c
View file

@ -2206,8 +2206,7 @@ rb_find_file(file)
char *file;
{
extern VALUE rb_load_path;
volatile VALUE vpath;
VALUE fname;
VALUE vpath, fname;
char *path;
struct stat st;
@ -2215,7 +2214,7 @@ rb_find_file(file)
if (is_macos_native_path(file)) {
FILE *f;
if (safe_level >= 2 && !rb_path_check(file)) {
if (rb_safe_level() >= 2 && !rb_path_check(file)) {
rb_raise(rb_eSecurityError, "loading from unsafe file %s", file);
}
f= fopen(file, "r");

View file

@ -15,6 +15,7 @@ $srcdir = CONFIG["srcdir"]
$libdir = CONFIG["libdir"]
$rubylibdir = CONFIG["rubylibdir"]
$archdir = CONFIG["archdir"]
$sitedir = CONFIG["sitedir"]
$sitelibdir = CONFIG["sitelibdir"]
$sitearchdir = CONFIG["sitearchdir"]
@ -453,6 +454,7 @@ exec_prefix = #{CONFIG["exec_prefix"].sub(drive, '')}
libdir = #{$libdir.sub(drive, '')}#{target_prefix}
rubylibdir = #{$rubylibdir.sub(drive, '')}#{target_prefix}
archdir = #{$archdir.sub(drive, '')}#{target_prefix}
sitedir = #{$sitedir.sub(drive, '')}#{target_prefix}
sitelibdir = #{$sitelibdir.sub(drive, '')}#{target_prefix}
sitearchdir = #{$sitearchdir.sub(drive, '')}#{target_prefix}

View file

@ -342,6 +342,9 @@ w_object(obj, arg, limit)
switch (BUILTIN_TYPE(obj)) {
case T_CLASS:
if (FL_TEST(obj, FL_SINGLETON)) {
rb_raise(rb_eTypeError, "singleton class can't be dumped");
}
w_byte(TYPE_CLASS, arg);
{
VALUE path = rb_class_path(obj);
@ -460,7 +463,8 @@ w_object(obj, arg, limit)
char *path;
if (FL_TEST(klass, FL_SINGLETON)) {
if (RCLASS(klass)->m_tbl->num_entries > 0) {
if (RCLASS(klass)->m_tbl->num_entries > 0 ||
RCLASS(klass)->iv_tbl->num_entries > 1) {
rb_raise(rb_eTypeError, "singleton can't be dumped");
}
}

View file

@ -130,7 +130,7 @@ rb_any_to_s(obj)
char *cname = rb_class2name(CLASS_OF(obj));
VALUE str;
str = rb_str_new(0, strlen(cname)+6+16+1); /* 6:tags 16:addr 1:eos */
str = rb_str_new(0, strlen(cname)+6+16+1); /* 6:tags 16:addr 1:nul */
sprintf(RSTRING(str)->ptr, "#<%s:0x%lx>", cname, obj);
RSTRING(str)->len = strlen(RSTRING(str)->ptr);
if (OBJ_TAINTED(obj)) OBJ_TAINT(str);
@ -198,12 +198,12 @@ rb_obj_inspect(obj)
c = rb_class2name(CLASS_OF(obj));
if (rb_inspecting_p(obj)) {
str = rb_str_new(0, strlen(c)+10+16+1); /* 10:tags 16:addr 1:eos */
str = rb_str_new(0, strlen(c)+10+16+1); /* 10:tags 16:addr 1:nul */
sprintf(RSTRING(str)->ptr, "#<%s:0x%lx ...>", c, obj);
RSTRING(str)->len = strlen(RSTRING(str)->ptr);
return str;
}
str = rb_str_new(0, strlen(c)+6+16+1); /* 6:tags 16:addr 1:eos */
str = rb_str_new(0, strlen(c)+6+16+1); /* 6:tags 16:addr 1:nul */
sprintf(RSTRING(str)->ptr, "-<%s:0x%lx", c, obj);
RSTRING(str)->len = strlen(RSTRING(str)->ptr);
return rb_protect_inspect(inspect_obj, obj, str);
@ -522,7 +522,17 @@ sym_intern(sym)
static VALUE
rb_mod_to_s(klass)
VALUE klass;
{
if (FL_TEST(klass, FL_SINGLETON)) {
VALUE s = rb_str_new2("#<");
rb_str_cat2(s, "Class:");
rb_str_cat2(s, rb_class2name(klass));
rb_str_cat2(s, ">");
return s;
}
return rb_str_dup(rb_class_path(klass));
}
@ -1111,6 +1121,10 @@ Init_Object()
rb_include_module(rb_cObject, rb_mKernel);
rb_define_private_method(rb_cObject, "initialize", rb_obj_dummy, 0);
rb_define_private_method(rb_cClass, "inherited", rb_obj_dummy, 1);
rb_define_private_method(rb_cModule, "included", rb_obj_dummy, 1);
rb_define_private_method(rb_cModule, "method_added", rb_obj_dummy, 1);
rb_define_private_method(rb_cModule, "method_removed", rb_obj_dummy, 1);
rb_define_private_method(rb_cModule, "method_undefined", rb_obj_dummy, 1);
/*
* Ruby's Class Hierarchy Chart
@ -1138,8 +1152,8 @@ Init_Object()
rb_define_method(rb_mKernel, "nil?", rb_false, 0);
rb_define_method(rb_mKernel, "==", rb_obj_equal, 1);
rb_define_alias(rb_mKernel, "equal?", "==");
rb_define_alias(rb_mKernel, "===", "==");
rb_define_method(rb_mKernel, "equal?", rb_obj_equal, 1);
rb_define_method(rb_mKernel, "===", rb_obj_equal, 1);
rb_define_method(rb_mKernel, "=~", rb_false, 1);
rb_define_method(rb_mKernel, "eql?", rb_obj_equal, 1);
@ -1176,6 +1190,8 @@ Init_Object()
rb_define_method(rb_mKernel, "is_a?", rb_obj_is_kind_of, 1);
rb_define_global_function("singleton_method_added", rb_obj_dummy, 1);
rb_define_global_function("singleton_method_removed", rb_obj_dummy, 1);
rb_define_global_function("singleton_method_undefined", rb_obj_dummy, 1);
rb_define_global_function("sprintf", rb_f_sprintf, -1);
rb_define_global_function("format", rb_f_sprintf, -1);
@ -1242,7 +1258,6 @@ Init_Object()
rb_define_method(rb_cModule, "const_set", rb_mod_const_set, 2);
rb_define_method(rb_cModule, "const_defined?", rb_mod_const_defined, 1);
rb_define_private_method(rb_cModule, "remove_const", rb_mod_remove_const, 1);
rb_define_private_method(rb_cModule, "method_added", rb_obj_dummy, 1);
rb_define_method(rb_cModule, "class_variables", rb_mod_class_variables, 0);
rb_define_private_method(rb_cModule, "remove_class_variable", rb_mod_remove_cvar, 1);

17
ruby.h
View file

@ -186,22 +186,19 @@ void rb_check_type _((VALUE,int));
#define Check_Type(v,t) rb_check_type((VALUE)(v),t)
VALUE rb_str_to_str _((VALUE));
#define StringValue(v) do {\
if (TYPE(v) != T_STRING) v = rb_str_to_str(v);\
} while (0)
VALUE rb_string_value _((VALUE*));
#define StringValue(v) if (TYPE(v) != T_STRING) rb_string_value(&(v))
void rb_check_safe_str _((VALUE));
/* obsolete macro - use SafeStringValue(v) */
#define Check_SafeStr(v) rb_check_safe_str((VALUE)(v))
#define SafeStringValue(v) do {\
if (TYPE(v) != T_STRING) v = rb_str_to_str(v);\
StringValue(v);\
rb_check_safe_str(v);\
} while (0)
#define StringValuePtr(v) \
(((TYPE(v) != T_STRING) ? v = rb_str_to_str(v) : (v)), RSTRING(v)->ptr)
#define StringValuePtr(v) RSTRING((TYPE(v) == T_STRING) ? (v) : rb_string_value(&(v)))->ptr
/* obsolete macro - use SafeStringValue(v) */
#define Check_SafeStr(v) rb_check_safe_str((VALUE)(v))
void rb_secure _((int));
EXTERN int ruby_safe_level;
#define rb_safe_level() (ruby_safe_level)
void rb_set_safe_level _((int));

View file

@ -139,6 +139,13 @@ rb_str_to_str(str)
return rb_convert_type(str, T_STRING, "String", "to_str");
}
VALUE
rb_string_value(ptr)
VALUE *ptr;
{
return *ptr = rb_str_to_str(*ptr);
}
static void
rb_str_become(str, str2)
VALUE str, str2;

View file

@ -257,9 +257,6 @@ char *
rb_class2name(klass)
VALUE klass;
{
if (klass == rb_cNilClass) return "nil";
if (klass == rb_cTrueClass) return "true";
if (klass == rb_cFalseClass) return "false";
return RSTRING(rb_class_path(klass))->ptr;
}

View file

@ -1,4 +1,4 @@
#define RUBY_VERSION "1.7.0"
#define RUBY_RELEASE_DATE "2001-05-07"
#define RUBY_RELEASE_DATE "2001-05-11"
#define RUBY_VERSION_CODE 170
#define RUBY_RELEASE_CODE 20010507
#define RUBY_RELEASE_CODE 20010511