+#define GET_OBJ(obj, type, o) \
+ type *(o) = NULL; \
+\
+ Data_Get_Struct ((obj), type, (o)); \
+\
+ if (!*(o)) { \
+ rb_raise (rb_eException, \
+ "%s destroyed already", \
+ rb_obj_classname ((obj))); \
+ return Qnil; \
+ }
+
+#define CHECK_BOOL(val) \
+ if (TYPE ((val)) != T_TRUE && TYPE ((val)) != T_FALSE) { \
+ rb_raise (rb_eTypeError, \
+ "wrong argument type %s (expected true or false)", \
+ rb_obj_classname ((val))); \
+ return Qnil; \
+ }
+
+#define INSPECT(obj, type) \
+ char buf[128]; \
+\
+ GET_OBJ (obj, type, o); \
+\
+ snprintf (buf, sizeof (buf), \
+ "#<%s:%p ptr=%p>", rb_obj_classname ((obj)), \
+ (void *) obj, *o); \
+\
+ return rb_str_new2 (buf);
+