Ruby
3.4.0dev (2024-11-22 revision 37a72b0150ec36b4ea27175039afc28c62207b0c)
|
#include "ruby/internal/config.h"
#include "ruby/internal/attr/deprecated.h"
#include "ruby/internal/attr/warning.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/core/rbasic.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/fl_type.h"
#include "ruby/internal/value.h"
#include "ruby/internal/value_type.h"
#include "ruby/defines.h"
Go to the source code of this file.
Data Structures | |
struct | RData |
Macros | |
#define | RDATA(obj) RBIMPL_CAST((struct RData *)(obj)) |
Convenient casting macro. More... | |
#define | DATA_PTR(obj) RDATA(obj)->data |
Convenient getter macro. More... | |
#define | RUBY_DEFAULT_FREE RBIMPL_DATA_FUNC(-1) |
This is a value you can set to RData::dfree. More... | |
#define | RUBY_NEVER_FREE RBIMPL_DATA_FUNC(0) |
This is a value you can set to RData::dfree. More... | |
#define | RUBY_UNTYPED_DATA_FUNC(f) f RBIMPL_ATTRSET_UNTYPED_DATA_FUNC() |
#define | Data_Wrap_Struct(klass, mark, free, sval) |
Converts sval, a pointer to your struct, into a Ruby object. More... | |
#define | Data_Make_Struct0(result, klass, type, size, mark, free, sval) |
This is an implementation detail of Data_Make_Struct. More... | |
#define | Data_Make_Struct(klass, type, mark, free, sval) |
Identical to Data_Wrap_Struct, except it allocates a new data region internally instead of taking an existing one. More... | |
#define | Data_Get_Struct(obj, type, sval) ((sval) = RBIMPL_CAST((type*)rb_data_object_get(obj))) |
Obtains a C struct from inside of a wrapper Ruby object. More... | |
Typedefs | |
typedef void(* | RUBY_DATA_FUNC) (void *) |
This is the type of callbacks registered to RData. More... | |
Functions | |
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. More... | |
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 taking an existing one. More... | |
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. More... | |
static VALUE | rb_data_object_alloc (VALUE klass, void *data, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree) |
Defines struct RData.
RBIMPL
or rbimpl
are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will. __VA_ARGS__
is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98. Definition in file rdata.h.
#define Data_Get_Struct | ( | obj, | |
type, | |||
sval | |||
) | ((sval) = RBIMPL_CAST((type*)rb_data_object_get(obj))) |
#define Data_Make_Struct | ( | klass, | |
type, | |||
mark, | |||
free, | |||
sval | |||
) |
Identical to Data_Wrap_Struct, except it allocates a new data region internally instead of taking an existing one.
The allocation is done using ruby_calloc(). Hence it makes no sense to pass anything other than RUBY_DEFAULT_FREE to the free
argument.
klass | Ruby level class of the returning object. |
type | Type name of the C struct. |
mark | Mark function. |
free | Free function. |
sval | Variable name of created C struct. |
rb_eTypeError | klass is not a class. |
rb_eNoMemError | Out of memory. |
#define Data_Make_Struct0 | ( | result, | |
klass, | |||
type, | |||
size, | |||
mark, | |||
free, | |||
sval | |||
) |
This is an implementation detail of Data_Make_Struct.
People don't use it directly.
result | Variable name of created Ruby object. |
klass | Ruby level class of the object. |
type | Type name of the C struct. |
size | Size of the C struct. |
mark | Mark function. |
free | Free function. |
sval | Variable name of created C struct. |
#define DATA_PTR | ( | obj | ) | RDATA(obj)->data |
Convenient getter macro.
obj | An object, which is in fact an RData. |
#define Data_Wrap_Struct | ( | klass, | |
mark, | |||
free, | |||
sval | |||
) |
Converts sval, a pointer to your struct, into a Ruby object.
klass | A ruby level class. |
mark | Mark function. |
free | Free function. |
sval | A pointer to your struct. |
rb_eTypeError | klass is not a class. |
rb_eNoMemError | Out of memory. |
#define RDATA | ( | obj | ) | RBIMPL_CAST((struct RData *)(obj)) |
#define RUBY_DEFAULT_FREE RBIMPL_DATA_FUNC(-1) |
This is a value you can set to RData::dfree.
Setting this means the data was allocated using ruby_xmalloc() (or variants), and shall be freed using ruby_xfree().
#define RUBY_NEVER_FREE RBIMPL_DATA_FUNC(0) |
This is a value you can set to RData::dfree.
Setting this means the data is managed by someone else, like, statically allocated. Of course you are on your own then.
#define RUBY_UNTYPED_DATA_FUNC | ( | f | ) | f RBIMPL_ATTRSET_UNTYPED_DATA_FUNC() |
Exists here for backwards compatibility only. You can safely forget about it.
typedef void(* RUBY_DATA_FUNC) (void *) |
|
inlinestatic |
|
inlinestatic |
This is an implementation detail of Data_Make_Struct.
People don't use it directly.
[in] | klass | Ruby level class of the returning object. |
[in] | mark_func | Mark function. |
[in] | free_func | Free function. |
[in] | datap | Variable of created C struct. |
[in] | size | Requested size of allocation. |
rb_eTypeError | klass is not a class. |
rb_eNoMemError | Out of memory. |
*datap
holds the created C struct. 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.
[in] | klass | Ruby level class of the returning object. |
[in] | datap | Pointer to the target C struct. |
[in] | dmark | Mark function. |
[in] | dfree | Free function. |
rb_eTypeError | klass is not a class. |
rb_eNoMemError | Out of memory. |
datap
. Definition at line 961 of file gc.c.
Referenced by rb_data_object_zalloc().
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 taking an existing one.
The allocation is done using ruby_calloc(). Hence it makes no sense to pass anything other than RUBY_DEFAULT_FREE to the last argument.
[in] | klass | Ruby level class of the returning object. |
[in] | size | Requested size of memory to allocate. |
[in] | dmark | Mark function. |
[in] | dfree | Free function. |
rb_eTypeError | klass is not a class. |
rb_eNoMemError | Out of memory. |
size
byte region.