なかだです。

現在rb_data_type_tにはreservedがありますが、配列になっていること
とその後にdataがあることのために実際に拡張するのは難しくなってい
ます。

typedef struct rb_data_type_struct {
    const char *wrap_struct_name;
    void (*dmark)(void*);
    void (*dfree)(void*);
    size_t (*dsize)(const void *);
    void *reserved[3];
    void *data;
} rb_data_type_t;

static const rb_data_type_t foo_data = {
    "foo", foo_mark, foo_free, foo_size, {}, my_data
};

これを以下のように拡張しようとすると

typedef struct rb_data_type_struct {
    const char *wrap_struct_name;
    void (*dmark)(void*);
    void (*dfree)(void*);
    size_t (*dsize)(const void *);
    void (*extension)(void *);
    void *reserved[2];
    void *data;
} rb_data_type_t;

このように一つずれてしまい、dataを設定している場合は書き換えが必
要になります。

static const rb_data_type_t foo_data = {
    "foo", foo_mark, foo_free, foo_size, foo_ext, {}, my_data
};

以下のようにすればズレは起きませんが、

typedef struct rb_data_type_struct {
    const char *wrap_struct_name;
    void (*dmark)(void*);
    void (*dfree)(void*);
    size_t (*dsize)(const void *);
    struct {
	void (*extension)(void *);
	void *reserved[2];
    } ext;
    void *data;
} rb_data_type_t;

static const rb_data_type_t foo_data = {
    "foo", foo_mark, foo_free, foo_size, {foo_ext,}, my_data
};

などと拡張された部分だけを{}に入れなければなりません。

そこで、dmarkからdsizeまでもreservedと一緒にstructに入れてしまい
たいと思います。{}が必要になりますが、上記のような不揃いさは回避
できますし、バイナリ互換性も保たれます。

幸いrb_data_type_tは1.9.1にはありません。変えるなら今が最後のチャ
ンスです。いかがでしょうか。


