23 #include "ruby/internal/config.h"
31 #include "ruby/internal/cast.h"
40 #ifndef RUBY_UNTYPED_DATA_WARNING
41 #define RUBY_UNTYPED_DATA_WARNING 1
44 #define RBIMPL_DATA_FUNC(f) RBIMPL_CAST((void (*)(void *))(f))
45 #define RBIMPL_ATTRSET_UNTYPED_DATA_FUNC() \
46 RBIMPL_ATTR_WARNING(("untyped Data is unsafe; use TypedData instead")) \
47 RBIMPL_ATTR_DEPRECATED(("by TypedData"))
49 #define RBIMPL_MACRO_SELECT(x, y) x ## y
50 #define RUBY_MACRO_SELECT(x, y) RBIMPL_MACRO_SELECT(x, y)
59 #define RDATA(obj) RBIMPL_CAST((struct RData *)(obj))
67 #define DATA_PTR(obj) RDATA(obj)->data
78 #define RUBY_DEFAULT_FREE RBIMPL_DATA_FUNC(-1)
85 #define RUBY_NEVER_FREE RBIMPL_DATA_FUNC(0)
94 #define RUBY_UNTYPED_DATA_FUNC(f) f RBIMPL_ATTRSET_UNTYPED_DATA_FUNC()
198 #define Data_Wrap_Struct(klass, mark, free, sval) \
199 rb_data_object_wrap( \
202 RBIMPL_DATA_FUNC(mark), \
203 RBIMPL_DATA_FUNC(free))
219 #define Data_Make_Struct0(result, klass, type, size, mark, free, sval) \
220 VALUE result = rb_data_object_zalloc( \
223 RBIMPL_DATA_FUNC(mark), \
224 RBIMPL_DATA_FUNC(free)); \
225 (sval) = RBIMPL_CAST((type *)DATA_PTR(result)); \
226 RBIMPL_CAST((void)(sval))
243 #ifdef HAVE_STMT_AND_DECL_IN_EXPR
244 #define Data_Make_Struct(klass, type, mark, free, sval) \
245 RB_GNUC_EXTENSION({ \
257 #define Data_Make_Struct(klass, type, mark, free, sval) \
258 rb_data_object_make( \
260 RBIMPL_DATA_FUNC(mark), \
261 RBIMPL_DATA_FUNC(free), \
262 RBIMPL_CAST((void **)&(sval)), \
274 #define Data_Get_Struct(obj, type, sval) \
275 ((sval) = RBIMPL_CAST((type*)rb_data_object_get(obj)))
277 RBIMPL_ATTRSET_UNTYPED_DATA_FUNC()
308 rb_data_object_get(
VALUE obj)
314 RBIMPL_ATTRSET_UNTYPED_DATA_FUNC()
325 rb_data_object_get_warning(
VALUE obj)
327 return rb_data_object_get(obj);
360 #define rb_data_object_wrap_0 rb_data_object_wrap
361 #define rb_data_object_wrap_1 rb_data_object_wrap_warning
362 #define rb_data_object_wrap_2 rb_data_object_wrap_
363 #define rb_data_object_wrap RUBY_MACRO_SELECT(rb_data_object_wrap_2, RUBY_UNTYPED_DATA_WARNING)
364 #define rb_data_object_get_0 rb_data_object_get
365 #define rb_data_object_get_1 rb_data_object_get_warning
366 #define rb_data_object_get_2 rb_data_object_get_
367 #define rb_data_object_get RUBY_MACRO_SELECT(rb_data_object_get_2, RUBY_UNTYPED_DATA_WARNING)
368 #define rb_data_object_make_0 rb_data_object_make
369 #define rb_data_object_make_1 rb_data_object_make_warning
370 #define rb_data_object_make_2 rb_data_object_make_
371 #define rb_data_object_make RUBY_MACRO_SELECT(rb_data_object_make_2, RUBY_UNTYPED_DATA_WARNING)
Defines RBIMPL_ATTR_WARNING.
Defines RBIMPL_ATTR_DEPRECATED.
#define RBIMPL_ATTR_DEPRECATED(msg)
Wraps (or simulates) [[deprecated]]
Tweaking visibility of C variables/functions.
#define RUBY_EXTERN
Declaration of externally visible global variables.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Defines enum ruby_fl_type.
char * ptr
Pointer to the underlying memory region, of at least capa bytes.
#define inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
VALUE rb_data_object_wrap(VALUE klass, void *datap, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree)
This is the primitive way to wrap an existing C struct into RData.
static VALUE rb_data_object_alloc(VALUE klass, void *data, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree)
static VALUE rb_data_object_make(VALUE klass, RUBY_DATA_FUNC mark_func, RUBY_DATA_FUNC free_func, void **datap, size_t size)
This is an implementation detail of Data_Make_Struct.
#define DATA_PTR(obj)
Convenient getter macro.
VALUE rb_data_object_zalloc(VALUE klass, size_t size, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree)
Identical to rb_data_object_wrap(), except it allocates a new data region internally instead of takin...
void(* RUBY_DATA_FUNC)(void *)
This is the type of callbacks registered to RData.
#define Data_Make_Struct0(result, klass, type, size, mark, free, sval)
This is an implementation detail of Data_Make_Struct.
Ruby object's base components.
const VALUE klass
Class of an object.
RUBY_DATA_FUNC dfree
This function is called when the object is no longer used.
RUBY_DATA_FUNC dmark
This function is called when the object is experiencing GC marks.
void * data
Pointer to the actual C level struct that you want to wrap.
struct RBasic basic
Basic part, including flags and class.
uintptr_t VALUE
Type that represents a Ruby object.
Defines enum ruby_value_type.
static void Check_Type(VALUE v, enum ruby_value_type t)
Identical to RB_TYPE_P(), except it raises exceptions on predication failure.