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

call initialize

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@149 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 1998-04-02 10:03:54 +00:00
parent a1d8147e44
commit b6fe3dae4d
19 changed files with 255 additions and 35 deletions

View file

@ -1,7 +1,22 @@
Thu Apr 2 18:31:46 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
* eval.c (obj_call_init): every object call `initialize'.
Wed Apr 1 01:20:31 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
* object.c (true_and): boolean operators &, | and ^.
Tue Mar 31 13:23:58 1998 Yukihiro Matsumoto <matz@netlab.co.jp> Tue Mar 31 13:23:58 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
* numeric.c (num2int): raise exception for too big Fixnums on * array.c (ary_compact_bang): returns nil, if it does not modify
platforms that sizeof(int) < sizeof(INT). the array like String's bang methods.
* array.c (ary_uniq_bang): new method to remove duplicate items.
* eval.c (bind_s_new): new method.
* numeric.c (num2int): raise exception if Fixnums too big to
convert into `int' in case that sizeof(int) < sizeof(INT).
* string.c (str_center): SEGV on negative width. * string.c (str_center): SEGV on negative width.

55
array.c
View file

@ -155,6 +155,7 @@ ary_s_new(argc, argv, klass)
ary->capa = NIL_P(size)?ARY_DEFAULT_SIZE:NUM2INT(size); ary->capa = NIL_P(size)?ARY_DEFAULT_SIZE:NUM2INT(size);
ary->ptr = ALLOC_N(VALUE, ary->capa); ary->ptr = ALLOC_N(VALUE, ary->capa);
memclear(ary->ptr, ary->capa); memclear(ary->ptr, ary->capa);
obj_call_init((VALUE)ary);
return (VALUE)ary; return (VALUE)ary;
} }
@ -739,7 +740,8 @@ ary_sort_bang(ary)
if (RARRAY(ary)->len == 0) return ary; if (RARRAY(ary)->len == 0) return ary;
ary_modify(ary); ary_modify(ary);
qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE), iterator_p()?sort_1:sort_2); qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE),
iterator_p()?sort_1:sort_2);
return ary; return ary;
} }
@ -1117,6 +1119,46 @@ ary_or(ary1, ary2)
return ary3; return ary3;
} }
static VALUE
ary_uniq_bang(ary)
VALUE ary;
{
VALUE *p, *q, *t, *end;
VALUE v;
int i;
ary_modify(ary);
p = RARRAY(ary)->ptr;
end = p + RARRAY(ary)->len;
while (p < end) {
v = *p++;
q = t = p;
while (q < end) {
if (rb_equal(*q, v)) q++;
else *t++ = *q++;
}
end = t;
}
if (RARRAY(ary)->len = (end - RARRAY(ary)->ptr)) {
return Qnil;
}
RARRAY(ary)->len = (end - RARRAY(ary)->ptr);
return ary;
}
static VALUE
ary_uniq(ary)
VALUE ary;
{
VALUE v = ary_uniq_bang(ary_clone(ary));
if (NIL_P(v)) return ary;
return v;
}
static VALUE static VALUE
ary_compact_bang(ary) ary_compact_bang(ary)
VALUE ary; VALUE ary;
@ -1130,6 +1172,9 @@ ary_compact_bang(ary)
if (NIL_P(*t)) t++; if (NIL_P(*t)) t++;
else *p++ = *t++; else *p++ = *t++;
} }
if (RARRAY(ary)->len == (p - RARRAY(ary)->ptr)) {
return Qnil;
}
RARRAY(ary)->len = RARRAY(ary)->capa = (p - RARRAY(ary)->ptr); RARRAY(ary)->len = RARRAY(ary)->capa = (p - RARRAY(ary)->ptr);
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len); REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
@ -1140,7 +1185,10 @@ static VALUE
ary_compact(ary) ary_compact(ary)
VALUE ary; VALUE ary;
{ {
return ary_compact_bang(ary_clone(ary)); VALUE v = ary_compact_bang(ary_clone(ary));
if (NIL_P(v)) return ary;
return v;
} }
static VALUE static VALUE
@ -1224,7 +1272,8 @@ Init_Array()
rb_define_method(cArray, "&", ary_and, 1); rb_define_method(cArray, "&", ary_and, 1);
rb_define_method(cArray, "|", ary_or, 1); rb_define_method(cArray, "|", ary_or, 1);
rb_define_method(cArray, "compact", ary_compact, 0); rb_define_method(cArray, "uniq!", ary_uniq_bang, 0);
rb_define_method(cArray, "uniq", ary_uniq, 0);
rb_define_method(cArray, "compact!", ary_compact_bang, 0); rb_define_method(cArray, "compact!", ary_compact_bang, 0);
rb_define_method(cArray, "nitems", ary_nitems, 0); rb_define_method(cArray, "nitems", ary_nitems, 0);

