* intern.h, struct.c (rb_struct_s_members, rb_struct_members): public

accessors.  [ruby-dev:24342]

* marshal.c (w_object, r_object0): use accessors.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2004-09-27 04:46:54 +00:00
Родитель ddd5b50d12
Коммит 0bedb2e07f
4 изменённых файлов: 28 добавлений и 25 удалений

Просмотреть файл

@ -1,3 +1,10 @@
Mon Sep 27 13:46:45 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* intern.h, struct.c (rb_struct_s_members, rb_struct_members): public
accessors. [ruby-dev:24342]
* marshal.c (w_object, r_object0): use accessors.
Sun Sep 26 08:05:10 2004 Tadayoshi Funaba <tadf@dotrb.org>
* lib/date.rb: provides {Time,Date,DateTime}#to_{time,date,datetime}.

Просмотреть файл

@ -444,6 +444,8 @@ VALUE rb_struct_aref _((VALUE, VALUE));
VALUE rb_struct_aset _((VALUE, VALUE, VALUE));
VALUE rb_struct_getmember _((VALUE, ID));
VALUE rb_struct_iv_get _((VALUE, char*));
VALUE rb_struct_s_members _((VALUE));
VALUE rb_struct_members _((VALUE));
/* time.c */
VALUE rb_time_new _((time_t, time_t));
/* variable.c */

Просмотреть файл

@ -635,10 +635,7 @@ w_object(obj, arg, limit)
long i;
w_long(len, arg);
mem = rb_struct_iv_get(rb_obj_class(obj), "__member__");
if (mem == Qnil) {
rb_raise(rb_eTypeError, "uninitialized struct");
}
mem = rb_struct_members(obj);
for (i=0; i<len; i++) {
w_symbol(SYM2ID(RARRAY(mem)->ptr[i]), arg);
w_object(RSTRUCT(obj)->ptr[i], arg, limit);
@ -1196,7 +1193,7 @@ r_object0(arg, proc, ivp, extmod)
ID slot;
klass = path2class(r_unique(arg));
mem = rb_struct_iv_get(klass, "__member__");
mem = rb_struct_s_members(klass);
if (mem == Qnil) {
rb_raise(rb_eTypeError, "uninitialized struct");
}

Просмотреть файл

@ -33,8 +33,8 @@ rb_struct_iv_get(c, name)
}
}
static VALUE
struct_s_members(klass)
VALUE
rb_struct_s_members(klass)
VALUE klass;
{
VALUE members = rb_struct_iv_get(klass, "__members__");
@ -45,15 +45,12 @@ struct_s_members(klass)
return members;
}
static VALUE
struct_members(s)
VALUE
rb_struct_members(s)
VALUE s;
{
VALUE members = struct_s_members(rb_obj_class(s));
VALUE members = rb_struct_s_members(rb_obj_class(s));
if (NIL_P(members)) {
rb_bug("non-initialized struct");
}
if (RSTRUCT(s)->len != RARRAY(members)->len) {
rb_raise(rb_eTypeError, "struct size differs (%d required %d given)",
RARRAY(members)->len, RSTRUCT(s)->len);
@ -62,13 +59,13 @@ struct_members(s)
}
static VALUE
rb_struct_s_members(klass)
rb_struct_s_members_m(klass)
VALUE klass;
{
VALUE members, ary;
VALUE *p, *pend;
members = struct_s_members(klass);
members = rb_struct_s_members(klass);
ary = rb_ary_new2(RARRAY(members)->len);
p = RARRAY(members)->ptr; pend = p + RARRAY(members)->len;
while (p < pend) {
@ -92,10 +89,10 @@ rb_struct_s_members(klass)
*/
static VALUE
rb_struct_members(obj)
rb_struct_members_m(obj)
VALUE obj;
{
return rb_struct_s_members(rb_obj_class(obj));
return rb_struct_s_members_m(rb_obj_class(obj));
}
VALUE
@ -106,7 +103,7 @@ rb_struct_getmember(obj, id)
VALUE members, slot;
long i;
members = struct_members(obj);
members = rb_struct_members(obj);
slot = ID2SYM(id);
for (i=0; i<RARRAY(members)->len; i++) {
if (RARRAY(members)->ptr[i] == slot) {
@ -164,7 +161,7 @@ rb_struct_set(obj, val)
VALUE members, slot;
long i;
members = struct_members(obj);
members = rb_struct_members(obj);
rb_struct_modify(obj);
for (i=0; i<RARRAY(members)->len; i++) {
slot = RARRAY(members)->ptr[i];
@ -209,7 +206,7 @@ make_struct(name, members, klass)
rb_define_alloc_func(nstr, struct_alloc);
rb_define_singleton_method(nstr, "new", rb_class_new_instance, -1);
rb_define_singleton_method(nstr, "[]", rb_class_new_instance, -1);
rb_define_singleton_method(nstr, "members", rb_struct_s_members, 0);
rb_define_singleton_method(nstr, "members", rb_struct_s_members_m, 0);
for (i=0; i< RARRAY(members)->len; i++) {
ID id = SYM2ID(RARRAY(members)->ptr[i]);
if (i<10) {
@ -457,7 +454,7 @@ rb_struct_each_pair(s)
VALUE members;
long i;
members = struct_members(s);
members = rb_struct_members(s);
for (i=0; i<RSTRUCT(s)->len; i++) {
rb_yield_values(2, rb_ary_entry(members, i), RSTRUCT(s)->ptr[i]);
}
@ -472,7 +469,7 @@ inspect_struct(s)
VALUE str, members;
long i;
members = struct_members(s);
members = rb_struct_members(s);
str = rb_str_buf_new2("#<struct ");
rb_str_cat2(str, cname);
rb_str_cat2(str, " ");
@ -563,7 +560,7 @@ rb_struct_aref_id(s, id)
VALUE members;
long i, len;
members = struct_members(s);
members = rb_struct_members(s);
len = RARRAY(members)->len;
for (i=0; i<len; i++) {
if (SYM2ID(RARRAY(members)->ptr[i]) == id) {
@ -622,7 +619,7 @@ rb_struct_aset_id(s, id, val)
VALUE members;
long i, len;
members = struct_members(s);
members = rb_struct_members(s);
rb_struct_modify(s);
len = RARRAY(members)->len;
if (RSTRUCT(s)->len != RARRAY(members)->len) {
@ -909,5 +906,5 @@ Init_Struct()
rb_define_method(rb_cStruct, "select", rb_struct_select, -1);
rb_define_method(rb_cStruct, "values_at", rb_struct_values_at, -1);
rb_define_method(rb_cStruct, "members", rb_struct_members, 0);
rb_define_method(rb_cStruct, "members", rb_struct_members_m, 0);
}