Ruby  3.4.0dev (2024-11-05 revision e440268d51fe02b303e3817a7a733a0dac1c5091)
Macros | Functions
rstruct.h File Reference

(e440268d51fe02b303e3817a7a733a0dac1c5091)

Routines to manipulate struct RStruct. More...

#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
#include "ruby/internal/value_type.h"
#include "ruby/internal/arithmetic/long.h"
#include "ruby/internal/arithmetic/int.h"
#include "ruby/backward.h"
Include dependency graph for rstruct.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define RSTRUCT_PTR(st)   rb_struct_ptr(st)
 

Functions

VALUE rb_struct_size (VALUE st)
 Returns the number of struct members. More...
 
VALUE rb_struct_aref (VALUE st, VALUE k)
 Resembles Struct#[]. More...
 
VALUE rb_struct_aset (VALUE st, VALUE k, VALUE v)
 Resembles Struct#[]=. More...
 
static long RSTRUCT_LEN (VALUE st)
 Returns the number of struct members.
More...
 
static VALUE RSTRUCT_SET (VALUE st, int k, VALUE v)
 Resembles Struct#[]=.
More...
 
static VALUE RSTRUCT_GET (VALUE st, int k)
 Resembles Struct#[].
More...
 

Detailed Description

Routines to manipulate struct RStruct.

Author
Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org
Warning
Symbols prefixed with either 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.
Note
To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance __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.
The struct RStruct itself is opaque.

Definition in file rstruct.h.

Macro Definition Documentation

◆ RSTRUCT_PTR

#define RSTRUCT_PTR (   st)    rb_struct_ptr(st)
Deprecated:
This macro once was a thing in the old days, but makes no sense any longer today.

Exists here for backwards compatibility only. You can safely forget about it.

Definition at line 45 of file rstruct.h.

Function Documentation

◆ rb_struct_aref()

VALUE rb_struct_aref ( VALUE  st,
VALUE  k 
)

Resembles Struct#[].

Parameters
[in]stAn instance of RStruct.
[in]kIndex a.k.a. key of the struct.
Exceptions
rb_eTypeErrork is neither Numeric, Symbol, nor String.
rb_eIndexErrorNumerical index out of range.
rb_eNameErrorNo such key.
Returns
The member stored at k in st.
Precondition
st must be of RUBY_T_STRUCT.

Definition at line 1217 of file struct.c.

Referenced by RSTRUCT_GET().

◆ rb_struct_aset()

VALUE rb_struct_aset ( VALUE  st,
VALUE  k,
VALUE  v 
)

Resembles Struct#[]=.

Parameters
[out]stAn instance of RStruct.
[in]kIndex a.k.a. key of the struct.
[in]vValue to store.
Exceptions
rb_eTypeErrork is neither Numeric, Symbol, nor String.
rb_eIndexErrorNumerical index out of range.
rb_eNameErrorNo such key.
Returns
Passed v.
Precondition
st must be of RUBY_T_STRUCT.
Postcondition
v is stored at k in st.

Definition at line 1255 of file struct.c.

Referenced by RSTRUCT_SET().

◆ rb_struct_size()

VALUE rb_struct_size ( VALUE  st)

Returns the number of struct members.

Parameters
[in]stAn instance of RStruct.
Returns
The number of members of st.
Precondition
st must be of RUBY_T_STRUCT.

Definition at line 1505 of file struct.c.

Referenced by RSTRUCT_LEN().

◆ RSTRUCT_GET()

static VALUE RSTRUCT_GET ( VALUE  st,
int  k 
)
inlinestatic

Resembles Struct#[].

Parameters
[in]stAn instance of RStruct.
[in]kIndex a.k.a. key of the struct.
Exceptions
rb_eTypeErrork is neither Numeric, Symbol, nor String.
rb_eIndexErrorNumerical index out of range.
rb_eNameErrorNo such key.
Returns
The member stored at k in st.
Precondition
st must be of RUBY_T_STRUCT.

Definition at line 114 of file rstruct.h.

Referenced by rb_struct_aref(), and rb_struct_getmember().

◆ RSTRUCT_LEN()

static long RSTRUCT_LEN ( VALUE  st)
inlinestatic

Returns the number of struct members.

Parameters
[in]stAn instance of RStruct.
Returns
The number of members of st.
Precondition
st must be of RUBY_T_STRUCT.

Definition at line 94 of file rstruct.h.

Referenced by rb_struct_members(), and rb_struct_size().

◆ RSTRUCT_SET()

static VALUE RSTRUCT_SET ( VALUE  st,
int  k,
VALUE  v 
)
inlinestatic

Resembles Struct#[]=.

Parameters
[out]stAn instance of RStruct.
[in]kIndex a.k.a. key of the struct.
[in]vValue to store.
Exceptions
rb_eTypeErrork is neither Numeric, Symbol, nor String.
rb_eIndexErrorNumerical index out of range.
rb_eNameErrorNo such key.
Returns
Passed v.
Precondition
st must be of RUBY_T_STRUCT.
Postcondition
v is stored at k in st.

Definition at line 104 of file rstruct.h.

Referenced by rb_struct_aset().