1 #ifndef RBIMPL_RTYPEDDATA_H
2 #define RBIMPL_RTYPEDDATA_H
23 #include "ruby/internal/config.h"
34 #include "ruby/internal/cast.h"
50 #define HAVE_TYPE_RB_DATA_TYPE_T 1
59 #define HAVE_RB_DATA_TYPE_T_FUNCTION 1
68 #define HAVE_RB_DATA_TYPE_T_PARENT 1
79 #define RUBY_TYPED_DEFAULT_FREE RUBY_DEFAULT_FREE
86 #define RUBY_TYPED_NEVER_FREE RUBY_NEVER_FREE
94 #define RTYPEDDATA(obj) RBIMPL_CAST((struct RTypedData *)(obj))
102 #define RTYPEDDATA_DATA(v) (RTYPEDDATA(v)->data)
105 #define Check_TypedStruct(v, t) \
106 rb_check_typeddata(RBIMPL_CAST((VALUE)(v)), (t))
109 #define RTYPEDDATA_P RTYPEDDATA_P
110 #define RTYPEDDATA_TYPE RTYPEDDATA_TYPE
111 #define RUBY_TYPED_FREE_IMMEDIATELY RUBY_TYPED_FREE_IMMEDIATELY
112 #define RUBY_TYPED_FROZEN_SHAREABLE RUBY_TYPED_FROZEN_SHAREABLE
113 #define RUBY_TYPED_WB_PROTECTED RUBY_TYPED_WB_PROTECTED
114 #define RUBY_TYPED_PROMOTED1 RUBY_TYPED_PROMOTED1
117 #define TYPED_DATA_EMBEDDED 2
126 rbimpl_typeddata_flags {
140 RUBY_TYPED_FREE_IMMEDIATELY = 1,
142 RUBY_TYPED_EMBEDDABLE = 2,
449 #define TypedData_Wrap_Struct(klass,data_type,sval)\
450 rb_data_typed_object_wrap((klass),(sval),(data_type))
465 #define TypedData_Make_Struct0(result, klass, type, size, data_type, sval) \
466 VALUE result = rb_data_typed_object_zalloc(klass, size, data_type); \
467 (sval) = (type *)RTYPEDDATA_GET_DATA(result); \
468 RBIMPL_CAST((void)(sval))
484 #ifdef HAVE_STMT_AND_DECL_IN_EXPR
485 #define TypedData_Make_Struct(klass, type, data_type, sval) \
486 RB_GNUC_EXTENSION({ \
487 TypedData_Make_Struct0( \
497 #define TypedData_Make_Struct(klass, type, data_type, sval) \
498 rb_data_typed_object_make( \
501 RBIMPL_CAST((void **)&(sval)), \
515 #define TypedData_Get_Struct(obj,type,data_type,sval) \
516 ((sval) = RBIMPL_CAST((type *)rb_check_typeddata((obj), (data_type))))
519 RTYPEDDATA_EMBEDDED_P(
VALUE obj)
528 return RTYPEDDATA(obj)->typed_flag & TYPED_DATA_EMBEDDED;
532 RTYPEDDATA_GET_DATA(
VALUE obj)
543 const size_t embedded_typed_data_size =
sizeof(
struct RTypedData) - sizeof(void *);
545 return RTYPEDDATA_EMBEDDED_P(obj) ? (
char *)obj + embedded_typed_data_size :
RTYPEDDATA(obj)->data;
562 rbimpl_rtypeddata_p(
VALUE obj)
588 return rbimpl_rtypeddata_p(obj);
Defines RBIMPL_ATTR_ARTIFICIAL.
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
#define RB_UNLIKELY(x)
Asserts that the given Boolean expression likely doesn't hold.
#define RBIMPL_ATTR_DEPRECATED(msg)
Wraps (or simulates) [[deprecated]]
Tweaking visibility of C variables/functions.
#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.
@ RUBY_FL_UNUSED6
This flag is no longer in use.
@ RUBY_FL_USER2
User-defined flag.
@ RUBY_FL_SHAREABLE
This flag has something to do with Ractor.
Defines RBIMPL_ATTR_FLAG_ENUM.
#define RBIMPL_ATTR_FLAG_ENUM()
Wraps (or simulates) __attribute__((flag_enum)
void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
Identical to rb_typeddata_is_kind_of(), except it raises exceptions instead of returning false.
int rb_typeddata_inherited_p(const rb_data_type_t *child, const rb_data_type_t *parent)
Checks for the domestic relationship between the two.
int rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type)
Checks if the given object is of given kind.
void rb_unexpected_type(VALUE x, int t)
Fails with the given object's type incompatibility to the type.
RBIMPL_ATTR_PURE() int rb_io_read_pending(rb_io_t *fptr)
Queries if the passed IO has any pending reads.
Defines RBIMPL_ASSUME / RBIMPL_UNREACHABLE.
#define RBIMPL_UNREACHABLE_RETURN(_)
Wraps (or simulates) __builtin_unreachable.
VALUE type(ANYARGS)
ANYARGS-ed function type.
Defines RBIMPL_ATTR_NONNULL.
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
#define inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Defines RBIMPL_ATTR_PURE.
#define RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Enables RBIMPL_ATTR_PURE if and only if.
void(* RUBY_DATA_FUNC)(void *)
This is the type of callbacks registered to RData.
static bool RTYPEDDATA_P(VALUE obj)
Checks whether the passed object is RTypedData or RData.
VALUE rb_data_typed_object_wrap(VALUE klass, void *datap, const rb_data_type_t *type)
This is the primitive way to wrap an existing C struct into RTypedData.
VALUE rb_data_typed_object_zalloc(VALUE klass, size_t size, const rb_data_type_t *type)
Identical to rb_data_typed_object_wrap(), except it allocates a new data region internally instead of...
#define TypedData_Make_Struct0(result, klass, type, size, data_type, sval)
This is an implementation detail of TypedData_Make_Struct.
static VALUE rb_data_typed_object_alloc(VALUE klass, void *datap, const rb_data_type_t *type)
#define RTYPEDDATA(obj)
Convenient casting macro.
static const struct rb_data_type_struct * RTYPEDDATA_TYPE(VALUE obj)
Queries for the type of given object.
static VALUE rb_data_typed_object_make(VALUE klass, const rb_data_type_t *type, void **datap, size_t size)
While we don't stop you from using this function, it seems to be an implementation detail of TypedDat...
Ruby object's base components.
const VALUE klass
Class of an object.
void * data
Pointer to the actual C level struct that you want to wrap.
const VALUE typed_flag
This has to be always 1.
struct RBasic basic
The part that all ruby objects have in common.
const rb_data_type_t *const type
This field stores various information about how Ruby should handle a data.
This is the struct that holds necessary info for a struct.
size_t(* dsize)(const void *)
This function is to query the size of the underlying memory regions.
const rb_data_type_t * parent
Parent of this class.
RUBY_DATA_FUNC dfree
This function is called when the object is no longer used.
void * reserved[1]
This field is reserved for future extension.
RUBY_DATA_FUNC dcompact
This function is called when the object is relocated.
const char * wrap_struct_name
Name of structs of this kind.
RUBY_DATA_FUNC dmark
This function is called when the object is experiencing GC marks.
void * data
Type-specific static data.
VALUE flags
Type-specific behavioural characteristics.
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.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.