summaryrefslogtreecommitdiffstats
path: root/error.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-07 04:44:54 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-07 04:44:54 +0000
commit0aa3e1bfaf925cd08a3944c4e6b956203403ebdd (patch)
tree96c1edc93cd5728f477e35b2541dd1b86dd24c8a /error.c
parent0a95ed94c85bad4540d8868eac335b4d85f524ee (diff)
downloadruby-0aa3e1bfaf925cd08a3944c4e6b956203403ebdd.tar.gz
ruby-0aa3e1bfaf925cd08a3944c4e6b956203403ebdd.tar.xz
ruby-0aa3e1bfaf925cd08a3944c4e6b956203403ebdd.zip
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@23981 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r--error.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/error.c b/error.c
index bfa3a950d..04ea58de1 100644
--- a/error.c
+++ b/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 */
#include <errno.h>