-
Notifications
You must be signed in to change notification settings - Fork 0
/
compat.h
57 lines (47 loc) · 1.22 KB
/
compat.h
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
48
49
50
51
52
53
54
55
56
57
/* contains basic macros to facilitate ruby 1.8 and ruby 1.9 compatibility */
#ifndef GUARD_COMPAT_H
#define GUARD_COMPAT_H
#include <ruby.h>
/* test for 1.9 */
#if !defined(RUBY_19) && defined(ROBJECT_EMBED_LEN_MAX)
# define RUBY_19
#endif
/* macros for backwards compatibility with 1.8 */
#ifndef RUBY_19
# define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
# define RCLASS_SUPER(c) (RCLASS(c)->super)
# define RCLASS_IV_TBL(c) (RCLASS(c)->iv_tbl)
# define OBJ_UNTRUSTED OBJ_TAINTED
# include "st.h"
#endif
#ifdef RUBY_19
inline static VALUE
class_alloc(VALUE flags, VALUE klass)
{
rb_classext_t *ext = ALLOC(rb_classext_t);
NEWOBJ(obj, struct RClass);
OBJSETUP(obj, klass, flags);
obj->ptr = ext;
RCLASS_IV_TBL(obj) = 0;
RCLASS_M_TBL(obj) = 0;
RCLASS_SUPER(obj) = 0;
RCLASS_IV_INDEX_TBL(obj) = 0;
return (VALUE)obj;
}
#endif
inline static VALUE
create_class(VALUE flags, VALUE klass)
{
#ifdef RUBY_19
VALUE new_klass = class_alloc(flags, klass);
#else
NEWOBJ(new_klass, struct RClass);
OBJSETUP(new_klass, klass, flags);
#endif
return (VALUE)new_klass;
}
# define FALSE 0
# define TRUE 1
/* a useful macro. cannot use ordinary CLASS_OF as it does not return an lvalue */
#define KLASS_OF(c) (RBASIC(c)->klass)
#endif