summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/deps/mruby/include/mruby/istruct.h
blob: 4d2393ccd30837e85d396362bd30899b2ff69e64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
** mruby/istruct.h - Inline structures
**
** See Copyright Notice in mruby.h
*/

#ifndef MRUBY_ISTRUCT_H
#define MRUBY_ISTRUCT_H

#include "common.h"
#include <string.h>

/**
 * Inline structures that fit in RVALUE
 *
 * They cannot have finalizer, and cannot have instance variables.
 */
MRB_BEGIN_DECL

#define ISTRUCT_DATA_SIZE (sizeof(void*) * 3)

struct RIstruct {
  MRB_OBJECT_HEADER;
  char inline_data[ISTRUCT_DATA_SIZE];
};

#define RISTRUCT(obj)         ((struct RIstruct*)(mrb_ptr(obj)))
#define ISTRUCT_PTR(obj)      (RISTRUCT(obj)->inline_data)

MRB_INLINE mrb_int mrb_istruct_size()
{
  return ISTRUCT_DATA_SIZE;
}

MRB_INLINE void* mrb_istruct_ptr(mrb_value object)
{
  return ISTRUCT_PTR(object);
}

MRB_INLINE void mrb_istruct_copy(mrb_value dest, mrb_value src)
{
  memcpy(ISTRUCT_PTR(dest), ISTRUCT_PTR(src), ISTRUCT_DATA_SIZE);
}

MRB_END_DECL

#endif /* MRUBY_ISTRUCT_H */