(SwigPtrType): Delete member `len' from this struct.

(SwigCacheType): Delete this struct and corresponding typedef.
(SwigStart): Delete this array.
(SWIG_CACHESIZE, SWIG_CACHEMASK): Delete these macros.
(SwigCache, SwigCacheIndex, SwigLastCache): Delete these
file-static vars.

(SWIG_RegisterMapping, SWIG_SortTable, SWIG_GetPtrType,
SWIG_Cast_Str, swigsort, swigcmp): No longer support
non-"with-smobs" handling.

(SWIG_MakePtr, SWIG_GetPtr): Delete these funcs.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@583 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Thien-Thi Nguyen 2000-07-20 19:46:09 +00:00
commit 7d7fb78130

View file

@ -10,62 +10,39 @@
struct SwigPtrType { struct SwigPtrType {
char *name; /* Datatype name */ char *name; /* Datatype name */
char *prettyname; /* Pretty datatype name */ char *prettyname; /* Pretty datatype name */
int len; /* Length (used for optimization) */
void *(*cast)(void *); /* Pointer casting function */ void *(*cast)(void *); /* Pointer casting function */
unsigned short tag; /* Index in SwigPtrTable */ unsigned short tag; /* Index in SwigPtrTable */
struct SwigPtrType *next; /* Linked list pointer */ struct SwigPtrType *next; /* Linked list pointer */
}; };
/* Pointer cache structure */
typedef struct {
int stat; /* Status (valid) bit */
SwigPtrType *tp; /* Pointer to type structure */
char name[256]; /* Given datatype name */
char mapped[256]; /* Equivalent name */
} SwigCacheType;
/* Some variables */ /* Some variables */
static int SwigPtrMax = 64; /* Max entries that can be currently held */ static int SwigPtrMax = 64; /* Max entries that can be held */
/* This value may be adjusted dynamically */ /* (may be adjusted dynamically) */
static int SwigPtrN = 0; /* Current number of entries */ static int SwigPtrN = 0; /* Current number of entries */
static int SwigPtrSort = 0; /* Status flag indicating sort */ static int SwigPtrSort = 0; /* Status flag indicating sort */
static int SwigStart[256]; /* Starting positions of types */
/* Pointer table */ /* Pointer table */
static SwigPtrType *SwigPtrList = 0; /* Table containing types and static SwigPtrType *SwigPtrList = 0; /* Table containing types and
equivalences; items will only be appended */ equivalences; items will only
static SwigPtrType **SwigPtrTbl = 0; /* Sorted indirect table; items will be appended */
static size_t *SwigPtrTbl = 0; /* Sorted indirect table; items will
be inserted */ be inserted */
/* Cached values */
#define SWIG_CACHESIZE 8
#define SWIG_CACHEMASK 0x7
static SwigCacheType SwigCache[SWIG_CACHESIZE];
static int SwigCacheIndex = 0;
static int SwigLastCache = 0;
/* Sort comparison function */ /* Sort comparison function */
static int swigsort(const void *data1, const void *data2) { static int
SwigPtrType **d1 = (SwigPtrType **) data1; swigsort (const void *data1, const void *data2)
SwigPtrType **d2 = (SwigPtrType **) data2; {
return strcmp((*d1)->name, (*d2)->name); size_t index1 = * (size_t *) data1;
} size_t index2 = * (size_t *) data2;
return strcmp(SwigPtrList[index1].name, SwigPtrList[index2].name);
/* Binary Search function */
static int swigcmp(const void *key, const void *data) {
char *k = (char *) key;
SwigPtrType **d = (SwigPtrType **) data;
return strcmp(k,(*d)->name);
} }
/* Register a new datatype with the type-checker */ /* Register a new datatype with the type-checker */
SWIGSTATIC SWIGSTATIC void
void SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *)) { SWIG_RegisterMapping (char *origtype, char *newtype, void *(*cast)(void *))
{
int i; int i;
SwigPtrType *t = 0,*t1; SwigPtrType *t = 0,*t1;
@ -73,7 +50,7 @@ void SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *))
if (!SwigPtrList) { if (!SwigPtrList) {
SwigPtrList = (SwigPtrType *) malloc(SwigPtrMax*sizeof(SwigPtrType)); SwigPtrList = (SwigPtrType *) malloc(SwigPtrMax*sizeof(SwigPtrType));
SwigPtrTbl = (SwigPtrType **) malloc(SwigPtrMax*sizeof(SwigPtrType *)); SwigPtrTbl = (size_t *) malloc(SwigPtrMax*sizeof(size_t));
SwigPtrN = 0; SwigPtrN = 0;
} }
/* Grow the table */ /* Grow the table */
@ -81,8 +58,8 @@ void SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *))
SwigPtrMax = 2*SwigPtrMax; SwigPtrMax = 2*SwigPtrMax;
SwigPtrList = (SwigPtrType *) realloc((char *) SwigPtrList, SwigPtrList = (SwigPtrType *) realloc((char *) SwigPtrList,
SwigPtrMax*sizeof(SwigPtrType)); SwigPtrMax*sizeof(SwigPtrType));
SwigPtrTbl = (SwigPtrType **) realloc((char *) SwigPtrList, SwigPtrTbl = (size_t *) realloc((char *) SwigPtrTbl,
SwigPtrMax*sizeof(SwigPtrType *)); SwigPtrMax*sizeof(size_t));
} }
for (i = 0; i < SwigPtrN; i++) for (i = 0; i < SwigPtrN; i++)
if (strcmp(SwigPtrList[i].name,origtype) == 0) { if (strcmp(SwigPtrList[i].name,origtype) == 0) {
@ -93,10 +70,10 @@ void SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *))
#if 0 #if 0
fprintf(stderr, "New type: %s\n", origtype); fprintf(stderr, "New type: %s\n", origtype);
#endif #endif
t = SwigPtrTbl[SwigPtrN] = &SwigPtrList[SwigPtrN]; SwigPtrTbl[SwigPtrN] = SwigPtrN;
t = &SwigPtrList[SwigPtrN];
t->name = origtype; t->name = origtype;
t->prettyname = NULL; t->prettyname = NULL;
t->len = strlen(t->name);
t->cast = 0; t->cast = 0;
t->next = 0; t->next = 0;
t->tag = SwigPtrN; t->tag = SwigPtrN;
@ -121,141 +98,70 @@ void SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *))
t1 = (SwigPtrType *) malloc(sizeof(SwigPtrType)); t1 = (SwigPtrType *) malloc(sizeof(SwigPtrType));
t1->name = newtype; t1->name = newtype;
t1->prettyname = NULL; t1->prettyname = NULL;
t1->len = strlen(t1->name);
t1->cast = cast; t1->cast = cast;
t1->next = 0; t1->next = 0;
t->next = t1; t->next = t1;
} }
} }
/* Make a pointer value string */ /* Sort table */
/* OBSOLESCENT */ static void
SWIGSTATIC SWIG_SortTable (void)
void SWIG_MakePtr(char *_c, const void *_ptr, char *type) {
static char _hex[16] =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'};
unsigned long _p, _s;
char _result[20], *_r; /* Note : a 64-bit hex number = 16 digits */
_r = _result;
_p = (unsigned long) _ptr;
if (_p > 0) {
while (_p > 0) {
_s = _p & 0xf;
*(_r++) = _hex[_s];
_p = _p >> 4;
}
*_r = '_';
while (_r >= _result)
*(_c++) = *(_r--);
} else {
strcpy (_c, "NULL");
}
if (_ptr)
strcpy (_c, type);
}
/* Sort table and make cache invalid */
static
void SWIG_SortTable()
{ {
int i; int i;
qsort((void *) SwigPtrTbl, SwigPtrN, sizeof(SwigPtrType *), swigsort); qsort ((void *) SwigPtrTbl, SwigPtrN, sizeof(size_t), swigsort);
for (i = 0; i < 256; i++) {
SwigStart[i] = SwigPtrN;
}
for (i = SwigPtrN-1; i >= 0; i--) {
SwigStart[(int) (SwigPtrTbl[i]->name[1])] = i;
}
for (i = 255; i >= 1; i--) {
if (SwigStart[i-1] > SwigStart[i])
SwigStart[i-1] = SwigStart[i];
}
/* Invalidate cache */
for (i = 0; i < SWIG_CACHESIZE; i++)
SwigCache[i].stat = 0;
/* Indicate that everything is sorted */ /* Indicate that everything is sorted */
SwigPtrSort = 1; SwigPtrSort = 1;
} }
/* Look up pointer-type entry in table */ /* Look up pointer-type entry in table */
static static int
SwigPtrType *SWIG_GetPtrType(char *_t) swigcmp (const void *key, const void *data)
{
char *k = (char *) key;
size_t index = *(size_t *)data;
return strcmp(k, SwigPtrList[index].name);
}
static SwigPtrType *
SWIG_GetPtrType (const char *_t)
{ {
int start, end; int start, end;
SwigPtrType **sp; size_t *result;
if (!SwigPtrSort) SWIG_SortTable(); if (!SwigPtrSort) SWIG_SortTable();
start = SwigStart[(int) _t[1]]; result = bsearch(_t, SwigPtrTbl, SwigPtrN, sizeof(size_t), swigcmp);
end = SwigStart[(int) _t[1]+1]; if (result!=NULL) return SwigPtrList+*result;
sp = &SwigPtrTbl[start]; else return NULL;
/* This can be improved by using binary search instead of linear search. */
while (start < end) {
if (swigcmp(_t,sp) == 0) return *sp;
sp++;
start++;
}
return NULL;
} }
/* Cast a pointer if possible */ /* Cast a pointer if possible */
static static char *
char *SWIG_Cast_Str(void *source, char *source_type, void **ptr, char *_t) SWIG_Cast_Str (void *source, char *source_type, void **ptr, char *_t)
{ {
char temp_type[256]; char temp_type[256];
char *name; char *name;
int i, len; int i, len;
SwigPtrType *sp,*tp; SwigPtrType *sp,*tp;
SwigCacheType *cache;
int start, end; int start, end;
if (_t) { if (_t) {
if (strcmp(_t,source_type)) { if (strcmp(_t,source_type)) {
if (!SwigPtrSort) SWIG_SortTable(); if (!SwigPtrSort) SWIG_SortTable();
/* First check cache for matches. Uses last cache value as starting point */
cache = &SwigCache[SwigLastCache];
for (i = 0; i < SWIG_CACHESIZE; i++) {
if (cache->stat) {
if (strcmp(_t,cache->name) == 0) {
if (strcmp(source_type,cache->mapped) == 0) {
cache->stat++;
*ptr = source;
if (cache->tp->cast) *ptr = (*(cache->tp->cast))(*ptr);
return (char *) 0;
}
}
}
SwigLastCache = (SwigLastCache+1) & SWIG_CACHEMASK;
if (!SwigLastCache) cache = SwigCache;
else cache++;
}
/* We have a type mismatch. Will have to look through our type /* We have a type mismatch. Will have to look through our type
mapping table to figure out whether or not we can accept this datatype */ mapping table to figure out whether or not we can accept this
datatype. */
sp = SWIG_GetPtrType(_t); sp = SWIG_GetPtrType(_t);
if (sp!=NULL) { if (sp!=NULL) {
name = sp->name; name = sp->name;
len = sp->len;
tp = sp->next; tp = sp->next;
/* Try to find entry for our given datatype */ /* Try to find entry for our given datatype. */
while(tp) { while(tp) {
/* I don't understand this code */ if (strcmp(source_type, tp->name) == 0) {
if (tp->len >= 255) { /* Get pointer value. */
return source_type;
}
strcpy(temp_type,tp->name);
strncat(temp_type,_t+len,255-tp->len);
if (strcmp(source_type,temp_type) == 0) {
strcpy(SwigCache[SwigCacheIndex].mapped,source_type);
strcpy(SwigCache[SwigCacheIndex].name,_t);
SwigCache[SwigCacheIndex].stat = 1;
SwigCache[SwigCacheIndex].tp = tp;
SwigCacheIndex = SwigCacheIndex & SWIG_CACHEMASK;
/* Get pointer value */
*ptr = source; *ptr = source;
if (tp->cast) *ptr = (*(tp->cast))(*ptr); if (tp->cast) *ptr = (*(tp->cast))(*ptr);
return (char *) 0; return (char *) 0;
@ -264,16 +170,16 @@ char *SWIG_Cast_Str(void *source, char *source_type, void **ptr, char *_t)
} }
} }
/* Didn't find any sort of match for this data. /* Didn't find any sort of match for this data.
Get the pointer value and return the received type */ Get the pointer value and return the received type. */
*ptr = source; *ptr = source;
return source_type; return source_type;
} else { } else {
/* Found a match on the first try. Return pointer value */ /* Found a match on the first try. Return pointer value. */
*ptr = source; *ptr = source;
return (char *) 0; return (char *) 0;
} }
} else { } else {
/* No type specified. Good luck */ /* No type specified. Good luck! */
*ptr = source; *ptr = source;
return (char *) 0; return (char *) 0;
} }
@ -281,41 +187,10 @@ char *SWIG_Cast_Str(void *source, char *source_type, void **ptr, char *_t)
/* Function for getting a pointer value */ /* Function for getting a pointer value */
/* OBSOLESCENT */
SWIGSTATIC
char *SWIG_GetPtr(char *_c, void **ptr, char *_t)
{
unsigned long _p;
_p = 0;
/* Pointer values must start with leading underscore */
if (*_c == '_') {
_c++;
/* Extract hex value from pointer */
while (*_c) {
if ((*_c >= '0') && (*_c <= '9'))
_p = (_p << 4) + (*_c - '0');
else if ((*_c >= 'a') && (*_c <= 'f'))
_p = (_p << 4) + ((*_c - 'a') + 10);
else
break;
_c++;
}
return SWIG_Cast_Str((void *)_p, _c, ptr, _t);
} else {
if (strcmp (_c, "NULL") == 0) {
*ptr = (void *) 0;
return (char *) 0;
}
*ptr = (void *) 0;
return _c;
}
}
static unsigned long swig_tag = 0; static unsigned long swig_tag = 0;
SWIGSTATIC SWIGSTATIC SCM
SCM SWIG_Guile_MakePtr(void *ptr, SwigPtrType *type) SWIG_Guile_MakePtr (void *ptr, SwigPtrType *type)
{ {
if (ptr==NULL) return SCM_EOL; if (ptr==NULL) return SCM_EOL;
SCM_RETURN_NEWSMOB((((unsigned long)type->tag << 16) | swig_tag), SCM_RETURN_NEWSMOB((((unsigned long)type->tag << 16) | swig_tag),
@ -323,8 +198,8 @@ SCM SWIG_Guile_MakePtr(void *ptr, SwigPtrType *type)
} }
/* TRANSITIONAL */ /* TRANSITIONAL */
SWIGSTATIC SWIGSTATIC SCM
SCM SWIG_Guile_MakePtr_Str(void *ptr, char *typestring, char *prettytypestring) SWIG_Guile_MakePtr_Str (void *ptr, char *typestring, char *prettytypestring)
{ {
SwigPtrType *type = SWIG_GetPtrType(typestring); SwigPtrType *type = SWIG_GetPtrType(typestring);
if (type == NULL) { if (type == NULL) {
@ -340,8 +215,8 @@ SCM SWIG_Guile_MakePtr_Str(void *ptr, char *typestring, char *prettytypestring)
} }
/* TRANSITIONAL */ /* TRANSITIONAL */
SWIGSTATIC SWIGSTATIC int
int SWIG_Guile_GetPtr_Str(SCM s, void **result, char *typestring) SWIG_Guile_GetPtr_Str (SCM s, void **result, char *typestring)
{ {
if (SCM_NULLP(s)) { if (SCM_NULLP(s)) {
*result = NULL; *result = NULL;
@ -358,16 +233,16 @@ int SWIG_Guile_GetPtr_Str(SCM s, void **result, char *typestring)
} }
/* Return 0 if successful. */ /* Return 0 if successful. */
SWIGSTATIC SWIGSTATIC int
int SWIG_Guile_GetPtr(SCM s, void **result, SwigPtrType *type) SWIG_Guile_GetPtr(SCM s, void **result, SwigPtrType *type)
{ {
return SWIG_Guile_GetPtr_Str(s, result, type->name); return SWIG_Guile_GetPtr_Str(s, result, type->name);
} }
/* Init */ /* Init */
static static int
int print_swig(SCM swig_smob, SCM port, scm_print_state *pstate) print_swig (SCM swig_smob, SCM port, scm_print_state *pstate)
{ {
char buf[16]; char buf[16];
scm_puts("#<swig ", port); scm_puts("#<swig ", port);
@ -380,8 +255,8 @@ int print_swig(SCM swig_smob, SCM port, scm_print_state *pstate)
return 1; return 1;
} }
static static SCM
SCM equalp_swig(SCM A, SCM B) equalp_swig (SCM A, SCM B)
{ {
if (SCM_CAR(A) == SCM_CAR(B) if (SCM_CAR(A) == SCM_CAR(B)
&& SCM_CDR(A) == SCM_CDR(B)) && SCM_CDR(A) == SCM_CDR(B))
@ -389,8 +264,8 @@ SCM equalp_swig(SCM A, SCM B)
else return SCM_BOOL_F; else return SCM_BOOL_F;
} }
SWIGSTATIC SWIGSTATIC void
void SWIG_Guile_Init() SWIG_Guile_Init (void)
{ {
if (swig_tag == 0) { if (swig_tag == 0) {
swig_tag = scm_make_smob_type_mfpe("swig", 0, NULL, NULL, swig_tag = scm_make_smob_type_mfpe("swig", 0, NULL, NULL,