sed -i s|ruby/3|ruby/impl|g
[ruby.git] / internal / struct.h
blob41664155760e04ba653c8124b2b699eced985df1
1 #ifndef INTERNAL_STRUCT_H /*-*-C-*-vi:se ft=c:*/
2 #define INTERNAL_STRUCT_H
3 /**
4 * @file
5 * @author Ruby developers <ruby-core@ruby-lang.org>
6 * @copyright This file is a part of the programming language Ruby.
7 * Permission is hereby granted, to either redistribute and/or
8 * modify this file, provided that the conditions mentioned in the
9 * file COPYING are met. Consult the file for details.
10 * @brief Internal header for Struct.
12 #include "ruby/impl/stdbool.h" /* for bool */
13 #include "internal/gc.h" /* for RB_OBJ_WRITE */
14 #include "ruby/ruby.h" /* for struct RBasic */
16 enum {
17 RSTRUCT_EMBED_LEN_MAX = RVALUE_EMBED_LEN_MAX,
18 RSTRUCT_EMBED_LEN_MASK = (RUBY_FL_USER2|RUBY_FL_USER1),
19 RSTRUCT_EMBED_LEN_SHIFT = (RUBY_FL_USHIFT+1),
20 RSTRUCT_TRANSIENT_FLAG = FL_USER3,
23 struct RStruct {
24 struct RBasic basic;
25 union {
26 struct {
27 long len;
28 const VALUE *ptr;
29 } heap;
30 const VALUE ary[RSTRUCT_EMBED_LEN_MAX];
31 } as;
34 #define RSTRUCT(obj) (R_CAST(RStruct)(obj))
36 #ifdef RSTRUCT_LEN
37 # undef RSTRUCT_LEN
38 #endif
40 #ifdef RSTRUCT_PTR
41 # undef RSTRUCT_PTR
42 #endif
44 #ifdef RSTRUCT_SET
45 # undef RSTRUCT_SET
46 #endif
48 #ifdef RSTRUCT_GET
49 # undef RSTRUCT_GET
50 #endif
52 #define RSTRUCT_LEN internal_RSTRUCT_LEN
53 #define RSTRUCT_SET internal_RSTRUCT_SET
54 #define RSTRUCT_GET internal_RSTRUCT_GET
56 /* struct.c */
57 VALUE rb_struct_init_copy(VALUE copy, VALUE s);
58 VALUE rb_struct_lookup(VALUE s, VALUE idx);
59 VALUE rb_struct_s_keyword_init(VALUE klass);
60 static inline const VALUE *rb_struct_const_heap_ptr(VALUE st);
61 static inline bool RSTRUCT_TRANSIENT_P(VALUE st);
62 static inline void RSTRUCT_TRANSIENT_SET(VALUE st);
63 static inline void RSTRUCT_TRANSIENT_UNSET(VALUE st);
64 static inline long RSTRUCT_EMBED_LEN(VALUE st);
65 static inline long RSTRUCT_LEN(VALUE st);
66 static inline int RSTRUCT_LENINT(VALUE st);
67 static inline const VALUE *RSTRUCT_CONST_PTR(VALUE st);
68 static inline void RSTRUCT_SET(VALUE st, long k, VALUE v);
69 static inline VALUE RSTRUCT_GET(VALUE st, long k);
71 static inline bool
72 RSTRUCT_TRANSIENT_P(VALUE st)
74 #if USE_TRANSIENT_HEAP
75 return FL_TEST_RAW(st, RSTRUCT_TRANSIENT_FLAG);