12
error.c
View file

@ -268,13 +268,17 @@ exc_s_new(argc, argv, etype)
VALUE *argv; VALUE *argv;
VALUE etype; VALUE etype;
{ {
VALUE arg; VALUE arg, exc;
if (rb_scan_args(argc, argv, "01", &arg) == 0) { if (rb_scan_args(argc, argv, "01", &arg) == 0) {
return exc_new(etype, 0, 0); exc = exc_new(etype, 0, 0);
} }
Check_Type(arg, T_STRING); else {
return exc_new3(etype, arg); Check_Type(arg, T_STRING);
exc = exc_new3(etype, arg);
}
obj_call_init(exc);
return exc;
} }
static VALUE static VALUE

40
eval.c
View file

@ -4344,6 +4344,15 @@ mod_include(argc, argv, module)
return module; return module;
} }
void
obj_call_init(obj)
VALUE obj;
{
PUSH_ITER(iterator_p()?ITER_PRE:ITER_NOT);
rb_funcall2(obj, init, the_frame->argc, the_frame->argv);
POP_ITER();
}
VALUE VALUE
class_new_instance(argc, argv, klass) class_new_instance(argc, argv, klass)
int argc; int argc;
@ -4356,9 +4365,8 @@ class_new_instance(argc, argv, klass)
TypeError("can't create instance of virtual class"); TypeError("can't create instance of virtual class");
} }
obj = obj_alloc(klass); obj = obj_alloc(klass);
PUSH_ITER(iterator_p()?ITER_PRE:ITER_NOT); obj_call_init(obj);
rb_funcall2(obj, init, argc, argv);
POP_ITER();
return obj; return obj;
} }
@ -4667,6 +4675,30 @@ blk_copy_prev(block)
} }
} }
static VALUE
bind_clone(self)
VALUE self;
{
struct BLOCK *orig, *data;
VALUE bind;
Data_Get_Struct(self, struct BLOCK, orig);
bind = Data_Make_Struct(self, struct BLOCK, blk_mark,blk_free,data);
MEMCPY(data, orig, struct BLOCK, 1);
data->frame.argv = ALLOC_N(VALUE, orig->frame.argc);
MEMCPY(data->frame.argv, orig->frame.argv, VALUE, orig->frame.argc);
if (data->iter) {
blk_copy_prev(data);
}
else {
data->prev = 0;
}
return bind;
}
static VALUE static VALUE
f_binding(self) f_binding(self)
VALUE self; VALUE self;
@ -5076,6 +5108,8 @@ Init_Proc()
rb_define_global_function("lambda", f_lambda, 0); rb_define_global_function("lambda", f_lambda, 0);
rb_define_global_function("binding", f_binding, 0); rb_define_global_function("binding", f_binding, 0);
cBinding = rb_define_class("Binding", cObject); cBinding = rb_define_class("Binding", cObject);
rb_undef_method(CLASS_OF(cMethod), "new");
rb_define_method(cBinding, "clone", bind_clone, 0);
cMethod = rb_define_class("Method", cObject); cMethod = rb_define_class("Method", cObject);
rb_undef_method(CLASS_OF(cMethod), "new"); rb_undef_method(CLASS_OF(cMethod), "new");

View file

@ -390,11 +390,15 @@ window_s_new(class, lines, cols, top, left)
VALUE top; VALUE top;
VALUE left; VALUE left;
{ {
VALUE w;
WINDOW *window; WINDOW *window;
window = newwin(NUM2INT(lines), NUM2INT(cols), NUM2INT(top), NUM2INT(left)); window = newwin(NUM2INT(lines), NUM2INT(cols), NUM2INT(top), NUM2INT(left));
wclear(window); wclear(window);
return prep_window(class, window); w = prep_window(class, window);
obj_call_init(w);
return w;
} }
/* def subwin(lines, cols, top, left) */ /* def subwin(lines, cols, top, left) */

View file

