diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-06-16 21:36:50 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-06-16 21:36:50 +0000 |
commit | a74d12dc285ed07464d1272c7c15ab3eae4972be (patch) | |
tree | 15aa77a6191cf6223baa51fc7578b6e1fcd6a62b /include/ruby | |
parent | a0e0fafa0c45eba54689854d6c8d3ace9badefe0 (diff) | |
download | ruby-a74d12dc285ed07464d1272c7c15ab3eae4972be.tar.gz |
* include/ruby/ruby.h: New structure RTypedData, added.
This structure incldues more explicit type information for
T_DATA objects. If RData(obj)->dfree is immediate value `1' on
T_DATA object obj, obj is needed to be accessed with RTYPEDDATA(obj)
instead of RDATA(obj). A RTypedData structure points the structure
rb_typed_data_t. rb_typed_data_t includes information such as the
type name of this data, mark and free function what RData includes,
and memsize function show how data consuming the memory size.
Note that you do not need any change existing T_DATA objects.
If you use RDataType instead of RData on T_DATA object,
you can specify explicit type information.
* gc.c (rb_data_typed_object_alloc, rb_objspace_data_type_memsize,
rb_objspace_data_type_name): added.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23710 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'include/ruby')
-rw-r--r-- | include/ruby/ruby.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 7da0b9e908..9da3f5b9fd 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -735,14 +735,34 @@ struct RData { void *data; }; +typedef struct rb_data_type_struct { + const char *name; + void (*dmark)(void*); + void (*dfree)(void*); + size_t (*dsize)(void *); + void *ary[4]; /* for extension */ +} rb_data_type_t; + +struct RTypedData { + struct RBasic basic; + const rb_data_type_t *type; + VALUE typed_flag; /* 1 or not */ + void *data; +}; + #define DATA_PTR(dta) (RDATA(dta)->data) +#define RTYPEDDATA_P(v) (RTYPEDDATA(v)->typed_flag == 1) +#define RTYPEDDATA_TYPE(v) (RTYPEDDATA(v)->type) +#define RTYPEDDATA_DATA(v) (RTYPEDDATA(v)->data) + /* #define RUBY_DATA_FUNC(func) ((void (*)(void*))func) */ 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 *); #define Data_Wrap_Struct(klass,mark,free,sval)\ rb_data_object_alloc(klass,sval,(RUBY_DATA_FUNC)mark,(RUBY_DATA_FUNC)free) @@ -753,6 +773,15 @@ VALUE rb_data_object_alloc(VALUE,void*,RUBY_DATA_FUNC,RUBY_DATA_FUNC); Data_Wrap_Struct(klass,mark,free,sval)\ ) +#define Data_Wrap_TypedStruct(klass,data_type,sval)\ + rb_data_typed_object_alloc(klass,sval,data_type) + +#define Data_Make_TypedStruct(klass, type, data_type, sval) (\ + sval = ALLOC(type),\ + memset(sval, 0, sizeof(type)),\ + Data_Wrap_TypedStruct(klass,data_type,sval)\ +) + #define Data_Get_Struct(obj,type,sval) do {\ Check_Type(obj, T_DATA); \ sval = (type*)DATA_PTR(obj);\ @@ -826,6 +855,7 @@ struct RBignum { #define RARRAY(obj) (R_CAST(RArray)(obj)) #define RHASH(obj) (R_CAST(RHash)(obj)) #define RDATA(obj) (R_CAST(RData)(obj)) +#define RTYPEDDATA(obj) (R_CAST(RTypedData)(obj)) #define RSTRUCT(obj) (R_CAST(RStruct)(obj)) #define RBIGNUM(obj) (R_CAST(RBignum)(obj)) #define RFILE(obj) (R_CAST(RFile)(obj)) |