Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* ---------------------------------------------------------------------- -*- c -*- |
2 | * perl5.swg | |
3 | * | |
4 | * Perl5 runtime library | |
5 | * $Header: /cvsroot/swig/SWIG/Lib/perl5/perlrun.swg,v 1.21 2005/02/01 00:08:17 wuzzeb Exp $ | |
6 | * ----------------------------------------------------------------------------- */ | |
7 | ||
8 | #define SWIGPERL | |
9 | #define SWIGPERL5 | |
10 | #ifdef __cplusplus | |
11 | /* Needed on some windows machines---since MS plays funny games with the header files under C++ */ | |
12 | #include <math.h> | |
13 | #include <stdlib.h> | |
14 | extern "C" { | |
15 | #endif | |
16 | #include "EXTERN.h" | |
17 | #include "perl.h" | |
18 | #include "XSUB.h" | |
19 | ||
20 | /* Get rid of free and malloc defined by perl */ | |
21 | #undef free | |
22 | #undef malloc | |
23 | ||
24 | #ifndef pTHX_ | |
25 | #define pTHX_ | |
26 | #endif | |
27 | ||
28 | #include <string.h> | |
29 | #ifdef __cplusplus | |
30 | } | |
31 | #endif | |
32 | ||
33 | /* Macro to call an XS function */ | |
34 | ||
35 | #ifdef PERL_OBJECT | |
36 | # define SWIG_CALLXS(_name) _name(cv,pPerl) | |
37 | #else | |
38 | # ifndef MULTIPLICITY | |
39 | # define SWIG_CALLXS(_name) _name(cv) | |
40 | # else | |
41 | # define SWIG_CALLXS(_name) _name(PERL_GET_THX, cv) | |
42 | # endif | |
43 | #endif | |
44 | ||
45 | /* Contract support */ | |
46 | ||
47 | #define SWIG_contract_assert(expr,msg) if (!(expr)) { SWIG_croak(msg); } else | |
48 | ||
49 | /* Note: SwigMagicFuncHack is a typedef used to get the C++ compiler to just shut up already */ | |
50 | ||
51 | #ifdef PERL_OBJECT | |
52 | #define MAGIC_PPERL CPerlObj *pPerl = (CPerlObj *) this; | |
53 | typedef int (CPerlObj::*SwigMagicFunc)(SV *, MAGIC *); | |
54 | ||
55 | #ifdef __cplusplus | |
56 | extern "C" { | |
57 | #endif | |
58 | typedef int (CPerlObj::*SwigMagicFuncHack)(SV *, MAGIC *); | |
59 | #ifdef __cplusplus | |
60 | } | |
61 | #endif | |
62 | ||
63 | #define SWIG_MAGIC(a,b) (SV *a, MAGIC *b) | |
64 | #define SWIGCLASS_STATIC | |
65 | #else | |
66 | #define MAGIC_PPERL | |
67 | #define SWIGCLASS_STATIC static | |
68 | #ifndef MULTIPLICITY | |
69 | #define SWIG_MAGIC(a,b) (SV *a, MAGIC *b) | |
70 | typedef int (*SwigMagicFunc)(SV *, MAGIC *); | |
71 | ||
72 | #ifdef __cplusplus | |
73 | extern "C" { | |
74 | #endif | |
75 | typedef int (*SwigMagicFuncHack)(SV *, MAGIC *); | |
76 | #ifdef __cplusplus | |
77 | } | |
78 | #endif | |
79 | ||
80 | ||
81 | #else | |
82 | #define SWIG_MAGIC(a,b) (struct interpreter *interp, SV *a, MAGIC *b) | |
83 | typedef int (*SwigMagicFunc)(struct interpreter *, SV *, MAGIC *); | |
84 | #ifdef __cplusplus | |
85 | extern "C" { | |
86 | #endif | |
87 | typedef int (*SwigMagicFuncHack)(struct interpreter *, SV *, MAGIC *); | |
88 | #ifdef __cplusplus | |
89 | } | |
90 | #endif | |
91 | ||
92 | #endif | |
93 | #endif | |
94 | ||
95 | #if defined(WIN32) && defined(PERL_OBJECT) && !defined(PerlIO_exportFILE) | |
96 | #define PerlIO_exportFILE(fh,fl) (FILE*)(fh) | |
97 | #endif | |
98 | ||
99 | /* Modifications for newer Perl 5.005 releases */ | |
100 | ||
101 | #if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50)))) | |
102 | # ifndef PL_sv_yes | |
103 | # define PL_sv_yes sv_yes | |
104 | # endif | |
105 | # ifndef PL_sv_undef | |
106 | # define PL_sv_undef sv_undef | |
107 | # endif | |
108 | # ifndef PL_na | |
109 | # define PL_na na | |
110 | # endif | |
111 | #endif | |
112 | ||
113 | #include <stdlib.h> | |
114 | ||
115 | #ifdef __cplusplus | |
116 | extern "C" { | |
117 | #endif | |
118 | ||
119 | #define SWIG_OWNER 1 | |
120 | #define SWIG_SHADOW 2 | |
121 | ||
122 | /* Common SWIG API */ | |
123 | ||
124 | #ifdef PERL_OBJECT | |
125 | # define SWIG_ConvertPtr(obj, pp, type, flags) \ | |
126 | SWIG_Perl_ConvertPtr(pPerl, obj, pp, type, flags) | |
127 | # define SWIG_NewPointerObj(p, type, flags) \ | |
128 | SWIG_Perl_NewPointerObj(pPerl, p, type, flags) | |
129 | # define SWIG_MakePackedObj(sv, p, s, type) \ | |
130 | SWIG_Perl_MakePackedObj(pPerl, sv, p, s, type) | |
131 | # define SWIG_ConvertPacked(obj, p, s, type, flags) \ | |
132 | SWIG_Perl_ConvertPacked(pPerl, obj, p, s, type, flags) | |
133 | ||
134 | #else | |
135 | # define SWIG_ConvertPtr(obj, pp, type, flags) \ | |
136 | SWIG_Perl_ConvertPtr(obj, pp, type, flags) | |
137 | # define SWIG_NewPointerObj(p, type, flags) \ | |
138 | SWIG_Perl_NewPointerObj(p, type, flags) | |
139 | # define SWIG_MakePackedObj(sv, p, s, type) \ | |
140 | SWIG_Perl_MakePackedObj(sv, p, s, type ) | |
141 | # define SWIG_ConvertPacked(obj, p, s, type, flags) \ | |
142 | SWIG_Perl_ConvertPacked(obj, p, s, type, flags) | |
143 | #endif | |
144 | ||
145 | /* Runtime API */ | |
146 | #define SWIG_GetModule(clientdata) SWIG_Perl_GetModule() | |
147 | #define SWIG_SetModule(clientdata, pointer) SWIG_Perl_SetModule(pointer) | |
148 | ||
149 | /* Perl-specific API */ | |
150 | #ifdef PERL_OBJECT | |
151 | # define SWIG_MakePtr(sv, ptr, type, flags) \ | |
152 | SWIG_Perl_MakePtr(pPerl, sv, ptr, type, flags) | |
153 | # define SWIG_SetError(str) \ | |
154 | SWIG_Perl_SetError(pPerl, str) | |
155 | #else | |
156 | # define SWIG_MakePtr(sv, ptr, type, flags) \ | |
157 | SWIG_Perl_MakePtr(sv, ptr, type, flags) | |
158 | # define SWIG_SetError(str) \ | |
159 | SWIG_Perl_SetError(str) | |
160 | # define SWIG_SetErrorSV(str) \ | |
161 | SWIG_Perl_SetErrorSV(str) | |
162 | #endif | |
163 | ||
164 | #define SWIG_SetErrorf SWIG_Perl_SetErrorf | |
165 | ||
166 | ||
167 | #ifdef PERL_OBJECT | |
168 | # define SWIG_MAYBE_PERL_OBJECT CPerlObj *pPerl, | |
169 | #else | |
170 | # define SWIG_MAYBE_PERL_OBJECT | |
171 | #endif | |
172 | ||
173 | static swig_cast_info * | |
174 | SWIG_Perl_TypeCheckRV(SWIG_MAYBE_PERL_OBJECT SV *rv, swig_type_info *ty) { | |
175 | SWIG_TypeCheck_Template(sv_derived_from(rv, (char *) iter->type->name), ty); | |
176 | } | |
177 | ||
178 | /* Function for getting a pointer value */ | |
179 | ||
180 | static int | |
181 | SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *_t, int flags) { | |
182 | swig_cast_info *tc; | |
183 | void *voidptr = (void *)0; | |
184 | ||
185 | /* If magical, apply more magic */ | |
186 | if (SvGMAGICAL(sv)) | |
187 | mg_get(sv); | |
188 | ||
189 | /* Check to see if this is an object */ | |
190 | if (sv_isobject(sv)) { | |
191 | SV *tsv = (SV*) SvRV(sv); | |
192 | IV tmp = 0; | |
193 | if ((SvTYPE(tsv) == SVt_PVHV)) { | |
194 | MAGIC *mg; | |
195 | if (SvMAGICAL(tsv)) { | |
196 | mg = mg_find(tsv,'P'); | |
197 | if (mg) { | |
198 | sv = mg->mg_obj; | |
199 | if (sv_isobject(sv)) { | |
200 | tmp = SvIV((SV*)SvRV(sv)); | |
201 | } | |
202 | } | |
203 | } else { | |
204 | return -1; | |
205 | } | |
206 | } else { | |
207 | tmp = SvIV((SV*)SvRV(sv)); | |
208 | } | |
209 | voidptr = (void *)tmp; | |
210 | if (!_t) { | |
211 | *(ptr) = voidptr; | |
212 | return 0; | |
213 | } | |
214 | } else if (! SvOK(sv)) { /* Check for undef */ | |
215 | *(ptr) = (void *) 0; | |
216 | return 0; | |
217 | } else if (SvTYPE(sv) == SVt_RV) { /* Check for NULL pointer */ | |
218 | *(ptr) = (void *) 0; | |
219 | if (!SvROK(sv)) | |
220 | return 0; | |
221 | else | |
222 | return -1; | |
223 | } else { /* Don't know what it is */ | |
224 | *(ptr) = (void *) 0; | |
225 | return -1; | |
226 | } | |
227 | if (_t) { | |
228 | /* Now see if the types match */ | |
229 | char *_c = HvNAME(SvSTASH(SvRV(sv))); | |
230 | tc = SWIG_TypeCheck(_c,_t); | |
231 | if (!tc) { | |
232 | *ptr = voidptr; | |
233 | return -1; | |
234 | } | |
235 | *ptr = SWIG_TypeCast(tc,voidptr); | |
236 | return 0; | |
237 | } | |
238 | *ptr = voidptr; | |
239 | return 0; | |
240 | } | |
241 | ||
242 | static void | |
243 | SWIG_Perl_MakePtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, swig_type_info *t, int flags) { | |
244 | if (ptr && (flags & SWIG_SHADOW)) { | |
245 | SV *self; | |
246 | SV *obj=newSV(0); | |
247 | HV *hash=newHV(); | |
248 | HV *stash; | |
249 | sv_setref_pv(obj, (char *) t->name, ptr); | |
250 | stash=SvSTASH(SvRV(obj)); | |
251 | if (flags & SWIG_OWNER) { | |
252 | HV *hv; | |
253 | GV *gv=*(GV**)hv_fetch(stash, "OWNER", 5, TRUE); | |
254 | if (!isGV(gv)) | |
255 | gv_init(gv, stash, "OWNER", 5, FALSE); | |
256 | hv=GvHVn(gv); | |
257 | hv_store_ent(hv, obj, newSViv(1), 0); | |
258 | } | |
259 | sv_magic((SV *)hash, (SV *)obj, 'P', Nullch, 0); | |
260 | SvREFCNT_dec(obj); | |
261 | self=newRV_noinc((SV *)hash); | |
262 | sv_setsv(sv, self); | |
263 | SvREFCNT_dec((SV *)self); | |
264 | sv_bless(sv, stash); | |
265 | } | |
266 | else { | |
267 | sv_setref_pv(sv, (char *) t->name, ptr); | |
268 | } | |
269 | } | |
270 | ||
271 | static SWIGINLINE SV * | |
272 | SWIG_Perl_NewPointerObj(SWIG_MAYBE_PERL_OBJECT void *ptr, swig_type_info *t, int flags) { | |
273 | SV *result = sv_newmortal(); | |
274 | SWIG_MakePtr(result, ptr, t, flags); | |
275 | return result; | |
276 | } | |
277 | ||
278 | static void | |
279 | SWIG_Perl_MakePackedObj(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, int sz, swig_type_info *type) { | |
280 | char result[1024]; | |
281 | char *r = result; | |
282 | if ((2*sz + 1 + strlen(type->name)) > 1000) return; | |
283 | *(r++) = '_'; | |
284 | r = SWIG_PackData(r,ptr,sz); | |
285 | strcpy(r,type->name); | |
286 | sv_setpv(sv, result); | |
287 | } | |
288 | ||
289 | /* Convert a packed value value */ | |
290 | static int | |
291 | SWIG_Perl_ConvertPacked(SWIG_MAYBE_PERL_OBJECT SV *obj, void *ptr, int sz, swig_type_info *ty, int flags) { | |
292 | swig_cast_info *tc; | |
293 | const char *c = 0; | |
294 | ||
295 | if ((!obj) || (!SvOK(obj))) return -1; | |
296 | c = SvPV(obj, PL_na); | |
297 | /* Pointer values must start with leading underscore */ | |
298 | if (*c != '_') return -1; | |
299 | c++; | |
300 | c = SWIG_UnpackData(c,ptr,sz); | |
301 | if (ty) { | |
302 | tc = SWIG_TypeCheck(c,ty); | |
303 | if (!tc) return -1; | |
304 | } | |
305 | return 0; | |
306 | } | |
307 | ||
308 | static SWIGINLINE void | |
309 | SWIG_Perl_SetError(SWIG_MAYBE_PERL_OBJECT const char *error) { | |
310 | if (error) sv_setpv(perl_get_sv("@", TRUE), error); | |
311 | } | |
312 | ||
313 | static SWIGINLINE void | |
314 | SWIG_Perl_SetErrorSV(SWIG_MAYBE_PERL_OBJECT SV *error) { | |
315 | if (error) sv_setsv(perl_get_sv("@", TRUE), error); | |
316 | } | |
317 | ||
318 | static void | |
319 | SWIG_Perl_SetErrorf(const char *fmt, ...) { | |
320 | va_list args; | |
321 | va_start(args, fmt); | |
322 | sv_vsetpvfn(perl_get_sv("@", TRUE), fmt, strlen(fmt), &args, Null(SV**), 0, Null(bool*)); | |
323 | va_end(args); | |
324 | } | |
325 | ||
326 | /* Macros for low-level exception handling */ | |
327 | #define SWIG_fail goto fail | |
328 | #define SWIG_croak(x) { SWIG_SetError(x); goto fail; } | |
329 | #define SWIG_croakSV(x) { SWIG_SetErrorSV(x); goto fail; } | |
330 | /* most preprocessors do not support vararg macros :-( */ | |
331 | /* #define SWIG_croakf(x...) { SWIG_SetErrorf(x); goto fail; } */ | |
332 | ||
333 | ||
334 | typedef XS(SwigPerlWrapper); | |
335 | typedef SwigPerlWrapper *SwigPerlWrapperPtr; | |
336 | ||
337 | /* Structure for command table */ | |
338 | typedef struct { | |
339 | const char *name; | |
340 | SwigPerlWrapperPtr wrapper; | |
341 | } swig_command_info; | |
342 | ||
343 | /* Information for constant table */ | |
344 | ||
345 | #define SWIG_INT 1 | |
346 | #define SWIG_FLOAT 2 | |
347 | #define SWIG_STRING 3 | |
348 | #define SWIG_POINTER 4 | |
349 | #define SWIG_BINARY 5 | |
350 | ||
351 | /* Constant information structure */ | |
352 | typedef struct swig_constant_info { | |
353 | int type; | |
354 | const char *name; | |
355 | long lvalue; | |
356 | double dvalue; | |
357 | void *pvalue; | |
358 | swig_type_info **ptype; | |
359 | } swig_constant_info; | |
360 | ||
361 | #ifdef __cplusplus | |
362 | } | |
363 | #endif | |
364 | ||
365 | /* Structure for variable table */ | |
366 | typedef struct { | |
367 | const char *name; | |
368 | SwigMagicFunc set; | |
369 | SwigMagicFunc get; | |
370 | swig_type_info **type; | |
371 | } swig_variable_info; | |
372 | ||
373 | /* Magic variable code */ | |
374 | #ifndef PERL_OBJECT | |
375 | #define swig_create_magic(s,a,b,c) _swig_create_magic(s,a,b,c) | |
376 | #ifndef MULTIPLICITY | |
377 | static void _swig_create_magic(SV *sv, char *name, int (*set)(SV *, MAGIC *), int (*get)(SV *,MAGIC *)) { | |
378 | #else | |
379 | static void _swig_create_magic(SV *sv, char *name, int (*set)(struct interpreter*, SV *, MAGIC *), int (*get)(struct interpreter*, SV *,MAGIC *)) { | |
380 | #endif | |
381 | #else | |
382 | # define swig_create_magic(s,a,b,c) _swig_create_magic(pPerl,s,a,b,c) | |
383 | static void _swig_create_magic(CPerlObj *pPerl, SV *sv, const char *name, int (CPerlObj::*set)(SV *, MAGIC *), int (CPerlObj::*get)(SV *, MAGIC *)) { | |
384 | #endif | |
385 | MAGIC *mg; | |
386 | sv_magic(sv,sv,'U',(char *) name,strlen(name)); | |
387 | mg = mg_find(sv,'U'); | |
388 | mg->mg_virtual = (MGVTBL *) malloc(sizeof(MGVTBL)); | |
389 | mg->mg_virtual->svt_get = (SwigMagicFuncHack) get; | |
390 | mg->mg_virtual->svt_set = (SwigMagicFuncHack) set; | |
391 | mg->mg_virtual->svt_len = 0; | |
392 | mg->mg_virtual->svt_clear = 0; | |
393 | mg->mg_virtual->svt_free = 0; | |
394 | } | |
395 | ||
396 | ||
397 | static swig_module_info * | |
398 | SWIG_Perl_GetModule() { | |
399 | static void *type_pointer = (void *)0; | |
400 | SV *pointer; | |
401 | ||
402 | /* first check if pointer already created */ | |
403 | if (!type_pointer) { | |
404 | pointer = get_sv("swig_runtime_data::type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, FALSE); | |
405 | if (pointer && SvOK(pointer)) { | |
406 | type_pointer = INT2PTR(swig_type_info **, SvIV(pointer)); | |
407 | } | |
408 | } | |
409 | ||
410 | return (swig_module_info *) type_pointer; | |
411 | } | |
412 | ||
413 | static void | |
414 | SWIG_Perl_SetModule(swig_module_info *module) { | |
415 | SV *pointer; | |
416 | ||
417 | /* create a new pointer */ | |
418 | pointer = get_sv("swig_runtime_data::type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, TRUE); | |
419 | sv_setiv(pointer, PTR2IV(module)); | |
420 | } |