@ -83,6 +83,7 @@ fdbm_s_open(argc, argv, class)
obj = Data_Make_Struct(class,struct dbmdata,0,free_dbm,dbmp); obj = Data_Make_Struct(class,struct dbmdata,0,free_dbm,dbmp);
dbmp->di_dbm = dbm; dbmp->di_dbm = dbm;
dbmp->di_size = -1; dbmp->di_size = -1;
obj_call_init(obj);
return obj; return obj;
} }

View file

@ -74,6 +74,7 @@ md5_new(argc, argv, class)
if (!NIL_P(arg)) { if (!NIL_P(arg)) {
md5_update(obj, arg); md5_update(obj, arg);
} }
obj_call_init(obj);
return obj; return obj;
} }

View file

@ -540,8 +540,11 @@ static VALUE
tcp_s_open(class, host, serv) tcp_s_open(class, host, serv)
VALUE class, host, serv; VALUE class, host, serv;
{ {
VALUE s;
Check_SafeStr(host); Check_SafeStr(host);
return open_inet(class, host, serv, INET_CLIENT); s = open_inet(class, host, serv, INET_CLIENT);
obj_call_init(s);
return s;
} }
#ifdef SOCKS #ifdef SOCKS
@ -550,6 +553,7 @@ socks_s_open(class, host, serv)
VALUE class, host, serv; VALUE class, host, serv;
{ {
static init = 0; static init = 0;
VALUE s;
if (init == 0) { if (init == 0) {
SOCKSinit("ruby"); SOCKSinit("ruby");
@ -557,7 +561,9 @@ socks_s_open(class, host, serv)
} }
Check_SafeStr(host); Check_SafeStr(host);
return open_inet(class, host, serv, INET_SOCKS); s = open_inet(class, host, serv, INET_SOCKS);
obj_call_init(s);
return s;
} }
#endif #endif
@ -567,12 +573,14 @@ tcp_svr_s_open(argc, argv, class)
VALUE *argv; VALUE *argv;
VALUE class; VALUE class;
{ {
VALUE arg1, arg2; VALUE arg1, arg2, s;
if (rb_scan_args(argc, argv, "11", &arg1, &arg2) == 2) if (rb_scan_args(argc, argv, "11", &arg1, &arg2) == 2)
return open_inet(class, arg1, arg2, INET_SERVER); s = open_inet(class, arg1, arg2, INET_SERVER);
else else
return open_inet(class, 0, arg1, INET_SERVER); s = open_inet(class, 0, arg1, INET_SERVER);
obj_call_init(s);
return s;
} }
static VALUE static VALUE
@ -801,7 +809,11 @@ static VALUE
udp_s_open(class) udp_s_open(class)
VALUE class; VALUE class;
{ {
return sock_new(class, socket(AF_INET, SOCK_DGRAM, 0)); VALUE s;
s = sock_new(class, socket(AF_INET, SOCK_DGRAM, 0));
obj_call_init(s);
return s;
} }
static void static void
@ -944,7 +956,10 @@ static VALUE
unix_s_sock_open(sock, path) unix_s_sock_open(sock, path)
VALUE sock, path; VALUE sock, path;
{ {
return open_unix(sock, path, 0); VALUE s;
s = open_unix(sock, path, 0);
obj_call_init(s);
return s;
} }
static VALUE static VALUE
@ -965,10 +980,13 @@ unix_path(sock)
} }
static VALUE static VALUE
unix_svr_s_open(class, path) unix_svr_s_open(sock, path)
VALUE class, path; VALUE sock, path;
{ {
return open_unix(class, path, 1); VALUE s;
s = open_unix(sock, path, 1);
obj_call_init(s);
return s;
} }
static VALUE static VALUE
@ -1121,18 +1139,25 @@ sock_s_open(class, domain, type, protocol)
{ {
int fd; int fd;
int d, t; int d, t;
VALUE s;
setup_domain_and_type(domain, &d, type, &t); setup_domain_and_type(domain, &d, type, &t);
fd = socket(d, t, NUM2INT(protocol)); fd = socket(d, t, NUM2INT(protocol));
if (fd < 0) rb_sys_fail("socket(2)"); if (fd < 0) rb_sys_fail("socket(2)");
return sock_new(class, fd); s = sock_new(class, fd);
obj_call_init(s);
return s;
} }
static VALUE static VALUE
sock_s_for_fd(class, fd) sock_s_for_fd(class, fd)
VALUE class, fd; VALUE class, fd;
{ {
return sock_new(class, NUM2INT(fd)); VALUE s = sock_new(class, NUM2INT(fd));
obj_call_init(s);
return s;
} }
static VALUE static VALUE

