| 1 |
/** |
| 2 |
** @file 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 |
union { |
| 25 |
intptr_t inline_alignment[3]; |
| 26 |
char inline_data[ISTRUCT_DATA_SIZE]; |
| 27 |
}; |
| 28 |
}; |
| 29 |
|
| 30 |
#define RISTRUCT(obj) ((struct RIStruct*)(mrb_ptr(obj))) |
| 31 |
#define ISTRUCT_PTR(obj) (RISTRUCT(obj)->inline_data) |
| 32 |
|
| 33 |
MRB_INLINE mrb_int mrb_istruct_size() |
| 34 |
{ |
| 35 |
return ISTRUCT_DATA_SIZE; |
| 36 |
} |
| 37 |
|
| 38 |
MRB_INLINE void* mrb_istruct_ptr(mrb_value object) |
| 39 |
{ |
| 40 |
return ISTRUCT_PTR(object); |
| 41 |
} |
| 42 |
|
| 43 |
MRB_INLINE void mrb_istruct_copy(mrb_value dest, mrb_value src) |
| 44 |
{ |
| 45 |
memcpy(ISTRUCT_PTR(dest), ISTRUCT_PTR(src), ISTRUCT_DATA_SIZE); |
| 46 |
} |
| 47 |
|
| 48 |
MRB_END_DECL |
| 49 |
|
| 50 |
#endif /* MRUBY_ISTRUCT_H */ |