diff --git a/cont.c b/cont.c index dec3b01..6065d34 100644 --- a/cont.c +++ b/cont.c @@ -375,5 +375,5 @@ 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,}, }; @@ -952,5 +952,5 @@ 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,}, }; diff --git a/dir.c b/dir.c index cab0cdc..8ebd1de 100644 --- a/dir.c +++ b/dir.c @@ -345,5 +345,5 @@ 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,}, }; diff --git a/encoding.c b/encoding.c index 328e109..2fa8b71 100644 --- a/encoding.c +++ b/encoding.c @@ -60,5 +60,6 @@ enc_memsize(const void *p) static const rb_data_type_t encoding_data_type = { - "encoding", 0, 0, enc_memsize, + "encoding", + {0, 0, enc_memsize,}, }; diff --git a/enumerator.c b/enumerator.c index bdf3bb8..47a5c7e 100644 --- a/enumerator.c +++ b/enumerator.c @@ -132,7 +132,9 @@ enumerator_memsize(const void *p) static const rb_data_type_t enumerator_data_type = { "enumerator", - enumerator_mark, - enumerator_free, - enumerator_memsize, + { + enumerator_mark, + enumerator_free, + enumerator_memsize, + }, }; @@ -813,7 +815,9 @@ yielder_memsize(const void *p) static const rb_data_type_t yielder_data_type = { "yielder", - yielder_mark, - yielder_free, - yielder_memsize, + { + yielder_mark, + yielder_free, + yielder_memsize, + }, }; @@ -916,7 +920,9 @@ generator_memsize(const void *p) static const rb_data_type_t generator_data_type = { "generator", - generator_mark, - generator_free, - generator_memsize, + { + generator_mark, + generator_free, + generator_memsize, + }, }; diff --git a/error.c b/error.c index 0e1eab0..0d8e2bd 100644 --- a/error.c +++ b/error.c @@ -816,7 +816,9 @@ 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, + { + name_err_mesg_mark, + name_err_mesg_free, + name_err_mesg_memsize, + }, }; diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 340ea8b..146145c 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -106,5 +106,5 @@ 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,}, }; diff --git a/ext/dl/cfunc.c b/ext/dl/cfunc.c index 536a723..7eb5860 100644 --- a/ext/dl/cfunc.c +++ b/ext/dl/cfunc.c @@ -71,5 +71,5 @@ 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,}, }; diff --git a/ext/dl/cptr.c b/ext/dl/cptr.c index bafbc48..68c18ec 100644 --- a/ext/dl/cptr.c +++ b/ext/dl/cptr.c @@ -44,5 +44,5 @@ 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,}, }; diff --git a/ext/dl/handle.c b/ext/dl/handle.c index a450e6b..ed042e1 100644 --- a/ext/dl/handle.c +++ b/ext/dl/handle.c @@ -49,5 +49,5 @@ 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,}, }; diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c index 4bc20c9..2e5f95a 100644 --- a/ext/socket/raddrinfo.c +++ b/ext/socket/raddrinfo.c @@ -535,5 +535,5 @@ 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,}, }; diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index c93ba10..4628a35 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -74,7 +74,9 @@ strio_memsize(const void *p) static const rb_data_type_t strio_data_type = { "strio", - strio_mark, - strio_free, - strio_memsize, + { + strio_mark, + strio_free, + strio_memsize, + }, }; diff --git a/file.c b/file.c index 94c2468..37c9c47 100644 --- a/file.c +++ b/file.c @@ -248,5 +248,5 @@ 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,}, }; diff --git a/gc.c b/gc.c index 20c34a7..f7fb399 100644 --- a/gc.c +++ b/gc.c @@ -1178,5 +1178,5 @@ rb_objspace_data_type_memsize(VALUE obj) { if (RTYPEDDATA_P(obj)) { - return RTYPEDDATA_TYPE(obj)->dsize(RTYPEDDATA_DATA(obj)); + return RTYPEDDATA_TYPE(obj)->ext.dsize(RTYPEDDATA_DATA(obj)); } else { @@ -1750,5 +1750,5 @@ 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)); + if (obj->as.typeddata.type->ext.dmark) (*obj->as.typeddata.type->ext.dmark)(DATA_PTR(obj)); } else { @@ -2187,5 +2187,5 @@ obj_free(rb_objspace_t *objspace, VALUE obj) 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->ext.dfree; } if ((long)RANY(obj)->as.data.dfree == -1) { @@ -2781,5 +2781,5 @@ run_final(rb_objspace_t *objspace, VALUE obj) if (RTYPEDDATA_P(obj)) { - free_func = RTYPEDDATA_TYPE(obj)->dfree; + free_func = RTYPEDDATA_TYPE(obj)->ext.dfree; } else { @@ -2903,5 +2903,5 @@ rb_objspace_call_finalizer(rb_objspace_t *objspace) 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->ext.dfree; } if ((long)RANY(p)->as.data.dfree == -1) { diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 03984b4..2dba533 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -745,9 +745,11 @@ struct RData { typedef struct rb_data_type_struct { const char *wrap_struct_name; - void (*dmark)(void*); - void (*dfree)(void*); - size_t (*dsize)(const void *); - void *reserved[3]; /* For future extension. - This array *must* be filled with ZERO. */ + struct { + void (*dmark)(void*); + void (*dfree)(void*); + size_t (*dsize)(const void *); + void *reserved[3]; /* For future extension. + This array *must* be filled with ZERO. */ + } ext; void *data; /* This area can be used for any purpose by a programmer who define the type. */ diff --git a/iseq.c b/iseq.c index ae45884..fc9b101 100644 --- a/iseq.c +++ b/iseq.c @@ -157,7 +157,9 @@ iseq_memsize(const void *ptr) static const rb_data_type_t iseq_data_type = { "iseq", - iseq_mark, - iseq_free, - iseq_memsize, + { + iseq_mark, + iseq_free, + iseq_memsize, + }, }; diff --git a/marshal.c b/marshal.c index bf76e6d..bcbc2de 100644 --- a/marshal.c +++ b/marshal.c @@ -187,5 +187,5 @@ 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,}, }; @@ -1000,5 +1000,5 @@ 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,}, }; diff --git a/parse.y b/parse.y index b9f59d4..6b4bf95 100644 --- a/parse.y +++ b/parse.y @@ -10028,7 +10028,9 @@ parser_memsize(const void *ptr) static const rb_data_type_t parser_data_type = { "parser", - parser_mark, - parser_free, - parser_memsize, + { + parser_mark, + parser_free, + parser_memsize, + }, }; diff --git a/proc.c b/proc.c index 7df2ec8..0489dd9 100644 --- a/proc.c +++ b/proc.c @@ -72,7 +72,9 @@ proc_memsize(const void *ptr) static const rb_data_type_t proc_data_type = { "proc", - proc_mark, - proc_free, - proc_memsize, + { + proc_mark, + proc_free, + proc_memsize, + }, }; @@ -269,7 +271,9 @@ binding_memsize(const void *ptr) static const rb_data_type_t binding_data_type = { "binding", - binding_mark, - binding_free, - binding_memsize, + { + binding_mark, + binding_free, + binding_memsize, + }, }; @@ -883,7 +887,9 @@ bm_memsize(const void *ptr) static const rb_data_type_t method_data_type = { "method", - bm_mark, - bm_free, - bm_memsize, + { + bm_mark, + bm_free, + bm_memsize, + }, }; diff --git a/random.c b/random.c index 333c593..72ef7c5 100644 --- a/random.c +++ b/random.c @@ -340,7 +340,9 @@ random_memsize(const void *ptr) static const rb_data_type_t random_data_type = { "random", - random_mark, - random_free, - random_memsize, + { + random_mark, + random_free, + random_memsize, + }, }; diff --git a/thread.c b/thread.c index de60b4d..49d4d28 100644 --- a/thread.c +++ b/thread.c @@ -2825,5 +2825,5 @@ 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,}, }; @@ -3063,5 +3063,5 @@ 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,}, }; @@ -3434,5 +3434,5 @@ barrier_mark(void *ptr) static const rb_data_type_t barrier_data_type = { "barrier", - barrier_mark, 0, 0, + {barrier_mark, 0, 0,}, }; diff --git a/time.c b/time.c index 1abbd96..15398e9 100644 --- a/time.c +++ b/time.c @@ -1852,5 +1852,5 @@ 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,}, }; diff --git a/transcode.c b/transcode.c index dadb57b..c718182 100644 --- a/transcode.c +++ b/transcode.c @@ -2830,5 +2830,5 @@ 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,}, }; diff --git a/variable.c b/variable.c index 382644b..33e6632 100644 --- a/variable.c +++ b/variable.c @@ -1419,5 +1419,5 @@ 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,}, }; diff --git a/vm.c b/vm.c index 8e93963..f8509d7 100644 --- a/vm.c +++ b/vm.c @@ -245,5 +245,5 @@ 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,}, }; @@ -1570,5 +1570,5 @@ 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,}, }; @@ -1760,7 +1760,9 @@ thread_memsize(const void *ptr) static const rb_data_type_t thread_data_type = { "VM/thread", - rb_thread_mark, - thread_free, - thread_memsize, + { + rb_thread_mark, + thread_free, + thread_memsize, + }, };
-- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