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

* include/ruby/ruby.h (rb_data_type_t): restructured. [ruby-dev:41862]

add parent member.

* error.c (rb_typeddata_inherited_p): new function.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28676 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2010-07-18 07:31:54 +00:00
parent ad654fe58e
commit 25b9eb5e57
25 changed files with 119 additions and 70 deletions

View file

@ -1,3 +1,10 @@
Sun Jul 18 16:31:50 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* include/ruby/ruby.h (rb_data_type_t): restructured. [ruby-dev:41862]
add parent member.
* error.c (rb_typeddata_inherited_p): new function.
Sun Jul 18 01:09:27 2010 Tanaka Akira <akr@fsij.org>
* ext/pathname/pathname.c (path_initialize): return a value.

4
cont.c
View file

@ -374,7 +374,7 @@ cont_save_machine_stack(rb_thread_t *th, rb_context_t *cont)
static const rb_data_type_t cont_data_type = {
"continuation",
cont_mark, cont_free, cont_memsize,
{cont_mark, cont_free, cont_memsize,},
};
static void
@ -951,7 +951,7 @@ rb_cont_call(int argc, VALUE *argv, VALUE contval)
static const rb_data_type_t fiber_data_type = {
"fiber",
fiber_mark, fiber_free, fiber_memsize,
{fiber_mark, fiber_free, fiber_memsize,},
};
static VALUE

2
dir.c
View file

@ -344,7 +344,7 @@ dir_memsize(const void *ptr)
static const rb_data_type_t dir_data_type = {
"dir",
dir_mark, dir_free, dir_memsize
{dir_mark, dir_free, dir_memsize,},
};
static VALUE dir_close(VALUE);

View file

@ -59,7 +59,8 @@ enc_memsize(const void *p)
}
static const rb_data_type_t encoding_data_type = {
"encoding", 0, 0, enc_memsize,
"encoding",
{0, 0, enc_memsize,},
};
#define is_data_encoding(obj) (RTYPEDDATA_P(obj) && RTYPEDDATA_TYPE(obj) == &encoding_data_type)

View file

@ -131,9 +131,11 @@ enumerator_memsize(const void *p)
static const rb_data_type_t enumerator_data_type = {
"enumerator",
{
enumerator_mark,
enumerator_free,
enumerator_memsize,
},
};
static struct enumerator *
@ -812,9 +814,11 @@ yielder_memsize(const void *p)
static const rb_data_type_t yielder_data_type = {
"yielder",
{
yielder_mark,
yielder_free,
yielder_memsize,
},
};
static struct yielder *
@ -915,9 +919,11 @@ generator_memsize(const void *p)
static const rb_data_type_t generator_data_type = {
"generator",
{
generator_mark,
generator_free,
generator_memsize,
},
};
static struct generator *

16
error.c
View file

