Apply PIE to nghttpx
[platform/upstream/nghttp2.git] / third-party / mruby / include / mruby / istruct.h
1 /*
2 ** mruby/istruct.h - Inline structures
3 **
4 ** See Copyright Notice in mruby.h
5 */
6
7 #ifndef MRUBY_ISTRUCT_H
8 #define MRUBY_ISTRUCT_H
9
10 #include "common.h"
11 #include <string.h>
12
13 /**
14  * Inline structures that fit in RVALUE
15  *
16  * They cannot have finalizer, and cannot have instance variables.
17  */
18 MRB_BEGIN_DECL
19
20 #define ISTRUCT_DATA_SIZE (sizeof(void*) * 3)
21
22 struct RIstruct {
23   MRB_OBJECT_HEADER;
24   char inline_data[ISTRUCT_DATA_SIZE];
25 };
26
27 #define RISTRUCT(obj)         ((struct RIstruct*)(mrb_ptr(obj)))
28 #define ISTRUCT_PTR(obj)      (RISTRUCT(obj)->inline_data)
29
30 MRB_INLINE mrb_int mrb_istruct_size()
31 {
32   return ISTRUCT_DATA_SIZE;
33 }
34
35 MRB_INLINE void* mrb_istruct_ptr(mrb_value object)
36 {
37   return ISTRUCT_PTR(object);
38 }
39
40 MRB_INLINE void mrb_istruct_copy(mrb_value dest, mrb_value src)
41 {
42   memcpy(ISTRUCT_PTR(dest), ISTRUCT_PTR(src), ISTRUCT_DATA_SIZE);
43 }
44
45 MRB_END_DECL
46
47 #endif /* MRUBY_ISTRUCT_H */