Ruby: include/ruby/internal/core/rstruct.h Source File

Ruby 3.3.5p100 (2024-09-03 revision ef084cc8f4958c1b6e4ead99136631bef6d8ddba)

rstruct.h
Go to the documentation of this file.
1#ifndef RBIMPL_RSTRUCT_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_RSTRUCT_H
24#include "ruby/internal/attr/artificial.h"
25#include "ruby/internal/dllexport.h"
26#include "ruby/internal/value.h"
27#include "ruby/internal/value_type.h"
28#include "ruby/internal/arithmetic/long.h"
29#include "ruby/internal/arithmetic/int.h"
30#if !defined RUBY_EXPORT && !defined RUBY_NO_OLD_COMPATIBILITY
31# include "ruby/backward.h"
32#endif
33
45#define RSTRUCT_PTR(st) rb_struct_ptr(st)
47#define RSTRUCT_LEN RSTRUCT_LEN
48#define RSTRUCT_SET RSTRUCT_SET
49#define RSTRUCT_GET RSTRUCT_GET
52 RBIMPL_SYMBOL_EXPORT_BEGIN()
60 VALUE rb_struct_size(VALUE st);
61
73 VALUE rb_struct_aref(VALUE st, VALUE k);
74
88 VALUE rb_struct_aset(VALUE st, VALUE k, VALUE v);
89 RBIMPL_SYMBOL_EXPORT_END()
90
91 RBIMPL_ATTR_ARTIFICIAL()
93static inline long
94RSTRUCT_LEN(VALUE st)
95{
96 RBIMPL_ASSERT_TYPE(st, RUBY_T_STRUCT);
97
98 return RB_NUM2LONG(rb_struct_size(st));
99}
100
101 RBIMPL_ATTR_ARTIFICIAL()
103static inline VALUE
104RSTRUCT_SET(VALUE st, int k, VALUE v)
105{
106 RBIMPL_ASSERT_TYPE(st, RUBY_T_STRUCT);
107
108 return rb_struct_aset(st, INT2NUM(k), (v));
109}
110
111 RBIMPL_ATTR_ARTIFICIAL()
113static inline VALUE
114RSTRUCT_GET(VALUE st, int k)
115{
116 RBIMPL_ASSERT_TYPE(st, RUBY_T_STRUCT);
117
118 return rb_struct_aref(st, INT2NUM(k));
119}
120
121#endif /* RBIMPL_RSTRUCT_H */
artificial.h
Defines RBIMPL_ATTR_ARTIFICIAL.
RBIMPL_ATTR_ARTIFICIAL
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition artificial.h:43
dllexport.h
Tweaking visibility of C variables/functions.
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition dllexport.h:74
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:65
INT2NUM
#define INT2NUM
Old name of RB_INT2NUM.
Definition int.h:43
int.h
Arithmetic conversion between C's int and Ruby's.
long.h
Arithmetic conversion between C's long and Ruby's.
RB_NUM2LONG
#define RB_NUM2LONG
Just another name of rb_num2long_inline.
Definition long.h:57
inline
#define inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Definition defines.h:66
rb_struct_aset
VALUE rb_struct_aset(VALUE st, VALUE k, VALUE v)
Resembles Struct#[]=.
Definition struct.c:1255
rb_struct_size
VALUE rb_struct_size(VALUE st)
Returns the number of struct members.
Definition struct.c:1505
rb_struct_aref
VALUE rb_struct_aref(VALUE st, VALUE k)
Resembles Struct#[].
Definition struct.c:1217
value.h
Defines VALUE and ID.
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40
value_type.h
Defines enum ruby_value_type.
RUBY_T_STRUCT
@ RUBY_T_STRUCT
Definition value_type.h:123