Ruby  3.4.0dev (2024-12-06 revision 892c46283a5ea4179500d951c9d4866c0051f27b)
rstruct.h
Go to the documentation of this file.
1 #ifndef RBIMPL_RSTRUCT_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RBIMPL_RSTRUCT_H
26 #include "ruby/internal/value.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
61 
74 
90 
93 static inline long
95 {
96  RBIMPL_ASSERT_TYPE(st, RUBY_T_STRUCT);
97 
98  return RB_NUM2LONG(rb_struct_size(st));
99 }
100 
103 static inline VALUE
104 RSTRUCT_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 
113 static inline VALUE
114 RSTRUCT_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 */
Defines RBIMPL_ATTR_ARTIFICIAL.
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition: artificial.h:41
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:74
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:65
#define INT2NUM
Old name of RB_INT2NUM.
Definition: int.h:43
Arithmetic conversion between C's int and Ruby's.
Arithmetic conversion between C's long and Ruby's.
#define RB_NUM2LONG
Just another name of rb_num2long_inline.
Definition: long.h:57
#define inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Definition: defines.h:88
static long RSTRUCT_LEN(VALUE st)
Returns the number of struct members.
Definition: rstruct.h:94
static VALUE RSTRUCT_SET(VALUE st, int k, VALUE v)
Resembles Struct#[]=.
Definition: rstruct.h:104
static VALUE RSTRUCT_GET(VALUE st, int k)
Resembles Struct#[].
Definition: rstruct.h:114
VALUE rb_struct_aset(VALUE st, VALUE k, VALUE v)
Resembles Struct#[]=.
Definition: struct.c:1255
VALUE rb_struct_size(VALUE st)
Returns the number of struct members.
Definition: struct.c:1505
VALUE rb_struct_aref(VALUE st, VALUE k)
Resembles Struct#[].
Definition: struct.c:1217
Defines VALUE and ID.
uintptr_t VALUE
Type that represents a Ruby object.
Definition: value.h:40
Defines enum ruby_value_type.
@ RUBY_T_STRUCT
Definition: value_type.h:124