* error.c (rb_check_typed_struct): new function to check typed
struct. * include/ruby/ruby.h (Check_TypedStruct, Data_Get_TypedStruct): new macro to check typed struct. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23981 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0f2d1527ab
commit
7bb9cc23a1
@ -1,3 +1,11 @@
|
|||||||
|
Tue Jul 7 13:44:49 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* error.c (rb_check_typed_struct): new function to check typed
|
||||||
|
struct.
|
||||||
|
|
||||||
|
* include/ruby/ruby.h (Check_TypedStruct, Data_Get_TypedStruct):
|
||||||
|
new macro to check typed struct.
|
||||||
|
|
||||||
Tue Jul 7 13:36:46 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue Jul 7 13:36:46 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* enum.c (DEFINE_ENUMFUNCS): included function signature.
|
* enum.c (DEFINE_ENUMFUNCS): included function signature.
|
||||||
|
20
error.c
20
error.c
@ -316,6 +316,26 @@ rb_check_type(VALUE x, int t)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
rb_check_typed_struct(VALUE obj, const rb_data_type_t *data_type)
|
||||||
|
{
|
||||||
|
const char *etype;
|
||||||
|
static const char mesg[] = "wrong argument type %s (expected %s)";
|
||||||
|
|
||||||
|
if (SPECIAL_CONST_P(obj) || BUILTIN_TYPE(obj) != T_DATA) {
|
||||||
|
Check_Type(obj, T_DATA);
|
||||||
|
}
|
||||||
|
if (!RTYPEDDATA_P(obj)) {
|
||||||
|
etype = rb_obj_classname(obj);
|
||||||
|
rb_raise(rb_eTypeError, mesg, etype, data_type->name);
|
||||||
|
}
|
||||||
|
else if (RTYPEDDATA_TYPE(obj) != data_type) {
|
||||||
|
etype = RTYPEDDATA_TYPE(obj)->name;
|
||||||
|
rb_raise(rb_eTypeError, mesg, etype, data_type->name);
|
||||||
|
}
|
||||||
|
return DATA_PTR(obj);
|
||||||
|
}
|
||||||
|
|
||||||
/* exception classes */
|
/* exception classes */
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
@ -764,6 +764,8 @@ typedef void (*RUBY_DATA_FUNC)(void*);
|
|||||||
|
|
||||||
VALUE rb_data_object_alloc(VALUE,void*,RUBY_DATA_FUNC,RUBY_DATA_FUNC);
|
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 *);
|
VALUE rb_data_typed_object_alloc(VALUE klass, void *datap, const rb_data_type_t *);
|
||||||
|
void *rb_check_typed_struct(VALUE, const rb_data_type_t *);
|
||||||
|
#define Check_TypedStruct(v,t) rb_check_typed_struct((VALUE)(v),t)
|
||||||
|
|
||||||
#define Data_Wrap_Struct(klass,mark,free,sval)\
|
#define Data_Wrap_Struct(klass,mark,free,sval)\
|
||||||
rb_data_object_alloc(klass,sval,(RUBY_DATA_FUNC)mark,(RUBY_DATA_FUNC)free)
|
rb_data_object_alloc(klass,sval,(RUBY_DATA_FUNC)mark,(RUBY_DATA_FUNC)free)
|
||||||
@ -788,6 +790,10 @@ VALUE rb_data_typed_object_alloc(VALUE klass, void *datap, const rb_data_type_t
|
|||||||
sval = (type*)DATA_PTR(obj);\
|
sval = (type*)DATA_PTR(obj);\
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define Data_Get_TypedStruct(obj,type,data_type,sval) do {\
|
||||||
|
sval = (type*)rb_check_typed_struct(obj, data_type); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#define RSTRUCT_EMBED_LEN_MAX 3
|
#define RSTRUCT_EMBED_LEN_MAX 3
|
||||||
struct RStruct {
|
struct RStruct {
|
||||||
struct RBasic basic;
|
struct RBasic basic;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user