@ -350,11 +350,21 @@ rb_check_type(VALUE x, int t)
}
}
int
rb_typeddata_inherited_p(const rb_data_type_t *child, const rb_data_type_t *parent)
{
while (child) {
if (child == parent) return 1;
child = child->parent;
}
return 0;
}
int
rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type)
{
if (SPECIAL_CONST_P(obj) || BUILTIN_TYPE(obj) != T_DATA ||
!RTYPEDDATA_P(obj) || RTYPEDDATA_TYPE(obj) != data_type) {
!RTYPEDDATA_P(obj) || !rb_typeddata_inherited_p(RTYPEDDATA_TYPE(obj), data_type)) {
return 0;
}
return 1;
@ -373,7 +383,7 @@ rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
etype = rb_obj_classname(obj);
rb_raise(rb_eTypeError, mesg, etype, data_type->wrap_struct_name);
}
else if (RTYPEDDATA_TYPE(obj) != data_type) {
else if (!rb_typeddata_inherited_p(RTYPEDDATA_TYPE(obj), data_type)) {
etype = RTYPEDDATA_TYPE(obj)->wrap_struct_name;
rb_raise(rb_eTypeError, mesg, etype, data_type->wrap_struct_name);
}
@ -815,9 +825,11 @@ name_err_mesg_memsize(const void *p)
static const rb_data_type_t name_err_mesg_data_type = {
"name_err_mesg",
{
name_err_mesg_mark,
name_err_mesg_free,
name_err_mesg_memsize,
},
};
/* :nodoc: */

View file

@ -105,7 +105,7 @@ BigDecimal_memsize(const void *ptr)
static const rb_data_type_t BigDecimal_data_type = {
"BigDecimal",
0, BigDecimal_delete, BigDecimal_memsize,
{0, BigDecimal_delete, BigDecimal_memsize,},
};
static VALUE

View file

@ -70,7 +70,7 @@ dlcfunc_memsize(const void *ptr)
const rb_data_type_t dlcfunc_data_type = {
"dl/cfunc",
0, dlcfunc_free, dlcfunc_memsize,
{0, dlcfunc_free, dlcfunc_memsize,},
};
VALUE

View file

@ -43,7 +43,7 @@ dlptr_memsize(const void *ptr)
static const rb_data_type_t dlptr_data_type = {
"dl/ptr",
0, dlptr_free, dlptr_memsize,
{0, dlptr_free, dlptr_memsize,},
};
void

View file

@ -48,7 +48,7 @@ dlhandle_memsize(const void *ptr)
static const rb_data_type_t dlhandle_data_type = {
"dl/handle",
0, dlhandle_free, dlhandle_memsize,
{0, dlhandle_free, dlhandle_memsize,},
};
/*

View file

@ -534,7 +534,7 @@ addrinfo_memsize(const void *ptr)
static const rb_data_type_t addrinfo_type = {
"socket/addrinfo",
addrinfo_mark, addrinfo_free, addrinfo_memsize,
{addrinfo_mark, addrinfo_free, addrinfo_memsize,},
};
static VALUE

View file

@ -73,9 +73,11 @@ strio_memsize(const void *p)
static const rb_data_type_t strio_data_type = {
"strio",
{
strio_mark,
strio_free,
strio_memsize,
},
};
#define check_strio(self) ((struct StringIO*)rb_check_typeddata(self, &strio_data_type))

2
file.c
View file

@ -247,7 +247,7 @@ stat_memsize(const void *p)
static const rb_data_type_t stat_data_type = {
"stat",
NULL, RUBY_TYPED_DEFAULT_FREE, stat_memsize,
{NULL, RUBY_TYPED_DEFAULT_FREE, stat_memsize,},
};
static VALUE

11
gc.c
View file

@ -1177,7 +1177,7 @@ size_t
rb_objspace_data_type_memsize(VALUE obj)
{
if (RTYPEDDATA_P(obj)) {
return RTYPEDDATA_TYPE(obj)->dsize(RTYPEDDATA_DATA(obj));
return RTYPEDDATA_TYPE(obj)->function.dsize(RTYPEDDATA_DATA(obj));
}
else {
return 0;
@ -1749,7 +1749,8 @@ gc_mark_children(rb_objspace_t *objspace, VALUE ptr, int lev)
case T_DATA:
if (RTYPEDDATA_P(obj)) {
if (obj->as.typeddata.type->dmark) (*obj->as.typeddata.type->dmark)(DATA_PTR(obj));
RUBY_DATA_FUNC mark_func = obj->as.typeddata.type->function.dmark;
if (mark_func) (*mark_func)(DATA_PTR(obj));
}
else {
if (obj->as.data.dmark) (*obj->as.data.dmark)(DATA_PTR(obj));
@ -2186,7 +2187,7 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
case T_DATA:
if (DATA_PTR(obj)) {
if (RTYPEDDATA_P(obj)) {
RDATA(obj)->dfree = RANY(obj)->as.typeddata.type->dfree;
RDATA(obj)->dfree = RANY(obj)->as.typeddata.type->function.dfree;
}
if ((long)RANY(obj)->as.data.dfree == -1) {
xfree(DATA_PTR(obj));
@ -2780,7 +2781,7 @@ run_final(rb_objspace_t *objspace, VALUE obj)
RBASIC(obj)->klass = 0;
if (RTYPEDDATA_P(obj)) {
free_func = RTYPEDDATA_TYPE(obj)->dfree;
free_func = RTYPEDDATA_TYPE(obj)->function.dfree;
}
else {
free_func = RDATA(obj)->dfree;
@ -2902,7 +2903,7 @@ rb_objspace_call_finalizer(rb_objspace_t *objspace)
RANY(p)->as.basic.klass != rb_cThread && RANY(p)->as.basic.klass != rb_cMutex) {
p->as.free.flags = 0;
if (RTYPEDDATA_P(p)) {
RDATA(p)->dfree = RANY(p)->as.typeddata.type->dfree;
RDATA(p)->dfree = RANY(p)->as.typeddata.type->function.dfree;
}
if ((long)RANY(p)->as.data.dfree == -1) {
xfree(DATA_PTR(p));

View file

@ -742,16 +742,21 @@ struct RData {
void *data;
};
typedef struct rb_data_type_struct {
typedef struct rb_data_type_struct rb_data_type_t;
struct rb_data_type_struct {
const char *wrap_struct_name;
struct {
void (*dmark)(void*);
void (*dfree)(void*);
size_t (*dsize)(const void *);
void *reserved[3]; /* For future extension.
void *reserved[2]; /* For future extension.
This array *must* be filled with ZERO. */
} function;
const rb_data_type_t *parent;
void *data; /* This area can be used for any purpose
by a programmer who define the type. */
} rb_data_type_t;
};
struct RTypedData {
struct RBasic basic;
@ -773,6 +778,7 @@ typedef void (*RUBY_DATA_FUNC)(void*);
VALUE rb_data_object_alloc(VALUE,void*,RUBY_DATA_FUNC,RUBY_DATA_FUNC);
VALUE rb_data_typed_object_alloc(VALUE klass, void *datap, const rb_data_type_t *);
int rb_typeddata_inherited_p(const rb_data_type_t *child, const rb_data_type_t *parent);
int rb_typeddata_is_kind_of(VALUE, const rb_data_type_t *);
void *rb_check_typeddata(VALUE, const rb_data_type_t *);
#define Check_TypedStruct(v,t) rb_check_typeddata((VALUE)(v),t)

2
iseq.c
View file

@ -156,9 +156,11 @@ iseq_memsize(const void *ptr)
static const rb_data_type_t iseq_data_type = {
"iseq",
{
iseq_mark,
iseq_free,
iseq_memsize,
},
};
static VALUE

View file

@ -186,7 +186,7 @@ memsize_dump_arg(const void *ptr)
static const rb_data_type_t dump_arg_data = {
"dump_arg",
mark_dump_arg, free_dump_arg, memsize_dump_arg
{mark_dump_arg, free_dump_arg, memsize_dump_arg,},
};
static const char *
@ -999,7 +999,7 @@ memsize_load_arg(const void *ptr)
static const rb_data_type_t load_arg_data = {
"load_arg",
mark_load_arg, free_load_arg, memsize_load_arg
{mark_load_arg, free_load_arg, memsize_load_arg,},
};
#define r_entry(v, arg) r_entry0(v, (arg)->data->num_entries, arg)

View file

@ -10027,9 +10027,11 @@ parser_memsize(const void *ptr)
static const rb_data_type_t parser_data_type = {
"parser",
{
parser_mark,
parser_free,
parser_memsize,
},
};
VALUE rb_parser_get_yydebug(VALUE);

6
proc.c
View file

@ -71,9 +71,11 @@ proc_memsize(const void *ptr)
static const rb_data_type_t proc_data_type = {
"proc",
{
proc_mark,
proc_free,
proc_memsize,
},
};
VALUE
@ -268,9 +270,11 @@ binding_memsize(const void *ptr)
static const rb_data_type_t binding_data_type = {
"binding",
{
binding_mark,
binding_free,
binding_memsize,
},
};
static VALUE
@ -882,9 +886,11 @@ bm_memsize(const void *ptr)
static const rb_data_type_t method_data_type = {
"method",
{
bm_mark,
bm_free,
bm_memsize,
},
};
static inline int

View file

@ -339,9 +339,11 @@ random_memsize(const void *ptr)
static const rb_data_type_t random_data_type = {
"random",
{
random_mark,
random_free,
random_memsize,
},
};
static rb_random_t *

View file

@ -2824,7 +2824,7 @@ thgroup_memsize(const void *ptr)
static const rb_data_type_t thgroup_data_type = {
"thgroup",
NULL, RUBY_TYPED_DEFAULT_FREE, thgroup_memsize,
{NULL, RUBY_TYPED_DEFAULT_FREE, thgroup_memsize,},
};
/*
@ -3062,7 +3062,7 @@ mutex_memsize(const void *ptr)
static const rb_data_type_t mutex_data_type = {
"mutex",
mutex_mark, mutex_free, mutex_memsize,
{mutex_mark, mutex_free, mutex_memsize,},
};
static VALUE
@ -3433,7 +3433,7 @@ barrier_mark(void *ptr)
static const rb_data_type_t barrier_data_type = {
"barrier",
barrier_mark, 0, 0,
{barrier_mark, 0, 0,},
};
static VALUE

2
time.c
View file

@ -1851,7 +1851,7 @@ time_memsize(const void *tobj)
static const rb_data_type_t time_data_type = {
"time",
time_mark, time_free, time_memsize,
{time_mark, time_free, time_memsize,},
};
static VALUE

View file

@ -2829,7 +2829,7 @@ econv_memsize(const void *ptr)
static const rb_data_type_t econv_data_type = {
"econv",
NULL, econv_free, econv_memsize,
{NULL, econv_free, econv_memsize,},
};
static VALUE

View file

@ -1418,7 +1418,7 @@ autoload_memsize(const void *ptr)
static const rb_data_type_t autoload_data_type = {
"autoload",
autoload_mark, autoload_free, autoload_memsize,
{autoload_mark, autoload_free, autoload_memsize,},
};
#define check_autoload_table(av) \

6
vm.c
View file

@ -244,7 +244,7 @@ env_memsize(const void *ptr)
static const rb_data_type_t env_data_type = {
"VM/env",
env_mark, env_free, env_memsize,
{env_mark, env_free, env_memsize,},
};
static VALUE
@ -1569,7 +1569,7 @@ vm_memsize(const void *ptr)
static const rb_data_type_t vm_data_type = {
"VM",
rb_vm_mark, vm_free, vm_memsize,
{rb_vm_mark, vm_free, vm_memsize,},
};
static void
@ -1759,9 +1759,11 @@ thread_memsize(const void *ptr)
static const rb_data_type_t thread_data_type = {
"VM/thread",
{
rb_thread_mark,
thread_free,
thread_memsize,
},
};
static VALUE