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 TYPED_DATA_EMBEDDED ((VALUE)1)
119#define TYPED_DATA_PTR_MASK (~(TYPED_DATA_EMBEDDED))
128rbimpl_typeddata_flags {
142 RUBY_TYPED_FREE_IMMEDIATELY = 1,
144 RUBY_TYPED_EMBEDDABLE = 2,
248 size_t (*
dsize)(
const void *);
381#if !defined(__cplusplus) || __cplusplus >= 201103L
461#define TypedData_Wrap_Struct(klass,data_type,sval)\
462 rb_data_typed_object_wrap((klass),(sval),(data_type))
477#define TypedData_Make_Struct0(result, klass, type, size, data_type, sval) \
478 VALUE result = rb_data_typed_object_zalloc(klass, size, data_type); \
479 (sval) = (type *)RTYPEDDATA_GET_DATA(result); \
480 RBIMPL_CAST((void)(sval))
495#ifdef HAVE_STMT_AND_DECL_IN_EXPR
496#define TypedData_Make_Struct(klass, type, data_type, sval) \
497 RB_GNUC_EXTENSION({ \
498 TypedData_Make_Struct0( \
508#define TypedData_Make_Struct(klass, type, data_type, sval) \
509 rb_data_typed_object_make( \
512 RBIMPL_CAST((void **)&(sval)), \
517RTYPEDDATA_EMBEDDED_P(
VALUE obj)
526 return (
RTYPEDDATA(obj)->type) & TYPED_DATA_EMBEDDED;
530RTYPEDDATA_GET_DATA(
VALUE obj)
540 return RTYPEDDATA_EMBEDDED_P(obj) ?
541 RBIMPL_CAST((
void *)&(
RTYPEDDATA(obj)->data)) :
559rbimpl_rtypeddata_p(
VALUE obj)
561 return FL_TEST_RAW(obj, RUBY_TYPED_FL_IS_TYPED_DATA);
584 return rbimpl_rtypeddata_p(obj);
622 void *data = RTYPEDDATA_GET_DATA(obj);
623 if (RB_LIKELY(actual_type == expected_type)) {
627 while (actual_type) {
628 actual_type = actual_type->
parent;
629 if (actual_type == expected_type) {
649#define TypedData_Get_Struct(obj,type,data_type,sval) \
650 ((sval) = RBIMPL_CAST((type *)rbimpl_check_typeddata((obj), (data_type))))
678 return rb_data_typed_object_wrap(
klass, datap, type);
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_USER2
User-defined flag.
@ RUBY_FL_USERPRIV0
This flag meaning is type dependent, currently only used by T_DATA.
@ 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).
#define T_DATA
Old name of RUBY_T_DATA.
#define FL_TEST_RAW
Old name of RB_FL_TEST_RAW.
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.
#define TypedData_Make_Struct0(result, klass, type, size, data_type, sval)
This is an implementation detail of TypedData_Make_Struct.
struct rb_data_type_struct rb_data_type_t
This is the struct that holds necessary info for a 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.
C99 shim for <stdbool.h>.
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.
void * reserved[1]
This field is reserved for future extension.
size_t(*) dsize(const void *)
This function is to query the size of the underlying memory regions.
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.
RUBY_DATA_FUNC dcompact
This function is called when the object is relocated.
This is the struct that holds necessary info for a struct.
const rb_data_type_t * parent
Parent of this class.
const char * wrap_struct_name
Name of structs of this kind.
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.