* 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> Mon May 7 15:58:45 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (arg): "||=" should not warn for uninitialized instance * 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. * to_i returns nil if str contains no digit.
* raise exception by `` error * raise exception by `` error
* jar like combined library package. * jar like combined library package.
* "@foo ||= 44" should not warn you.
Hacking Interpreter Hacking Interpreter
@ -83,6 +82,7 @@ Standard Libraries
* warn, warning for Ruby level * warn, warning for Ruby level
* hash etc. should handle self referenceing array/hash * hash etc. should handle self referenceing array/hash
* move NameError under StandardError. * move NameError under StandardError.
* library to load per-user profile seeking .ruby_profile or ruby.ini file.
Extension Libraries Extension Libraries

View File

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

View File

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

6
dir.c
View File

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

80
eval.c
View File

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

View File

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

5
file.c
View File

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

View File

@ -15,6 +15,7 @@ $srcdir = CONFIG["srcdir"]
$libdir = CONFIG["libdir"] $libdir = CONFIG["libdir"]
$rubylibdir = CONFIG["rubylibdir"] $rubylibdir = CONFIG["rubylibdir"]
$archdir = CONFIG["archdir"] $archdir = CONFIG["archdir"]
$sitedir = CONFIG["sitedir"]
$sitelibdir = CONFIG["sitelibdir"] $sitelibdir = CONFIG["sitelibdir"]
$sitearchdir = CONFIG["sitearchdir"] $sitearchdir = CONFIG["sitearchdir"]
@ -453,6 +454,7 @@ exec_prefix = #{CONFIG["exec_prefix"].sub(drive, '')}
libdir = #{$libdir.sub(drive, '')}#{target_prefix} libdir = #{$libdir.sub(drive, '')}#{target_prefix}
rubylibdir = #{$rubylibdir.sub(drive, '')}#{target_prefix} rubylibdir = #{$rubylibdir.sub(drive, '')}#{target_prefix}
archdir = #{$archdir.sub(drive, '')}#{target_prefix} archdir = #{$archdir.sub(drive, '')}#{target_prefix}
sitedir = #{$sitedir.sub(drive, '')}#{target_prefix}
sitelibdir = #{$sitelibdir.sub(drive, '')}#{target_prefix} sitelibdir = #{$sitelibdir.sub(drive, '')}#{target_prefix}
sitearchdir = #{$sitearchdir.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)) { switch (BUILTIN_TYPE(obj)) {
case T_CLASS: case T_CLASS:
if (FL_TEST(obj, FL_SINGLETON)) {
rb_raise(rb_eTypeError, "singleton class can't be dumped");
}
w_byte(TYPE_CLASS, arg); w_byte(TYPE_CLASS, arg);
{ {
VALUE path = rb_class_path(obj); VALUE path = rb_class_path(obj);
@ -460,7 +463,8 @@ w_object(obj, arg, limit)
char *path; char *path;
if (FL_TEST(klass, FL_SINGLETON)) { 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"); 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)); char *cname = rb_class2name(CLASS_OF(obj));
VALUE str; 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); sprintf(RSTRING(str)->ptr, "#<%s:0x%lx>", cname, obj);
RSTRING(str)->len = strlen(RSTRING(str)->ptr); RSTRING(str)->len = strlen(RSTRING(str)->ptr);
if (OBJ_TAINTED(obj)) OBJ_TAINT(str); if (OBJ_TAINTED(obj)) OBJ_TAINT(str);
@ -198,12 +198,12 @@ rb_obj_inspect(obj)
c = rb_class2name(CLASS_OF(obj)); c = rb_class2name(CLASS_OF(obj));
if (rb_inspecting_p(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); sprintf(RSTRING(str)->ptr, "#<%s:0x%lx ...>", c, obj);
RSTRING(str)->len = strlen(RSTRING(str)->ptr); RSTRING(str)->len = strlen(RSTRING(str)->ptr);
return str; 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); sprintf(RSTRING(str)->ptr, "-<%s:0x%lx", c, obj);
RSTRING(str)->len = strlen(RSTRING(str)->ptr); RSTRING(str)->len = strlen(RSTRING(str)->ptr);
return rb_protect_inspect(inspect_obj, obj, str); return rb_protect_inspect(inspect_obj, obj, str);
@ -522,7 +522,17 @@ sym_intern(sym)
static VALUE static VALUE
rb_mod_to_s(klass) rb_mod_to_s(klass)
VALUE 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)); return rb_str_dup(rb_class_path(klass));
} }
@ -1111,6 +1121,10 @@ Init_Object()
rb_include_module(rb_cObject, rb_mKernel); rb_include_module(rb_cObject, rb_mKernel);
rb_define_private_method(rb_cObject, "initialize", rb_obj_dummy, 0); 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_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 * 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, "nil?", rb_false, 0);
rb_define_method(rb_mKernel, "==", rb_obj_equal, 1); rb_define_method(rb_mKernel, "==", rb_obj_equal, 1);
rb_define_alias(rb_mKernel, "equal?", "=="); rb_define_method(rb_mKernel, "equal?", rb_obj_equal, 1);
rb_define_alias(rb_mKernel, "===", "=="); rb_define_method(rb_mKernel, "===", rb_obj_equal, 1);
rb_define_method(rb_mKernel, "=~", rb_false, 1); rb_define_method(rb_mKernel, "=~", rb_false, 1);
rb_define_method(rb_mKernel, "eql?", rb_obj_equal, 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_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_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("sprintf", rb_f_sprintf, -1);
rb_define_global_function("format", 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_set", rb_mod_const_set, 2);
rb_define_method(rb_cModule, "const_defined?", rb_mod_const_defined, 1); 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, "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_method(rb_cModule, "class_variables", rb_mod_class_variables, 0);
rb_define_private_method(rb_cModule, "remove_class_variable", rb_mod_remove_cvar, 1); 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) #define Check_Type(v,t) rb_check_type((VALUE)(v),t)
VALUE rb_str_to_str _((VALUE)); VALUE rb_str_to_str _((VALUE));
#define StringValue(v) do {\ VALUE rb_string_value _((VALUE*));
if (TYPE(v) != T_STRING) v = rb_str_to_str(v);\
} while (0) #define StringValue(v) if (TYPE(v) != T_STRING) rb_string_value(&(v))
void rb_check_safe_str _((VALUE)); 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 {\ #define SafeStringValue(v) do {\
if (TYPE(v) != T_STRING) v = rb_str_to_str(v);\ StringValue(v);\
rb_check_safe_str(v);\ rb_check_safe_str(v);\
} while (0) } while (0)
#define StringValuePtr(v) RSTRING((TYPE(v) == T_STRING) ? (v) : rb_string_value(&(v)))->ptr
#define StringValuePtr(v) \ /* obsolete macro - use SafeStringValue(v) */
(((TYPE(v) != T_STRING) ? v = rb_str_to_str(v) : (v)), RSTRING(v)->ptr) #define Check_SafeStr(v) rb_check_safe_str((VALUE)(v))
void rb_secure _((int)); void rb_secure _((int));
EXTERN int ruby_safe_level; EXTERN int ruby_safe_level;
#define rb_safe_level() (ruby_safe_level) #define rb_safe_level() (ruby_safe_level)
void rb_set_safe_level _((int)); 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"); 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 static void
rb_str_become(str, str2) rb_str_become(str, str2)
VALUE str, str2; VALUE str, str2;

View File

@ -257,9 +257,6 @@ char *
rb_class2name(klass) rb_class2name(klass)
VALUE 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; return RSTRING(rb_class_path(klass))->ptr;
} }

View File

@ -1,4 +1,4 @@
#define RUBY_VERSION "1.7.0" #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_VERSION_CODE 170
#define RUBY_RELEASE_CODE 20010507 #define RUBY_RELEASE_CODE 20010511