Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* ruby.swg */ |
2 | /* Implementation : RUBY */ | |
3 | #define SWIGRUBY 1 | |
4 | ||
5 | #include "ruby.h" | |
6 | ||
7 | /* Flags for pointer conversion */ | |
8 | #define SWIG_POINTER_EXCEPTION 0x1 | |
9 | #define SWIG_POINTER_OWN 0x1 | |
10 | #define SWIG_POINTER_DISOWN 0x2 | |
11 | #define SWIG_TRACK_OBJECTS 0x4 | |
12 | ||
13 | #define NUM2USHRT(n) (\ | |
14 | (0 <= NUM2UINT(n) && NUM2UINT(n) <= USHRT_MAX)\ | |
15 | ? (unsigned short) NUM2UINT(n) \ | |
16 | : (rb_raise(rb_eArgError, "integer %d out of range of `unsigned short'",\ | |
17 | NUM2UINT(n)), (short)0)\ | |
18 | ) | |
19 | ||
20 | #define NUM2SHRT(n) (\ | |
21 | (SHRT_MIN <= NUM2INT(n) && NUM2INT(n) <= SHRT_MAX)\ | |
22 | ? (short)NUM2INT(n)\ | |
23 | : (rb_raise(rb_eArgError, "integer %d out of range of `short'",\ | |
24 | NUM2INT(n)), (short)0)\ | |
25 | ) | |
26 | ||
27 | /* Ruby 1.7 defines NUM2LL(), LL2NUM() and ULL2NUM() macros */ | |
28 | #ifndef NUM2LL | |
29 | #define NUM2LL(x) NUM2LONG((x)) | |
30 | #endif | |
31 | #ifndef LL2NUM | |
32 | #define LL2NUM(x) INT2NUM((long) (x)) | |
33 | #endif | |
34 | #ifndef ULL2NUM | |
35 | #define ULL2NUM(x) UINT2NUM((unsigned long) (x)) | |
36 | #endif | |
37 | ||
38 | /* Ruby 1.7 doesn't (yet) define NUM2ULL() */ | |
39 | #ifndef NUM2ULL | |
40 | #ifdef HAVE_LONG_LONG | |
41 | #define NUM2ULL(x) rb_num2ull((x)) | |
42 | #else | |
43 | #define NUM2ULL(x) NUM2ULONG(x) | |
44 | #endif | |
45 | #endif | |
46 | ||
47 | /* | |
48 | * Need to be very careful about how these macros are defined, especially | |
49 | * when compiling C++ code or C code with an ANSI C compiler. | |
50 | * | |
51 | * VALUEFUNC(f) is a macro used to typecast a C function that implements | |
52 | * a Ruby method so that it can be passed as an argument to API functions | |
53 | * like rb_define_method() and rb_define_singleton_method(). | |
54 | * | |
55 | * VOIDFUNC(f) is a macro used to typecast a C function that implements | |
56 | * either the "mark" or "free" stuff for a Ruby Data object, so that it | |
57 | * can be passed as an argument to API functions like Data_Wrap_Struct() | |
58 | * and Data_Make_Struct(). | |
59 | */ | |
60 | ||
61 | #ifdef __cplusplus | |
62 | # ifndef RUBY_METHOD_FUNC /* These definitions should work for Ruby 1.4.6 */ | |
63 | # define PROTECTFUNC(f) ((VALUE (*)()) f) | |
64 | # define VALUEFUNC(f) ((VALUE (*)()) f) | |
65 | # define VOIDFUNC(f) ((void (*)()) f) | |
66 | # else | |
67 | # ifndef ANYARGS /* These definitions should work for Ruby 1.6 */ | |
68 | # define PROTECTFUNC(f) ((VALUE (*)()) f) | |
69 | # define VALUEFUNC(f) ((VALUE (*)()) f) | |
70 | # define VOIDFUNC(f) ((RUBY_DATA_FUNC) f) | |
71 | # else /* These definitions should work for Ruby 1.7+ */ | |
72 | # define PROTECTFUNC(f) ((VALUE (*)(VALUE)) f) | |
73 | # define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f) | |
74 | # define VOIDFUNC(f) ((RUBY_DATA_FUNC) f) | |
75 | # endif | |
76 | # endif | |
77 | #else | |
78 | # define VALUEFUNC(f) (f) | |
79 | # define VOIDFUNC(f) (f) | |
80 | #endif | |
81 | ||
82 | typedef struct { | |
83 | VALUE klass; | |
84 | VALUE mImpl; | |
85 | void (*mark)(void *); | |
86 | void (*destroy)(void *); | |
87 | } swig_class; | |
88 | ||
89 | /* Don't use for expressions have side effect */ | |
90 | #ifndef RB_STRING_VALUE | |
91 | #define RB_STRING_VALUE(s) (TYPE(s) == T_STRING ? (s) : (*(volatile VALUE *)&(s) = rb_str_to_str(s))) | |
92 | #endif | |
93 | #ifndef StringValue | |
94 | #define StringValue(s) RB_STRING_VALUE(s) | |
95 | #endif | |
96 | #ifndef StringValuePtr | |
97 | #define StringValuePtr(s) RSTRING(RB_STRING_VALUE(s))->ptr | |
98 | #endif | |
99 | #ifndef StringValueLen | |
100 | #define StringValueLen(s) RSTRING(RB_STRING_VALUE(s))->len | |
101 | #endif | |
102 | #ifndef SafeStringValue | |
103 | #define SafeStringValue(v) do {\ | |
104 | StringValue(v);\ | |
105 | rb_check_safe_str(v);\ | |
106 | } while (0) | |
107 | #endif | |
108 | ||
109 | #ifndef HAVE_RB_DEFINE_ALLOC_FUNC | |
110 | #define rb_define_alloc_func(klass, func) rb_define_singleton_method((klass), "new", VALUEFUNC((func)), -1) | |
111 | #define rb_undef_alloc_func(klass) rb_undef_method(CLASS_OF((klass)), "new") | |
112 | #endif | |
113 | ||
114 | /* Contract support */ | |
115 | ||
116 | #define SWIG_contract_assert(expr, msg) if (!(expr)) { rb_raise(rb_eRuntimeError, (char *) msg ); } else | |
117 |