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

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

rstruct.h
Go to the documentation of this file.
1#ifndef RBIMPL_RSTRUCT_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_RSTRUCT_H
23#include "ruby/internal/attr/artificial.h"
24#include "ruby/internal/dllexport.h"
25#include "ruby/internal/value.h"
26#include "ruby/internal/value_type.h"
27#include "ruby/internal/arithmetic/long.h"
28#include "ruby/internal/arithmetic/int.h"
29#if !defined RUBY_EXPORT && !defined RUBY_NO_OLD_COMPATIBILITY
30# include "ruby/backward.h"
31#endif
32
33#define RSTRUCT_PTR(st) rb_struct_ptr(st)
35#define RSTRUCT_LEN RSTRUCT_LEN
36#define RSTRUCT_SET RSTRUCT_SET
37#define RSTRUCT_GET RSTRUCT_GET
40 RBIMPL_SYMBOL_EXPORT_BEGIN()
41 VALUE rb_struct_size(VALUE s);
42 VALUE rb_struct_aref(VALUE, VALUE);
43 VALUE rb_struct_aset(VALUE, VALUE, VALUE);
44 RBIMPL_SYMBOL_EXPORT_END()
45
46 RBIMPL_ATTR_ARTIFICIAL()
47static inline long
48 RSTRUCT_LEN(VALUE st)
49{
50 RBIMPL_ASSERT_TYPE(st, RUBY_T_STRUCT);
51
52 return RB_NUM2LONG(rb_struct_size(st));
53}
54
55 RBIMPL_ATTR_ARTIFICIAL()
56static inline VALUE
57 RSTRUCT_SET(VALUE st, int k, VALUE v)
58{
59 RBIMPL_ASSERT_TYPE(st, RUBY_T_STRUCT);
60
61 return rb_struct_aset(st, INT2NUM(k), (v));
62}
63
64 RBIMPL_ATTR_ARTIFICIAL()
65static inline VALUE
66 RSTRUCT_GET(VALUE st, int k)
67{
68 RBIMPL_ASSERT_TYPE(st, RUBY_T_STRUCT);
69
70 return rb_struct_aref(st, INT2NUM(k));
71}
72
73#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
backward.h
dllexport.h
Tewaking visibility of C variables/functions.
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:86
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:77
int.h
Arithmetic conversion between C's int and Ruby's.
INT2NUM
#define INT2NUM
Definition: int.h:43
RSTRUCT_GET
#define RSTRUCT_GET
Definition: struct.h:54
RSTRUCT_LEN
#define RSTRUCT_LEN
Definition: struct.h:52
RSTRUCT_SET
#define RSTRUCT_SET
Definition: struct.h:53
long.h
Arithmetic conversion between C's long and Ruby's.
RB_NUM2LONG
#define RB_NUM2LONG
Definition: long.h:57
rb_struct_size
VALUE rb_struct_size(VALUE s)
Definition: struct.c:1326
rb_struct_aref
VALUE rb_struct_aref(VALUE, VALUE)
Definition: struct.c:1096
rb_struct_aset
VALUE rb_struct_aset(VALUE, VALUE, VALUE)
Definition: struct.c:1123
value.h
Defines VALUE and ID.
VALUE
unsigned long VALUE
Definition: value.h:38
value_type.h
Defines enum ruby_value_type.
RUBY_T_STRUCT
@ RUBY_T_STRUCT
Definition: value_type.h:121