Ruby 4.0.7p0 (2026-09-15 revision 229531a6cfbf07e3caef30dbac24a2a3f3fed482)
rb_data_type_struct Struct Reference

This is the struct that holds necessary info for a struct. More...

#include <rtypeddata.h>

Data Structures

struct  [struct].function
 Function pointers. More...

Data Fields

const char * wrap_struct_name
 Name of structs of this kind.
struct  function
const rb_data_type_tparent
 Parent of this class.
void * data
 Type-specific static data.
VALUE flags
 Type-specific behavioural characteristics.

Detailed Description

This is the struct that holds necessary info for a struct.

It roughly resembles a Ruby level class; multiple objects can share a rb_data_type_t instance.

Definition at line 208 of file rtypeddata.h.

Field Documentation

◆ data

void* rb_data_type_struct::data

Type-specific static data.

This area can be used for any purpose by a programmer who define the type. Ruby does not manage this at all.

Definition at line 304 of file rtypeddata.h.

◆ flags

VALUE rb_data_type_struct::flags

Type-specific behavioural characteristics.

This is a bitfield. It is an EXTREMELY WISE IDEA to leave this field blank. It is designed so that setting zero is the safest thing to do. If you risk to set any bits on, you have to know exactly what you are doing.

Definition at line 317 of file rtypeddata.h.

◆ parent

const rb_data_type_t* rb_data_type_struct::parent

Parent of this class.

Sometimes C structs have inheritance-like relationships. An example is struct sockaddr and its family. If you design such things, make rb_data_type_t for each of them and connect using this field. Ruby can then transparently cast your data back and forth when you call TypedData_Get_Struct().

struct parent { };
static inline const rb_data_type_t parent_type = {
.wrap_struct_name = "parent",
};
struct child: public parent { };
static inline const rb_data_type_t child_type = {
.wrap_struct_name = "child",
.parent = &parent_type,
};
// This function can take both parent_class and child_class.
static inline struct parent *
get_parent(VALUE v)
{
struct parent *p;
TypedData_Get_Struct(v, parent_type, struct parent, p);
return p;
}
#define TypedData_Get_Struct(obj, type, data_type, sval)
Obtains a C struct from inside of a wrapper Ruby object.
Definition rtypeddata.h:649
struct rb_data_type_struct rb_data_type_t
This is the struct that holds necessary info for a struct.
Definition rtypeddata.h:205
const rb_data_type_t * parent
Parent of this class.
Definition rtypeddata.h:298
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40

Definition at line 298 of file rtypeddata.h.

Referenced by rb_typeddata_inherited_p().

◆ wrap_struct_name

const char* rb_data_type_struct::wrap_struct_name

Name of structs of this kind.

This is used for diagnostic purposes. This has to be unique in the process, but doesn't has to be a valid C/Ruby identifier.

Definition at line 215 of file rtypeddata.h.

Referenced by rb_check_typeddata().


The documentation for this struct was generated from the following file: