1#ifndef RBIMPL_RTYPEDDATA_H
2#define RBIMPL_RTYPEDDATA_H
23#include "ruby/internal/config.h"
34#include "ruby/internal/cast.h"
51#define HAVE_TYPE_RB_DATA_TYPE_T 1
60#define HAVE_RB_DATA_TYPE_T_FUNCTION 1
69#define HAVE_RB_DATA_TYPE_T_PARENT 1
80#define RUBY_TYPED_DEFAULT_FREE RUBY_DEFAULT_FREE
87#define RUBY_TYPED_NEVER_FREE RUBY_NEVER_FREE
95#define RTYPEDDATA(obj) RBIMPL_CAST((struct RTypedData *)(obj))
103#define RTYPEDDATA_DATA(v) (RTYPEDDATA(v)->data)
106#define Check_TypedStruct(v, t) \
107 rb_check_typeddata(RBIMPL_CAST((VALUE)(v)), (t))
110#define RTYPEDDATA_P RTYPEDDATA_P
111#define RTYPEDDATA_TYPE RTYPEDDATA_TYPE
112#define RUBY_TYPED_FREE_IMMEDIATELY RUBY_TYPED_FREE_IMMEDIATELY
113#define RUBY_TYPED_FROZEN_SHAREABLE RUBY_TYPED_FROZEN_SHAREABLE
114#define RUBY_TYPED_WB_PROTECTED RUBY_TYPED_WB_PROTECTED
115#define RUBY_TYPED_PROMOTED1 RUBY_TYPED_PROMOTED1
118#define IS_TYPED_DATA ((VALUE)1)
119#define TYPED_DATA_EMBEDDED ((VALUE)2)
120#define TYPED_DATA_PTR_FLAGS ((VALUE)3)
121#define TYPED_DATA_PTR_MASK (~TYPED_DATA_PTR_FLAGS)
130rbimpl_typeddata_flags {
144 RUBY_TYPED_FREE_IMMEDIATELY = 1,
146 RUBY_TYPED_EMBEDDABLE = 2,
378#if !defined(__cplusplus) || __cplusplus >= 201103L
458#define TypedData_Wrap_Struct(klass,data_type,sval)\
459 rb_data_typed_object_wrap((klass),(sval),(data_type))
474#define TypedData_Make_Struct0(result, klass, type, size, data_type, sval) \
475 VALUE result = rb_data_typed_object_zalloc(klass, size, data_type); \
476 (sval) = (type *)RTYPEDDATA_GET_DATA(result); \
477 RBIMPL_CAST((void)(sval))
492#ifdef HAVE_STMT_AND_DECL_IN_EXPR
493#define TypedData_Make_Struct(klass, type, data_type, sval) \
494 RB_GNUC_EXTENSION({ \
495 TypedData_Make_Struct0( \
505#define TypedData_Make_Struct(klass, type, data_type, sval) \
506 rb_data_typed_object_make( \
509 RBIMPL_CAST((void **)&(sval)), \
523#define TypedData_Get_Struct(obj,type,data_type,sval) \
524 ((sval) = RBIMPL_CAST((type *)rb_check_typeddata((obj), (data_type))))
527RTYPEDDATA_EMBEDDED_P(
VALUE obj)
536 return (
RTYPEDDATA(obj)->type) & TYPED_DATA_EMBEDDED;
540RTYPEDDATA_GET_DATA(
VALUE obj)
551 const size_t embedded_typed_data_size =
sizeof(
struct RTypedData) - sizeof(void *);
553 return RTYPEDDATA_EMBEDDED_P(obj) ? (
char *)obj + embedded_typed_data_size :
RTYPEDDATA(obj)->
data;
570rbimpl_rtypeddata_p(
VALUE obj)
595 return rbimpl_rtypeddata_p(obj);
Defines RBIMPL_ATTR_ARTIFICIAL.
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
#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)
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_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.
void rb_unexpected_type(VALUE x, int t)
Fails with the given object's type incompatibility to the type.
Defines RBIMPL_STATIC_ASSERT.
#define RBIMPL_STATIC_ASSERT
Wraps (or simulates) static_assert
Defines RBIMPL_ASSUME / RBIMPL_UNREACHABLE.
#define RBIMPL_UNREACHABLE_RETURN(_)
Wraps (or simulates) __builtin_unreachable.
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()
Wraps (or simulates) __attribute__((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.
#define RTYPEDDATA(obj)
Convenient casting macro.
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...
static const struct rb_data_type_struct * RTYPEDDATA_TYPE(VALUE obj)
Queries for the type of given object.
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 type
This is a const rb_data_type_t *const value, with the low bits set:
VALUE fields_obj
Direct reference to the slots that holds instance variables, if any.
struct RBasic basic
The part that all ruby objects have in common.
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.
struct rb_data_type_struct::@54 function
Function pointers.
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.