1
file.c
View file

@ -101,6 +101,7 @@ file_s_open(argc, argv, klass)
if (iterator_p()) { if (iterator_p()) {
rb_ensure(rb_yield, file, io_close, file); rb_ensure(rb_yield, file, io_close, file);
} }
obj_call_init(file);
return file; return file;
} }

13
hash.c
View file

@ -205,6 +205,7 @@ hash_s_new(argc, argv, klass)
hash->status = 0; hash->status = 0;
hash->tbl = 0; /* avoid GC crashing */ hash->tbl = 0; /* avoid GC crashing */
hash->tbl = st_init_table_with_size(&objhash, size); hash->tbl = st_init_table_with_size(&objhash, size);
obj_call_init((VALUE)hash);
return (VALUE)hash; return (VALUE)hash;
} }
@ -213,7 +214,15 @@ static VALUE
hash_new2(klass) hash_new2(klass)
VALUE klass; VALUE klass;
{ {
return hash_s_new(0, 0, klass); NEWOBJ(hash, struct RHash);
OBJSETUP(hash, klass, T_HASH);
hash->iter_lev = 0;
hash->status = 0;
hash->tbl = 0; /* avoid GC crashing */
hash->tbl = st_init_table(&objhash);
return (VALUE)hash;
} }
VALUE VALUE
@ -241,6 +250,7 @@ hash_s_create(argc, argv, klass)
hash->status = 0; hash->status = 0;
hash->tbl = 0; /* avoid GC crashing */ hash->tbl = 0; /* avoid GC crashing */
hash->tbl = (st_table*)st_copy(RHASH(argv[0])->tbl); hash->tbl = (st_table*)st_copy(RHASH(argv[0])->tbl);
obj_call_init((VALUE)hash);
return (VALUE)hash; return (VALUE)hash;
} }
} }
@ -253,6 +263,7 @@ hash_s_create(argc, argv, klass)
for (i=0; i<argc; i+=2) { for (i=0; i<argc; i+=2) {
st_insert(RHASH(hash)->tbl, argv[i], argv[i+1]); st_insert(RHASH(hash)->tbl, argv[i], argv[i+1]);
} }
obj_call_init(hash);
return hash; return hash;
} }

View file

@ -121,6 +121,7 @@ ID rb_frame_last_func _((void));
VALUE f_load _((VALUE, VALUE)); VALUE f_load _((VALUE, VALUE));
void rb_provide _((char *)); void rb_provide _((char *));
VALUE f_require _((VALUE, VALUE)); VALUE f_require _((VALUE, VALUE));
void obj_call_init _((VALUE));
VALUE class_new_instance _((int, VALUE *, VALUE)); VALUE class_new_instance _((int, VALUE *, VALUE));
VALUE f_lambda _((void)); VALUE f_lambda _((void));
void rb_set_end_proc _((void (*)(),VALUE)); void rb_set_end_proc _((void (*)(),VALUE));

8
io.c
View file

@ -1533,8 +1533,8 @@ io_s_new(argc, argv)
VALUE *argv; VALUE *argv;
{ {
VALUE fnum, mode; VALUE fnum, mode;
FILE *f;
char *m = "r"; char *m = "r";
VALUE io;
rb_scan_args(argc, argv, "11", &fnum, &mode); rb_scan_args(argc, argv, "11", &fnum, &mode);
@ -1542,8 +1542,10 @@ io_s_new(argc, argv)
Check_SafeStr(mode); Check_SafeStr(mode);
m = RSTRING(mode)->ptr; m = RSTRING(mode)->ptr;
} }
f = rb_fdopen(NUM2INT(fnum), m); io = prep_stdio(rb_fdopen(NUM2INT(fnum), m), io_mode_flags(m));
return prep_stdio(f, io_mode_flags(m)); obj_call_init(io);
return io;
} }
static VALUE filename, file; static VALUE filename, file;

View file

