3
/* SWIG pointer structure */
10
struct SwigPtrType *type; /* Type in SwigPtrTbl */
11
void *(*cast)(void *); /* Pointer casting function */
12
struct SwigCast *next; /* Linked list pointer */
16
const char *name; /* Datatype name */
17
const char *prettyname; /* Pretty datatype name */
18
struct SwigCast *cast; /* List of compatible types */
28
static SwigPtrType **SwigPtrTbl = 0; /* Sorted table */
29
static int SwigPtrMax = 64; /* Max entries that can be held */
30
/* (may be adjusted dynamically) */
31
static int SwigPtrN = 0; /* Current number of entries */
32
static int SwigPtrSort = 0; /* Status flag indicating sort */
34
/* Sort comparison function */
36
swigsort (const void *data1, const void *data2)
38
SwigPtrType *type1 = * (SwigPtrType **) data1;
39
SwigPtrType *type2 = * (SwigPtrType **) data2;
40
return strcmp(type1->name, type2->name);
43
/* Register a new datatype with the type-checker */
44
SWIGSTATIC SwigPtrType *
45
SWIG_RegisterType (const char *type, const char *prettyname)
48
struct SwigPtrType **t;
50
/* Allocate the pointer table if necessary */
52
SwigPtrTbl = (SwigPtrType **) malloc(SwigPtrMax*sizeof(SwigPtrType *));
55
/* Grow the table if necessary */
56
if (SwigPtrN >= SwigPtrMax) {
57
SwigPtrMax = 2*SwigPtrMax;
58
SwigPtrTbl = (SwigPtrType **) realloc((char *) SwigPtrTbl,
59
SwigPtrMax*sizeof(SwigPtrType *));
62
for (i = 0; i < SwigPtrN; i++)
63
if (strcmp(SwigPtrTbl[i]->name,type) == 0) {
65
SwigPtrTbl[i]->prettyname = prettyname;
68
t = SwigPtrTbl + SwigPtrN;
69
*t = (SwigPtrType *) malloc(sizeof(SwigPtrType));
71
(*t)->prettyname = prettyname;
78
/* Register two data types and their mapping with the type checker. */
80
SWIG_RegisterMapping (const char *origtype, const char *newtype, void *(*cast)(void *))
82
struct SwigPtrType *t = SWIG_RegisterType(origtype, NULL);
85
struct SwigPtrType *t1 = SWIG_RegisterType(newtype, NULL);
87
/* Check for existing cast */
88
for (c = t->cast; c && c->type!=t1; c=c->next) /* nothing */;
90
if (cast) c->cast = cast;
93
c = (struct SwigCast *) malloc(sizeof(struct SwigCast));
105
SWIG_SortTable (void)
107
qsort ((void *) SwigPtrTbl, SwigPtrN, sizeof(struct SwigPtrTbl *), swigsort);
108
/* Indicate that everything is sorted */
112
/* Look up pointer-type entry in table */
115
swigcmp (const void *key, const void *data)
117
char *k = (char *) key;
118
SwigPtrType *t = *(SwigPtrType **) data;
119
return strcmp(k, t->name);
123
SWIG_GetPtrType (const char *_t)
125
SwigPtrType **result;
126
if (!SwigPtrSort) SWIG_SortTable();
127
result = (SwigPtrType **) bsearch(_t, SwigPtrTbl, SwigPtrN,
128
sizeof(SwigPtrType *), swigcmp);
129
if (result!=NULL) return *result;
133
/* Cast a pointer if possible; returns 1 if successful */
136
SWIG_Cast (void *source, SwigPtrType *source_type,
137
void **ptr, SwigPtrType *dest_type)
139
if (dest_type != source_type) {
140
/* We have a type mismatch. Will have to look through our type
141
mapping table to figure out whether or not we can accept this
144
for (c = dest_type->cast;
145
c && c->type!=source_type; c = c->next) /* nothing */;
147
/* Get pointer value. */
148
if (c->cast) *ptr = (*(c->cast))(source);
152
/* Didn't find any sort of match for this data.
153
Get the pointer value and return false. */
157
/* Found a match on the first try. Return pointer value. */
163
/* Function for getting a pointer value */
165
static Scheme_Type swig_type;
166
int swig_initialized_p = 0;
168
SWIGSTATIC Scheme_Object *
169
SWIG_MakePtr(void *c_pointer, swig_type_info *type) {
170
struct swig_proxy *new_proxy;
171
new_proxy = (struct swig_proxy *) scheme_malloc(sizeof(struct swig_proxy));
172
new_proxy->type = swig_type;
173
new_proxy->ptrtype = type->ptrtype;
174
new_proxy->object = (void *) c_pointer;
175
return (Scheme_Object *) new_proxy;
178
/* Return 0 if successful. */
180
SWIG_GetPtr(Scheme_Object *s, void **result, swig_type_info *type)
182
if (SCHEME_NULLP(s)) {
186
else if (SCHEME_TYPE(s) == swig_type) {
187
struct swig_proxy *proxy = (struct swig_proxy *) s;
189
return !SWIG_Cast(proxy->object, proxy->ptrtype,
190
result, type->ptrtype);
193
*result = proxy->object;
201
SWIG_MustGetPtr_ (Scheme_Object *s, swig_type_info *type,
202
int argnum, const char *func_name,
203
int argc, Scheme_Object **argv)
206
if (SWIG_GetPtr(s, &result, type) != 0) {
208
scheme_wrong_type(func_name, type->str, argnum, argc, argv);
214
void SWIG_RegisterTypes(swig_type_info **table,
215
swig_type_info **init)
217
if (!swig_initialized_p) {
218
swig_type = scheme_make_type((char *) "swig");
219
swig_initialized_p = 1;
221
for (; *init; table++, init++) {
222
swig_type_info *type = *table = *init;
223
const char *origname = type->name;
224
/* Register datatype itself and store pointer back */
225
type->ptrtype = SWIG_RegisterType(origname, type->str);
226
/* Register compatible types */
227
for (type++; type->name; type++)
228
SWIG_RegisterMapping(origname, type->name, type->converter);
232
static Scheme_Object *
233
swig_package_values(int num, Scheme_Object **values)
235
/* ignore first value if void */
236
if (num > 0 && SCHEME_VOIDP(values[0]))
238
if (num == 0) return scheme_void;
239
else if (num == 1) return values[0];
240
else return scheme_values(num, values);
244
swig_malloc(size_t size, const char *func_name)
246
void *p = malloc(size);
248
scheme_signal_error("swig-memory-error");