]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxSWIG/Runtime/libperl.c
   4 /* Definitions for compiling Perl extensions on a variety of machines */ 
   6 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) 
   8 #       define SWIGEXPORT(a) __declspec(dllexport) a 
  10 #       if defined(__BORLANDC__) 
  11 #           define SWIGEXPORT(a) a _export  
  13 #           define SWIGEXPORT(a) a  
  17 #   define SWIGEXPORT(a) a  
  21 #define MAGIC_PPERL  CPerlObj *pPerl = (CPerlObj *) this; 
  22 #define MAGIC_CAST   (int (CPerlObj::*)(SV *, MAGIC *)) 
  23 #define SWIGCLASS_STATIC  
  27 #define SWIGCLASS_STATIC static 
  30 #if defined(WIN32) && defined(PERL_OBJECT) && !defined(PerlIO_exportFILE) 
  31 #define PerlIO_exportFILE(fh,fl) (FILE*)(fh) 
  34 /* Modifications for newer Perl 5.005 releases */ 
  36 #if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50)))) 
  38 #define PL_sv_yes sv_yes 
  41 #define PL_sv_undef sv_undef 
  48 /****************************************************************************** 
  49  * Pointer type-checking code 
  50  *****************************************************************************/ 
  59 extern void SWIG_MakePtr(char *, void *, char *); 
  61 extern void SWIG_RegisterMapping(char *, char *, void *(*)(void *)); 
  63 #define SWIG_RegisterMapping(a,b,c) _SWIG_RegisterMapping(pPerl,a,b,c); 
  64 extern void _SWIG_RegisterMapping(CPerlObj 
*,char *, char *, void *(*)(void *),int); 
  67 extern char *SWIG_GetPtr(SV 
*, void **, char *); 
  69 extern char *_SWIG_GetPtr(CPerlObj 
*, SV 
*, void **, char *); 
  70 #define SWIG_GetPtr(a,b,c) _SWIG_GetPtr(pPerl,a,b,c) 
  76 #define SWIGSTATICRUNTIME(a) SWIGEXPORT(a) 
  78 #define SWIGSTATICRUNTIME(a) static a 
  81 /* These are internal variables.   Should be static */ 
  83 typedef struct SwigPtrType 
{ 
  86   void               *(*cast
)(void *); 
  87   struct SwigPtrType 
*next
; 
  90 /* Pointer cache structure */ 
  93   int                 stat
;               /* Status (valid) bit             */ 
  94   SwigPtrType        
*tp
;                 /* Pointer to type structure      */ 
  95   char                name
[256];          /* Given datatype name            */ 
  96   char                mapped
[256];        /* Equivalent name                */ 
  99 static int SwigPtrMax  
= 64;           /* Max entries that can be currently held */ 
 100 static int SwigPtrN    
= 0;            /* Current number of entries              */ 
 101 static int SwigPtrSort 
= 0;            /* Status flag indicating sort            */ 
 102 static SwigPtrType 
*SwigPtrTable 
= 0;  /* Table containing pointer equivalences  */ 
 103 static int SwigStart
[256];             /* Table containing starting positions    */ 
 107 #define SWIG_CACHESIZE  8 
 108 #define SWIG_CACHEMASK  0x7 
 109 static SwigCacheType SwigCache
[SWIG_CACHESIZE
];   
 110 static int SwigCacheIndex 
= 0; 
 111 static int SwigLastCache 
= 0; 
 113 /* Sort comparison function */ 
 114 static int swigsort(const void *data1
, const void *data2
) { 
 115         SwigPtrType 
*d1 
= (SwigPtrType 
*) data1
; 
 116         SwigPtrType 
*d2 
= (SwigPtrType 
*) data2
; 
 117         return strcmp(d1
->name
,d2
->name
); 
 120 /* Binary Search function */ 
 121 static int swigcmp(const void *key
, const void *data
) { 
 122   char *k 
= (char *) key
; 
 123   SwigPtrType 
*d 
= (SwigPtrType 
*) data
; 
 124   return strncmp(k
,d
->name
,d
->len
); 
 127 /* Register a new datatype with the type-checker */ 
 130 SWIGSTATICRUNTIME(void)  
 131 SWIG_RegisterMapping(char *origtype
, char *newtype
, void *(*cast
)(void *)) { 
 133 #define SWIG_RegisterMapping(a,b,c) _SWIG_RegisterMapping(pPerl, a,b,c) 
 134 SWIGSTATICRUNTIME(void) 
 135 _SWIG_RegisterMapping(CPerlObj 
*pPerl
, char *origtype
, char *newtype
, void *(*cast
)(void *)) { 
 139   SwigPtrType 
*t 
= 0, *t1
; 
 142     SwigPtrTable 
= (SwigPtrType 
*) malloc(SwigPtrMax
*sizeof(SwigPtrType
)); 
 145   if (SwigPtrN 
>= SwigPtrMax
) { 
 146     SwigPtrMax 
= 2*SwigPtrMax
; 
 147     SwigPtrTable 
= (SwigPtrType 
*) realloc(SwigPtrTable
,SwigPtrMax
*sizeof(SwigPtrType
)); 
 149   for (i 
= 0; i 
< SwigPtrN
; i
++) 
 150     if (strcmp(SwigPtrTable
[i
].name
,origtype
) == 0) { 
 151       t 
= &SwigPtrTable
[i
]; 
 155     t 
= &SwigPtrTable
[SwigPtrN
]; 
 157     t
->len 
= strlen(t
->name
); 
 163     if (strcmp(t
->name
,newtype
) == 0) { 
 164       if (cast
) t
->cast 
= cast
; 
 169   t1 
= (SwigPtrType 
*) malloc(sizeof(SwigPtrType
)); 
 171   t1
->len 
= strlen(t1
->name
); 
 178 /* Make a pointer value string */ 
 180 SWIGSTATICRUNTIME(void)  
 181 SWIG_MakePtr(char *_c
, const void *_ptr
, char *type
) { 
 182   static char _hex
[16] = 
 183   {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 
 184    'a', 'b', 'c', 'd', 'e', 'f'}; 
 185   unsigned long _p
, _s
; 
 186   char _result
[20], *_r
;    /* Note : a 64-bit hex number = 16 digits */ 
 188   _p 
= (unsigned long) _ptr
; 
 196     while (_r 
>= _result
) 
 205 /* Function for getting a pointer value */ 
 208 SWIGSTATICRUNTIME(char *)  
 209 SWIG_GetPtr(SV 
*sv
, void **ptr
, char *_t
) 
 211 #define SWIG_GetPtr(a,b,c) _SWIG_GetPtr(pPerl,a,b,c) 
 212 SWIGSTATICRUNTIME(char *) 
 213 _SWIG_GetPtr(CPerlObj 
*pPerl
, SV 
*sv
, void **ptr
, char *_t
) 
 221   SwigCacheType 
*cache
; 
 223   /* If magical, apply more magic */ 
 228   /* Check to see if this is an object */ 
 229   if (sv_isobject(sv
)) { 
 230     SV 
*tsv 
= (SV
*) SvRV(sv
); 
 231     if ((SvTYPE(tsv
) == SVt_PVHV
)) { 
 233       if (SvMAGICAL(tsv
)) { 
 234         mg 
= mg_find(tsv
,'P'); 
 236           SV 
*rsv 
= mg
->mg_obj
; 
 237           if (sv_isobject(rsv
)) { 
 238             tmp 
= SvIV((SV
*)SvRV(rsv
)); 
 242         return "Not a valid pointer value"; 
 245       tmp 
= SvIV((SV
*)SvRV(sv
)); 
 248       *(ptr
) = (void *) tmp
; 
 251   } else if (! SvOK(sv
)) {            /* Check for undef */ 
 254   } else if (SvTYPE(sv
) == SVt_RV
) {       /* Check for NULL pointer */ 
 259       return "Not a valid pointer value"; 
 260   } else {                                 /* Don't know what it is */ 
 262       return "Not a valid pointer value"; 
 265     /* Now see if the types match */       
 267     if (!sv_isa(sv
,_t
)) { 
 268       _c 
= HvNAME(SvSTASH(SvRV(sv
))); 
 270         qsort((void *) SwigPtrTable
, SwigPtrN
, sizeof(SwigPtrType
), swigsort
);   
 271         for (i 
= 0; i 
< 256; i
++) { 
 272           SwigStart
[i
] = SwigPtrN
; 
 274         for (i 
= SwigPtrN
-1; i 
>= 0; i
--) { 
 275           SwigStart
[SwigPtrTable
[i
].name
[0]] = i
; 
 277         for (i 
= 255; i 
>= 1; i
--) { 
 278           if (SwigStart
[i
-1] > SwigStart
[i
]) 
 279             SwigStart
[i
-1] = SwigStart
[i
]; 
 282         for (i 
= 0; i 
< SWIG_CACHESIZE
; i
++)   
 283           SwigCache
[i
].stat 
= 0; 
 285       /* First check cache for matches.  Uses last cache value as starting point */ 
 286       cache 
= &SwigCache
[SwigLastCache
]; 
 287       for (i 
= 0; i 
< SWIG_CACHESIZE
; i
++) { 
 289           if (strcmp(_t
,cache
->name
) == 0) { 
 290             if (strcmp(_c
,cache
->mapped
) == 0) { 
 293               if (cache
->tp
->cast
) *ptr 
= (*(cache
->tp
->cast
))(*ptr
); 
 298         SwigLastCache 
= (SwigLastCache
+1) & SWIG_CACHEMASK
; 
 299         if (!SwigLastCache
) cache 
= SwigCache
; 
 303       start 
= SwigStart
[_t
[0]]; 
 304       end 
= SwigStart
[_t
[0]+1]; 
 305       sp 
= &SwigPtrTable
[start
]; 
 306       while (start 
< end
) { 
 307         if (swigcmp(_t
,sp
) == 0) break; 
 311       if (start 
> end
) sp 
= 0; 
 312       while (start 
<= end
) { 
 313         if (swigcmp(_t
,sp
) == 0) { 
 318             if (tp
->len 
>= 255) { 
 321             strcpy(temp_type
,tp
->name
); 
 322             strncat(temp_type
,_t
+len
,255-tp
->len
); 
 323             if (sv_isa(sv
,temp_type
)) { 
 324               /* Get pointer value */ 
 326               if (tp
->cast
) *ptr 
= (*(tp
->cast
))(*ptr
); 
 328               strcpy(SwigCache
[SwigCacheIndex
].mapped
,_c
); 
 329               strcpy(SwigCache
[SwigCacheIndex
].name
,_t
); 
 330               SwigCache
[SwigCacheIndex
].stat 
= 1; 
 331               SwigCache
[SwigCacheIndex
].tp 
= tp
; 
 332               SwigCacheIndex 
= SwigCacheIndex 
& SWIG_CACHEMASK
; 
 341       /* Didn't find any sort of match for this data.   
 342          Get the pointer value and return the received type */ 
 346       /* Found a match on the first try.  Return pointer value */