@ -330,6 +330,27 @@ true_type(obj)
return cTrueClass; return cTrueClass;
} }
static VALUE
true_and(obj, obj2)
VALUE obj, obj2;
{
return RTEST(obj2)?TRUE:FALSE;
}
static VALUE
true_or(obj, obj2)
VALUE obj, obj2;
{
return TRUE;
}
static VALUE
true_xor(obj, obj2)
VALUE obj, obj2;
{
return RTEST(obj2)?FALSE:TRUE;
}
static VALUE static VALUE
false_to_s(obj) false_to_s(obj)
VALUE obj; VALUE obj;
@ -351,6 +372,27 @@ false_type(obj)
return cFalseClass; return cFalseClass;
} }
static VALUE
false_and(obj, obj2)
VALUE obj, obj2;
{
return FALSE;
}
static VALUE
false_or(obj, obj2)
VALUE obj, obj2;
{
return RTEST(obj2)?TRUE:FALSE;
}
static VALUE
false_xor(obj, obj2)
VALUE obj, obj2;
{
return RTEST(obj2)?TRUE:FALSE;
}
static VALUE static VALUE
rb_true(obj) rb_true(obj)
VALUE obj; VALUE obj;
@ -480,7 +522,14 @@ mod_cmp(mod, arg)
return INT2FIX(1); return INT2FIX(1);
} }
VALUE module_new(); VALUE module_s_new()
{
VALUE mod = module_new();
obj_call_init(mod);
return mod;
}
VALUE class_new_instance(); VALUE class_new_instance();
static VALUE static VALUE
@ -500,6 +549,7 @@ class_s_new(argc, argv)
/* make metaclass */ /* make metaclass */
RBASIC(klass)->klass = singleton_class_new(RBASIC(super)->klass); RBASIC(klass)->klass = singleton_class_new(RBASIC(super)->klass);
singleton_class_attached(RBASIC(klass)->klass, klass); singleton_class_attached(RBASIC(klass)->klass, klass);
obj_call_init(klass);
return klass; return klass;
} }
@ -917,7 +967,7 @@ Init_Object()
rb_define_private_method(cModule, "attr_writer", mod_attr_writer, -1); rb_define_private_method(cModule, "attr_writer", mod_attr_writer, -1);
rb_define_private_method(cModule, "attr_accessor", mod_attr_accessor, -1); rb_define_private_method(cModule, "attr_accessor", mod_attr_accessor, -1);
rb_define_singleton_method(cModule, "new", module_new, 0); rb_define_singleton_method(cModule, "new", module_s_new, 0);
rb_define_method(cModule, "instance_methods", class_instance_methods, -1); rb_define_method(cModule, "instance_methods", class_instance_methods, -1);
rb_define_method(cModule, "private_instance_methods", class_private_instance_methods, -1); rb_define_method(cModule, "private_instance_methods", class_private_instance_methods, -1);
@ -933,8 +983,6 @@ Init_Object()
rb_undef_method(cClass, "extend_object"); rb_undef_method(cClass, "extend_object");
rb_undef_method(cClass, "append_features"); rb_undef_method(cClass, "append_features");
rb_define_singleton_method(cClass, "new", class_s_new, -1);
cData = rb_define_class("Data", cObject); cData = rb_define_class("Data", cObject);
rb_undef_method(CLASS_OF(cData), "new"); rb_undef_method(CLASS_OF(cData), "new");
@ -946,6 +994,9 @@ Init_Object()
rb_define_method(cTrueClass, "to_s", true_to_s, 0); rb_define_method(cTrueClass, "to_s", true_to_s, 0);
rb_define_method(cTrueClass, "to_i", true_to_i, 0); rb_define_method(cTrueClass, "to_i", true_to_i, 0);
rb_define_method(cTrueClass, "type", true_type, 0); rb_define_method(cTrueClass, "type", true_type, 0);
rb_define_method(cTrueClass, "&", true_and, 1);
rb_define_method(cTrueClass, "|", true_or, 1);
rb_define_method(cTrueClass, "^", true_xor, 1);
rb_undef_method(CLASS_OF(cTrueClass), "new"); rb_undef_method(CLASS_OF(cTrueClass), "new");
rb_define_global_const("TRUE", TRUE); rb_define_global_const("TRUE", TRUE);
@ -953,6 +1004,9 @@ Init_Object()
rb_define_method(cFalseClass, "to_s", false_to_s, 0); rb_define_method(cFalseClass, "to_s", false_to_s, 0);
rb_define_method(cFalseClass, "to_i", false_to_i, 0); rb_define_method(cFalseClass, "to_i", false_to_i, 0);
rb_define_method(cFalseClass, "type", false_type, 0); rb_define_method(cFalseClass, "type", false_type, 0);
rb_define_method(cFalseClass, "&", false_and, 1);
rb_define_method(cFalseClass, "|", false_or, 1);
rb_define_method(cFalseClass, "^", false_xor, 1);
rb_undef_method(CLASS_OF(cFalseClass), "new"); rb_undef_method(CLASS_OF(cFalseClass), "new");
rb_define_global_const("FALSE", FALSE); rb_define_global_const("FALSE", FALSE);

