Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* Common SWIG API */ |
2 | #define SWIG_ConvertPtr(obj, pp, type, flags) \ | |
3 | SWIG_Ruby_ConvertPtr(obj, pp, type, flags) | |
4 | #define SWIG_NewPointerObj(p, type, flags) \ | |
5 | SWIG_Ruby_NewPointerObj(p, type, flags) | |
6 | #define SWIG_MustGetPtr(p, type, argnum, flags) \ | |
7 | SWIG_Ruby_MustGetPtr(p, type, argnum, flags) | |
8 | #define SWIG_GetModule(clientdata) \ | |
9 | SWIG_Ruby_GetModule() | |
10 | #define SWIG_SetModule(clientdata, pointer) \ | |
11 | SWIG_Ruby_SetModule(pointer) | |
12 | ||
13 | /* Ruby-specific SWIG API */ | |
14 | ||
15 | #define SWIG_InitRuntime() \ | |
16 | SWIG_Ruby_InitRuntime() | |
17 | #define SWIG_define_class(ty) \ | |
18 | SWIG_Ruby_define_class(ty) | |
19 | #define SWIG_NewClassInstance(value, ty) \ | |
20 | SWIG_Ruby_NewClassInstance(value, ty) | |
21 | #define SWIG_MangleStr(value) \ | |
22 | SWIG_Ruby_MangleStr(value) | |
23 | #define SWIG_CheckConvert(value, ty) \ | |
24 | SWIG_Ruby_CheckConvert(value, ty) | |
25 | #define SWIG_NewPackedObj(ptr, sz, ty) \ | |
26 | SWIG_Ruby_NewPackedObj(ptr, sz, ty) | |
27 | #define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) \ | |
28 | SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty, flags) | |
29 | ||
30 | /* rubydef.swg */ | |
31 | #ifdef __cplusplus | |
32 | extern "C" { | |
33 | #endif | |
34 | ||
35 | static VALUE _mSWIG = Qnil; | |
36 | static VALUE _cSWIG_Pointer = Qnil; | |
37 | static VALUE swig_runtime_data_type_pointer = Qnil; | |
38 | ||
39 | /* Initialize Ruby runtime support */ | |
40 | static void | |
41 | SWIG_Ruby_InitRuntime(void) | |
42 | { | |
43 | if (_mSWIG == Qnil) { | |
44 | _mSWIG = rb_define_module("SWIG"); | |
45 | } | |
46 | } | |
47 | ||
48 | /* Define Ruby class for C type */ | |
49 | static void | |
50 | SWIG_Ruby_define_class(swig_type_info *type) | |
51 | { | |
52 | VALUE klass; | |
53 | char *klass_name = (char *) malloc(4 + strlen(type->name) + 1); | |
54 | sprintf(klass_name, "TYPE%s", type->name); | |
55 | if (NIL_P(_cSWIG_Pointer)) { | |
56 | _cSWIG_Pointer = rb_define_class_under(_mSWIG, "Pointer", rb_cObject); | |
57 | rb_undef_method(CLASS_OF(_cSWIG_Pointer), "new"); | |
58 | } | |
59 | klass = rb_define_class_under(_mSWIG, klass_name, _cSWIG_Pointer); | |
60 | free((void *) klass_name); | |
61 | } | |
62 | ||
63 | /* Create a new pointer object */ | |
64 | static VALUE | |
65 | SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int flags) | |
66 | { | |
67 | int own = flags & SWIG_POINTER_OWN; | |
68 | int track = flags & SWIG_TRACK_OBJECTS; | |
69 | ||
70 | char *klass_name; | |
71 | swig_class *sklass; | |
72 | VALUE klass; | |
73 | VALUE obj; | |
74 | ||
75 | if (!ptr) | |
76 | return Qnil; | |
77 | ||
78 | /* Have we already wrapped this pointer? */ | |
79 | if (track) { | |
80 | obj = SWIG_RubyInstanceFor(ptr); | |
81 | if (obj != Qnil) { | |
82 | return obj; | |
83 | } | |
84 | } | |
85 | ||
86 | if (type->clientdata) { | |
87 | sklass = (swig_class *) type->clientdata; | |
88 | obj = Data_Wrap_Struct(sklass->klass, VOIDFUNC(sklass->mark), (own ? VOIDFUNC(sklass->destroy) : 0), ptr); | |
89 | } else { | |
90 | klass_name = (char *) malloc(4 + strlen(type->name) + 1); | |
91 | sprintf(klass_name, "TYPE%s", type->name); | |
92 | klass = rb_const_get(_mSWIG, rb_intern(klass_name)); | |
93 | free((void *) klass_name); | |
94 | obj = Data_Wrap_Struct(klass, 0, 0, ptr); | |
95 | } | |
96 | rb_iv_set(obj, "__swigtype__", rb_str_new2(type->name)); | |
97 | ||
98 | /* Keep track of this object if necessary */ | |
99 | if (track) { | |
100 | SWIG_RubyAddTracking(ptr, obj); | |
101 | } | |
102 | ||
103 | return obj; | |
104 | } | |
105 | ||
106 | /* Create a new class instance (always owned) */ | |
107 | static VALUE | |
108 | SWIG_Ruby_NewClassInstance(VALUE klass, swig_type_info *type) | |
109 | { | |
110 | VALUE obj; | |
111 | swig_class *sklass = (swig_class *) type->clientdata; | |
112 | obj = Data_Wrap_Struct(klass, VOIDFUNC(sklass->mark), VOIDFUNC(sklass->destroy), 0); | |
113 | rb_iv_set(obj, "__swigtype__", rb_str_new2(type->name)); | |
114 | return obj; | |
115 | } | |
116 | ||
117 | /* Get type mangle from class name */ | |
118 | static SWIGINLINE char * | |
119 | SWIG_Ruby_MangleStr(VALUE obj) | |
120 | { | |
121 | VALUE stype = rb_iv_get(obj, "__swigtype__"); | |
122 | return StringValuePtr(stype); | |
123 | } | |
124 | ||
125 | /* Convert a pointer value */ | |
126 | static int | |
127 | SWIG_Ruby_ConvertPtr(VALUE obj, void **ptr, swig_type_info *ty, int flags) | |
128 | { | |
129 | char *c; | |
130 | swig_cast_info *tc; | |
131 | ||
132 | /* Grab the pointer */ | |
133 | if (NIL_P(obj)) { | |
134 | *ptr = 0; | |
135 | return 0; | |
136 | } else { | |
137 | Data_Get_Struct(obj, void, *ptr); | |
138 | } | |
139 | ||
140 | /* Check to see if the input object is giving up ownership | |
141 | of the underlying C struct or C++ object. If so then we | |
142 | need to reset the destructor since the Ruby object no | |
143 | longer owns the underlying C++ object.*/ | |
144 | if (flags & SWIG_POINTER_DISOWN) { | |
145 | if (flags & SWIG_TRACK_OBJECTS) { | |
146 | /* We are tracking objects. Thus we change the destructor | |
147 | * to SWIG_RubyRemoveTracking. This allows us to | |
148 | * remove the mapping from the C++ to Ruby object | |
149 | * when the Ruby object is garbage collected. If we don't | |
150 | * do this, then it is possible we will return a reference | |
151 | * to a Ruby object that no longer exists thereby crashing Ruby. */ | |
152 | RDATA(obj)->dfree = SWIG_RubyRemoveTracking; | |
153 | } else { | |
154 | RDATA(obj)->dfree = 0; | |
155 | } | |
156 | } | |
157 | ||
158 | /* Do type-checking if type info was provided */ | |
159 | if (ty) { | |
160 | if (ty->clientdata) { | |
161 | if (rb_obj_is_kind_of(obj, ((swig_class *) (ty->clientdata))->klass)) { | |
162 | if (*ptr == 0) | |
163 | rb_raise(rb_eRuntimeError, "This %s already released", ty->str); | |
164 | return 0; | |
165 | } | |
166 | } | |
167 | if ((c = SWIG_MangleStr(obj)) == NULL) { | |
168 | if (flags & SWIG_POINTER_EXCEPTION) | |
169 | rb_raise(rb_eTypeError, "Expected %s", ty->str); | |
170 | else | |
171 | return -1; | |
172 | } | |
173 | tc = SWIG_TypeCheck(c, ty); | |
174 | if (!tc) { | |
175 | if (flags & SWIG_POINTER_EXCEPTION) | |
176 | rb_raise(rb_eTypeError, "Expected %s", ty->str); | |
177 | else | |
178 | return -1; | |
179 | } | |
180 | *ptr = SWIG_TypeCast(tc, *ptr); | |
181 | } | |
182 | return 0; | |
183 | } | |
184 | ||
185 | /* Convert a pointer value, signal an exception on a type mismatch */ | |
186 | static SWIGINLINE void * | |
187 | SWIG_Ruby_MustGetPtr(VALUE obj, swig_type_info *ty, int argnum, int flags) | |
188 | { | |
189 | void *result; | |
190 | SWIG_ConvertPtr(obj, &result, ty, flags | SWIG_POINTER_EXCEPTION); | |
191 | return result; | |
192 | } | |
193 | ||
194 | /* Check convert */ | |
195 | static SWIGINLINE int | |
196 | SWIG_Ruby_CheckConvert(VALUE obj, swig_type_info *ty) | |
197 | { | |
198 | char *c = SWIG_MangleStr(obj); | |
199 | if (!c) | |
200 | return 0; | |
201 | return SWIG_TypeCheck(c,ty) != 0; | |
202 | } | |
203 | ||
204 | static VALUE | |
205 | SWIG_Ruby_NewPackedObj(void *ptr, int sz, swig_type_info *type) { | |
206 | char result[1024]; | |
207 | char *r = result; | |
208 | if ((2*sz + 1 + strlen(type->name)) > 1000) return 0; | |
209 | *(r++) = '_'; | |
210 | r = SWIG_PackData(r, ptr, sz); | |
211 | strcpy(r, type->name); | |
212 | return rb_str_new2(result); | |
213 | } | |
214 | ||
215 | /* Convert a packed value value */ | |
216 | static void | |
217 | SWIG_Ruby_ConvertPacked(VALUE obj, void *ptr, int sz, swig_type_info *ty, int flags) { | |
218 | swig_cast_info *tc; | |
219 | const char *c; | |
220 | ||
221 | if (TYPE(obj) != T_STRING) goto type_error; | |
222 | c = StringValuePtr(obj); | |
223 | /* Pointer values must start with leading underscore */ | |
224 | if (*c != '_') goto type_error; | |
225 | c++; | |
226 | c = SWIG_UnpackData(c, ptr, sz); | |
227 | if (ty) { | |
228 | tc = SWIG_TypeCheck(c, ty); | |
229 | if (!tc) goto type_error; | |
230 | } | |
231 | return; | |
232 | ||
233 | type_error: | |
234 | ||
235 | if (flags) { | |
236 | if (ty) { | |
237 | rb_raise(rb_eTypeError, "Type error. Expected %s", ty->name); | |
238 | } else { | |
239 | rb_raise(rb_eTypeError, "Expected a pointer"); | |
240 | } | |
241 | } | |
242 | } | |
243 | ||
244 | static swig_module_info *SWIG_Ruby_GetModule() { | |
245 | VALUE pointer; | |
246 | swig_module_info *ret = 0; | |
247 | ||
248 | /* first check if pointer already created */ | |
249 | pointer = rb_gv_get("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME); | |
250 | if (pointer != Qnil) { | |
251 | Data_Get_Struct(pointer, swig_module_info, ret); | |
252 | } | |
253 | return ret; | |
254 | } | |
255 | ||
256 | static void SWIG_Ruby_SetModule(swig_module_info *pointer) { | |
257 | /* register a new class */ | |
258 | VALUE cl = rb_define_class("swig_runtime_data", rb_cObject); | |
259 | /* create and store the structure pointer to a global variable */ | |
260 | swig_runtime_data_type_pointer = Data_Wrap_Struct(cl, 0, 0, pointer); | |
261 | rb_define_readonly_variable("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, &swig_runtime_data_type_pointer); | |
262 | } | |
263 | ||
264 | #ifdef __cplusplus | |
265 | } | |
266 | #endif | |
267 |