]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wxSWIG/Runtime/libperl.swg
Test if G_threads already are initialized.
[wxWidgets.git] / wxPython / wxSWIG / Runtime / libperl.swg
1 /* Definitions for compiling Perl extensions on a variety of machines */
2
3 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
4 # if defined(_MSC_VER)
5 # define SWIGEXPORT(a) __declspec(dllexport) a
6 # else
7 # if defined(__BORLANDC__)
8 # define SWIGEXPORT(a) a _export
9 # else
10 # define SWIGEXPORT(a) a
11 # endif
12 # endif
13 #else
14 # define SWIGEXPORT(a) a
15 #endif
16
17 #ifdef PERL_OBJECT
18 #define MAGIC_PPERL CPerlObj *pPerl = (CPerlObj *) this;
19 #define MAGIC_CAST (int (CPerlObj::*)(SV *, MAGIC *))
20 #define SWIGCLASS_STATIC
21 #else
22 #define MAGIC_PPERL
23 #define MAGIC_CAST
24 #define SWIGCLASS_STATIC static
25 #endif
26
27 #if defined(WIN32) && defined(PERL_OBJECT) && !defined(PerlIO_exportFILE)
28 #define PerlIO_exportFILE(fh,fl) (FILE*)(fh)
29 #endif
30
31 /* Modifications for newer Perl 5.005 releases */
32
33 #if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50))))
34 #ifndef PL_sv_yes
35 #define PL_sv_yes sv_yes
36 #endif
37 #ifndef PL_sv_undef
38 #define PL_sv_undef sv_undef
39 #endif
40 #ifndef PL_na
41 #define PL_na na
42 #endif
43 #endif
44
45 /******************************************************************************
46 * Pointer type-checking code
47 *****************************************************************************/
48
49 #include <stdlib.h>
50
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54
55 #ifdef SWIG_NOINCLUDE
56 extern void SWIG_MakePtr(char *, void *, char *);
57 #ifndef PERL_OBJECT
58 extern void SWIG_RegisterMapping(char *, char *, void *(*)(void *));
59 #else
60 #define SWIG_RegisterMapping(a,b,c) _SWIG_RegisterMapping(pPerl,a,b,c);
61 extern void _SWIG_RegisterMapping(CPerlObj *,char *, char *, void *(*)(void *),int);
62 #endif
63 #ifndef PERL_OBJECT
64 extern char *SWIG_GetPtr(SV *, void **, char *);
65 #else
66 extern char *_SWIG_GetPtr(CPerlObj *, SV *, void **, char *);
67 #define SWIG_GetPtr(a,b,c) _SWIG_GetPtr(pPerl,a,b,c)
68 #endif
69
70 #else
71
72 #ifdef SWIG_GLOBAL
73 #define SWIGSTATICRUNTIME(a) SWIGEXPORT(a)
74 #else
75 #define SWIGSTATICRUNTIME(a) static a
76 #endif
77
78 /* These are internal variables. Should be static */
79
80 typedef struct SwigPtrType {
81 char *name;
82 int len;
83 void *(*cast)(void *);
84 struct SwigPtrType *next;
85 } SwigPtrType;
86
87 /* Pointer cache structure */
88
89 typedef struct {
90 int stat; /* Status (valid) bit */
91 SwigPtrType *tp; /* Pointer to type structure */
92 char name[256]; /* Given datatype name */
93 char mapped[256]; /* Equivalent name */
94 } SwigCacheType;
95
96 static int SwigPtrMax = 64; /* Max entries that can be currently held */
97 static int SwigPtrN = 0; /* Current number of entries */
98 static int SwigPtrSort = 0; /* Status flag indicating sort */
99 static SwigPtrType *SwigPtrTable = 0; /* Table containing pointer equivalences */
100 static int SwigStart[256]; /* Table containing starting positions */
101
102 /* Cached values */
103
104 #define SWIG_CACHESIZE 8
105 #define SWIG_CACHEMASK 0x7
106 static SwigCacheType SwigCache[SWIG_CACHESIZE];
107 static int SwigCacheIndex = 0;
108 static int SwigLastCache = 0;
109
110 /* Sort comparison function */
111 static int swigsort(const void *data1, const void *data2) {
112 SwigPtrType *d1 = (SwigPtrType *) data1;
113 SwigPtrType *d2 = (SwigPtrType *) data2;
114 return strcmp(d1->name,d2->name);
115 }
116
117 /* Binary Search function */
118 static int swigcmp(const void *key, const void *data) {
119 char *k = (char *) key;
120 SwigPtrType *d = (SwigPtrType *) data;
121 return strncmp(k,d->name,d->len);
122 }
123
124 /* Register a new datatype with the type-checker */
125
126 #ifndef PERL_OBJECT
127 SWIGSTATICRUNTIME(void)
128 SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *)) {
129 #else
130 #define SWIG_RegisterMapping(a,b,c) _SWIG_RegisterMapping(pPerl, a,b,c)
131 SWIGSTATICRUNTIME(void)
132 _SWIG_RegisterMapping(CPerlObj *pPerl, char *origtype, char *newtype, void *(*cast)(void *)) {
133 #endif
134
135 int i;
136 SwigPtrType *t = 0, *t1;
137
138 if (!SwigPtrTable) {
139 SwigPtrTable = (SwigPtrType *) malloc(SwigPtrMax*sizeof(SwigPtrType));
140 SwigPtrN = 0;
141 }
142 if (SwigPtrN >= SwigPtrMax) {
143 SwigPtrMax = 2*SwigPtrMax;
144 SwigPtrTable = (SwigPtrType *) realloc(SwigPtrTable,SwigPtrMax*sizeof(SwigPtrType));
145 }
146 for (i = 0; i < SwigPtrN; i++)
147 if (strcmp(SwigPtrTable[i].name,origtype) == 0) {
148 t = &SwigPtrTable[i];
149 break;
150 }
151 if (!t) {
152 t = &SwigPtrTable[SwigPtrN];
153 t->name = origtype;
154 t->len = strlen(t->name);
155 t->cast = 0;
156 t->next = 0;
157 SwigPtrN++;
158 }
159 while (t->next) {
160 if (strcmp(t->name,newtype) == 0) {
161 if (cast) t->cast = cast;
162 return;
163 }
164 t = t->next;
165 }
166 t1 = (SwigPtrType *) malloc(sizeof(SwigPtrType));
167 t1->name = newtype;
168 t1->len = strlen(t1->name);
169 t1->cast = cast;
170 t1->next = 0;
171 t->next = t1;
172 SwigPtrSort = 0;
173 }
174
175 /* Make a pointer value string */
176
177 SWIGSTATICRUNTIME(void)
178 SWIG_MakePtr(char *_c, const void *_ptr, char *type) {
179 static char _hex[16] =
180 {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
181 'a', 'b', 'c', 'd', 'e', 'f'};
182 unsigned long _p, _s;
183 char _result[20], *_r; /* Note : a 64-bit hex number = 16 digits */
184 _r = _result;
185 _p = (unsigned long) _ptr;
186 if (_p > 0) {
187 while (_p > 0) {
188 _s = _p & 0xf;
189 *(_r++) = _hex[_s];
190 _p = _p >> 4;
191 }
192 *_r = '_';
193 while (_r >= _result)
194 *(_c++) = *(_r--);
195 } else {
196 strcpy (_c, "NULL");
197 }
198 if (_ptr)
199 strcpy (_c, type);
200 }
201
202 /* Function for getting a pointer value */
203
204 #ifndef PERL_OBJECT
205 SWIGSTATICRUNTIME(char *)
206 SWIG_GetPtr(SV *sv, void **ptr, char *_t)
207 #else
208 #define SWIG_GetPtr(a,b,c) _SWIG_GetPtr(pPerl,a,b,c)
209 SWIGSTATICRUNTIME(char *)
210 _SWIG_GetPtr(CPerlObj *pPerl, SV *sv, void **ptr, char *_t)
211 #endif
212 {
213 char temp_type[256];
214 char *name,*_c;
215 int len,i,start,end;
216 IV tmp;
217 SwigPtrType *sp,*tp;
218 SwigCacheType *cache;
219
220 /* If magical, apply more magic */
221
222 if (SvGMAGICAL(sv))
223 mg_get(sv);
224
225 /* Check to see if this is an object */
226 if (sv_isobject(sv)) {
227 SV *tsv = (SV*) SvRV(sv);
228 if ((SvTYPE(tsv) == SVt_PVHV)) {
229 MAGIC *mg;
230 if (SvMAGICAL(tsv)) {
231 mg = mg_find(tsv,'P');
232 if (mg) {
233 SV *rsv = mg->mg_obj;
234 if (sv_isobject(rsv)) {
235 tmp = SvIV((SV*)SvRV(rsv));
236 }
237 }
238 } else {
239 return "Not a valid pointer value";
240 }
241 } else {
242 tmp = SvIV((SV*)SvRV(sv));
243 }
244 if (!_t) {
245 *(ptr) = (void *) tmp;
246 return (char *) 0;
247 }
248 } else if (! SvOK(sv)) { /* Check for undef */
249 *(ptr) = (void *) 0;
250 return (char *) 0;
251 } else if (SvTYPE(sv) == SVt_RV) { /* Check for NULL pointer */
252 *(ptr) = (void *) 0;
253 if (!SvROK(sv))
254 return (char *) 0;
255 else
256 return "Not a valid pointer value";
257 } else { /* Don't know what it is */
258 *(ptr) = (void *) 0;
259 return "Not a valid pointer value";
260 }
261 if (_t) {
262 /* Now see if the types match */
263
264 if (!sv_isa(sv,_t)) {
265 _c = HvNAME(SvSTASH(SvRV(sv)));
266 if (!SwigPtrSort) {
267 qsort((void *) SwigPtrTable, SwigPtrN, sizeof(SwigPtrType), swigsort);
268 for (i = 0; i < 256; i++) {
269 SwigStart[i] = SwigPtrN;
270 }
271 for (i = SwigPtrN-1; i >= 0; i--) {
272 SwigStart[SwigPtrTable[i].name[0]] = i;
273 }
274 for (i = 255; i >= 1; i--) {
275 if (SwigStart[i-1] > SwigStart[i])
276 SwigStart[i-1] = SwigStart[i];
277 }
278 SwigPtrSort = 1;
279 for (i = 0; i < SWIG_CACHESIZE; i++)
280 SwigCache[i].stat = 0;
281 }
282 /* First check cache for matches. Uses last cache value as starting point */
283 cache = &SwigCache[SwigLastCache];
284 for (i = 0; i < SWIG_CACHESIZE; i++) {
285 if (cache->stat) {
286 if (strcmp(_t,cache->name) == 0) {
287 if (strcmp(_c,cache->mapped) == 0) {
288 cache->stat++;
289 *ptr = (void *) tmp;
290 if (cache->tp->cast) *ptr = (*(cache->tp->cast))(*ptr);
291 return (char *) 0;
292 }
293 }
294 }
295 SwigLastCache = (SwigLastCache+1) & SWIG_CACHEMASK;
296 if (!SwigLastCache) cache = SwigCache;
297 else cache++;
298 }
299
300 start = SwigStart[_t[0]];
301 end = SwigStart[_t[0]+1];
302 sp = &SwigPtrTable[start];
303 while (start < end) {
304 if (swigcmp(_t,sp) == 0) break;
305 sp++;
306 start++;
307 }
308 if (start > end) sp = 0;
309 while (start <= end) {
310 if (swigcmp(_t,sp) == 0) {
311 name = sp->name;
312 len = sp->len;
313 tp = sp->next;
314 while(tp) {
315 if (tp->len >= 255) {
316 return _c;
317 }
318 strcpy(temp_type,tp->name);
319 strncat(temp_type,_t+len,255-tp->len);
320 if (sv_isa(sv,temp_type)) {
321 /* Get pointer value */
322 *ptr = (void *) tmp;
323 if (tp->cast) *ptr = (*(tp->cast))(*ptr);
324
325 strcpy(SwigCache[SwigCacheIndex].mapped,_c);
326 strcpy(SwigCache[SwigCacheIndex].name,_t);
327 SwigCache[SwigCacheIndex].stat = 1;
328 SwigCache[SwigCacheIndex].tp = tp;
329 SwigCacheIndex = SwigCacheIndex & SWIG_CACHEMASK;
330 return (char *) 0;
331 }
332 tp = tp->next;
333 }
334 }
335 sp++;
336 start++;
337 }
338 /* Didn't find any sort of match for this data.
339 Get the pointer value and return the received type */
340 *ptr = (void *) tmp;
341 return _c;
342 } else {
343 /* Found a match on the first try. Return pointer value */
344 *ptr = (void *) tmp;
345 return (char *) 0;
346 }
347 }
348 *ptr = (void *) tmp;
349 return (char *) 0;
350 }
351
352 #endif
353 #ifdef __cplusplus
354 }
355 #endif
356
357
358
359
360
361