View file

@ -45,6 +45,7 @@ range_s_new(klass, first, last)
rb_iv_set(obj, "first", first); rb_iv_set(obj, "first", first);
rb_iv_set(obj, "last", last); rb_iv_set(obj, "last", last);
obj_call_init(obj);
return obj; return obj;
} }

3
re.c
View file

@ -659,6 +659,7 @@ reg_new_1(klass, s, len, flag)
memcpy(re->str, s, len); memcpy(re->str, s, len);
re->str[len] = '\0'; re->str[len] = '\0';
re->len = len; re->len = len;
obj_call_init((VALUE)re);
return (VALUE)re; return (VALUE)re;
} }
@ -795,7 +796,7 @@ reg_s_new(argc, argv, self)
Check_Type(src, T_STRING); Check_Type(src, T_STRING);
} }
return Qnil; return Qnil; /* not reached */
} }
static VALUE static VALUE

View file

@ -277,11 +277,20 @@ ok($x[0] == -1 && $x[1] == 10)
$x[-1, 1] = 20 $x[-1, 1] = 20
ok($x[-1] == 20 && $x.pop == 20) ok($x[-1] == 20 && $x.pop == 20)
# array and/or
ok(([1,2,3]&[2,4,6]) == [2])
ok(([1,2,3]|[2,4,6]) == [1,2,3,4,6])
# compact # compact
$x = [nil, 1, nil, nil, 5, nil, nil] $x = [nil, 1, nil, nil, 5, nil, nil]
$x.compact! $x.compact!
ok($x == [1, 5]) ok($x == [1, 5])
# uniq
$x = [1, 1, 4, 2, 5, 4, 5, 1, 2]
$x.uniq!
ok($x == [1, 4, 2, 5])
# empty? # empty?
ok(!$x.empty?) ok(!$x.empty?)
$x = [] $x = []

View file

@ -177,6 +177,7 @@ str_s_new(klass, orig)
if (rb_safe_level() >= 3) { if (rb_safe_level() >= 3) {
FL_SET(str, STR_TAINT); FL_SET(str, STR_TAINT);
} }
obj_call_init((VALUE)str);
return (VALUE)str; return (VALUE)str;
} }

View file

@ -185,6 +185,7 @@ struct_s_def(argc, argv)
struct RString *name; struct RString *name;
struct RArray *rest; struct RArray *rest;
int i; int i;
VALUE st;
rb_scan_args(argc, argv, "1*", &name, &rest); rb_scan_args(argc, argv, "1*", &name, &rest);
Check_Type(name, T_STRING); Check_Type(name, T_STRING);
@ -192,7 +193,10 @@ struct_s_def(argc, argv)
ID id = rb_to_id(rest->ptr[i]); ID id = rb_to_id(rest->ptr[i]);
rest->ptr[i] = INT2FIX(id); rest->ptr[i] = INT2FIX(id);
} }
return make_struct(name, rest); st = make_struct(name, rest);
obj_call_init((VALUE)st);
return st;
} }
VALUE VALUE
@ -215,6 +219,7 @@ struct_alloc(klass, values)
st->len = n; st->len = n;
MEMCPY(st->ptr, RARRAY(values)->ptr, VALUE, RARRAY(values)->len); MEMCPY(st->ptr, RARRAY(values)->ptr, VALUE, RARRAY(values)->len);
memclear(st->ptr+RARRAY(values)->len, n - RARRAY(values)->len); memclear(st->ptr+RARRAY(values)->len, n - RARRAY(values)->len);
obj_call_init((VALUE)st);
return (VALUE)st; return (VALUE)st;
} }

1
time.c
View file

@ -62,6 +62,7 @@ time_s_now(klass)
if (gettimeofday(&(tobj->tv), 0) == -1) { if (gettimeofday(&(tobj->tv), 0) == -1) {
rb_sys_fail("gettimeofday"); rb_sys_fail("gettimeofday");
} }
obj_call_init(obj);
return obj; return obj;
} }