1 /* Definitions for compiling Perl extensions on a variety of machines */
 
   3 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
 
   5 #       define SWIGEXPORT(a) __declspec(dllexport) a
 
   7 #       if defined(__BORLANDC__)
 
   8 #           define SWIGEXPORT(a) a _export 
 
  10 #           define SWIGEXPORT(a) a 
 
  14 #   define SWIGEXPORT(a) a 
 
  18 #define MAGIC_PPERL  CPerlObj *pPerl = (CPerlObj *) this;
 
  19 #define MAGIC_CAST   (int (CPerlObj::*)(SV *, MAGIC *))
 
  20 #define SWIGCLASS_STATIC 
 
  24 #define SWIGCLASS_STATIC static
 
  27 #if defined(WIN32) && defined(PERL_OBJECT) && !defined(PerlIO_exportFILE)
 
  28 #define PerlIO_exportFILE(fh,fl) (FILE*)(fh)
 
  31 /* Modifications for newer Perl 5.005 releases */
 
  33 #if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50))))
 
  35 #define PL_sv_yes sv_yes
 
  38 #define PL_sv_undef sv_undef
 
  45 /******************************************************************************
 
  46  * Pointer type-checking code
 
  47  *****************************************************************************/
 
  56 extern void SWIG_MakePtr(char *, void *, char *);
 
  58 extern void SWIG_RegisterMapping(char *, char *, void *(*)(void *));
 
  60 #define SWIG_RegisterMapping(a,b,c) _SWIG_RegisterMapping(pPerl,a,b,c);
 
  61 extern void _SWIG_RegisterMapping(CPerlObj *,char *, char *, void *(*)(void *),int);
 
  64 extern char *SWIG_GetPtr(SV *, void **, char *);
 
  66 extern char *_SWIG_GetPtr(CPerlObj *, SV *, void **, char *);
 
  67 #define SWIG_GetPtr(a,b,c) _SWIG_GetPtr(pPerl,a,b,c)
 
  73 #define SWIGSTATICRUNTIME(a) SWIGEXPORT(a)
 
  75 #define SWIGSTATICRUNTIME(a) static a
 
  78 /* These are internal variables.   Should be static */
 
  80 typedef struct SwigPtrType {
 
  83   void               *(*cast)(void *);
 
  84   struct SwigPtrType *next;
 
  87 /* Pointer cache structure */
 
  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                */
 
  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    */
 
 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;
 
 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);
 
 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);
 
 124 /* Register a new datatype with the type-checker */
 
 127 SWIGSTATICRUNTIME(void) 
 
 128 SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *)) {
 
 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 *)) {
 
 136   SwigPtrType *t = 0, *t1;
 
 139     SwigPtrTable = (SwigPtrType *) malloc(SwigPtrMax*sizeof(SwigPtrType));
 
 142   if (SwigPtrN >= SwigPtrMax) {
 
 143     SwigPtrMax = 2*SwigPtrMax;
 
 144     SwigPtrTable = (SwigPtrType *) realloc(SwigPtrTable,SwigPtrMax*sizeof(SwigPtrType));
 
 146   for (i = 0; i < SwigPtrN; i++)
 
 147     if (strcmp(SwigPtrTable[i].name,origtype) == 0) {
 
 148       t = &SwigPtrTable[i];
 
 152     t = &SwigPtrTable[SwigPtrN];
 
 154     t->len = strlen(t->name);
 
 160     if (strcmp(t->name,newtype) == 0) {
 
 161       if (cast) t->cast = cast;
 
 166   t1 = (SwigPtrType *) malloc(sizeof(SwigPtrType));
 
 168   t1->len = strlen(t1->name);
 
 175 /* Make a pointer value string */
 
 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 */
 
 185   _p = (unsigned long) _ptr;
 
 193     while (_r >= _result)
 
 202 /* Function for getting a pointer value */
 
 205 SWIGSTATICRUNTIME(char *) 
 
 206 SWIG_GetPtr(SV *sv, void **ptr, char *_t)
 
 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)
 
 218   SwigCacheType *cache;
 
 220   /* If magical, apply more magic */
 
 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)) {
 
 230       if (SvMAGICAL(tsv)) {
 
 231         mg = mg_find(tsv,'P');
 
 233           SV *rsv = mg->mg_obj;
 
 234           if (sv_isobject(rsv)) {
 
 235             tmp = SvIV((SV*)SvRV(rsv));
 
 239         return "Not a valid pointer value";
 
 242       tmp = SvIV((SV*)SvRV(sv));
 
 245       *(ptr) = (void *) tmp;
 
 248   } else if (! SvOK(sv)) {            /* Check for undef */
 
 251   } else if (SvTYPE(sv) == SVt_RV) {       /* Check for NULL pointer */
 
 256       return "Not a valid pointer value";
 
 257   } else {                                 /* Don't know what it is */
 
 259       return "Not a valid pointer value";
 
 262     /* Now see if the types match */      
 
 264     if (!sv_isa(sv,_t)) {
 
 265       _c = HvNAME(SvSTASH(SvRV(sv)));
 
 267         qsort((void *) SwigPtrTable, SwigPtrN, sizeof(SwigPtrType), swigsort);  
 
 268         for (i = 0; i < 256; i++) {
 
 269           SwigStart[i] = SwigPtrN;
 
 271         for (i = SwigPtrN-1; i >= 0; i--) {
 
 272           SwigStart[SwigPtrTable[i].name[0]] = i;
 
 274         for (i = 255; i >= 1; i--) {
 
 275           if (SwigStart[i-1] > SwigStart[i])
 
 276             SwigStart[i-1] = SwigStart[i];
 
 279         for (i = 0; i < SWIG_CACHESIZE; i++)  
 
 280           SwigCache[i].stat = 0;
 
 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++) {
 
 286           if (strcmp(_t,cache->name) == 0) {
 
 287             if (strcmp(_c,cache->mapped) == 0) {
 
 290               if (cache->tp->cast) *ptr = (*(cache->tp->cast))(*ptr);
 
 295         SwigLastCache = (SwigLastCache+1) & SWIG_CACHEMASK;
 
 296         if (!SwigLastCache) cache = SwigCache;
 
 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;
 
 308       if (start > end) sp = 0;
 
 309       while (start <= end) {
 
 310         if (swigcmp(_t,sp) == 0) {
 
 315             if (tp->len >= 255) {
 
 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 */
 
 323               if (tp->cast) *ptr = (*(tp->cast))(*ptr);
 
 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;
 
 338       /* Didn't find any sort of match for this data.  
 
 339          Get the pointer value and return the received type */
 
 343       /* Found a match on the first try.  Return pointer value */