1 /***********************************************************************
3 * swig_lib/python/python.cfg
5 * Contains variable linking and pointer type-checking code.
6 ************************************************************************/
13 /* Definitions for Windows/Unix exporting */
14 #if defined(_WIN32) || defined(__WIN32__)
15 # if defined(_MSC_VER)
16 # define SWIGEXPORT(a) __declspec(dllexport) a
18 # if defined(__BORLANDC__)
19 # define SWIGEXPORT(a) a _export
21 # define SWIGEXPORT(a) a
25 # define SWIGEXPORT(a) a
29 #define SWIGSTATICRUNTIME(a) SWIGEXPORT(a)
31 #define SWIGSTATICRUNTIME(a) static a
36 PyObject
*(*get_attr
)(void);
37 int (*set_attr
)(PyObject
*);
40 typedef struct swig_varlinkobject
{
42 swig_globalvar
**vars
;
47 /* ----------------------------------------------------------------------
50 Function for python repr method
51 ---------------------------------------------------------------------- */
54 swig_varlink_repr(swig_varlinkobject
*v
)
57 return PyString_FromString("<Global variables>");
60 /* ---------------------------------------------------------------------
63 Print out all of the global variable names
64 --------------------------------------------------------------------- */
67 swig_varlink_print(swig_varlinkobject
*v
, FILE *fp
, int flags
)
72 fprintf(fp
,"Global variables { ");
74 fprintf(fp
,"%s", v
->vars
[i
]->name
);
76 if (v
->vars
[i
]) fprintf(fp
,", ");
82 /* --------------------------------------------------------------------
85 This function gets the value of a variable and returns it as a
86 PyObject. In our case, we'll be looking at the datatype and
87 converting into a number or string
88 -------------------------------------------------------------------- */
91 swig_varlink_getattr(swig_varlinkobject
*v
, char *n
)
97 if (strcmp(v
->vars
[i
]->name
,n
) == 0) {
98 return (*v
->vars
[i
]->get_attr
)();
102 sprintf(temp
,"C global variable %s not found.", n
);
103 PyErr_SetString(PyExc_NameError
,temp
);
107 /* -------------------------------------------------------------------
108 swig_varlink_setattr()
110 This function sets the value of a variable.
111 ------------------------------------------------------------------- */
114 swig_varlink_setattr(swig_varlinkobject
*v
, char *n
, PyObject
*p
)
119 if (strcmp(v
->vars
[i
]->name
,n
) == 0) {
120 return (*v
->vars
[i
]->set_attr
)(p
);
124 sprintf(temp
,"C global variable %s not found.", n
);
125 PyErr_SetString(PyExc_NameError
,temp
);
129 statichere PyTypeObject varlinktype
= {
130 /* PyObject_HEAD_INIT(&PyType_Type) Note : This doesn't work on some machines */
131 PyObject_HEAD_INIT(0)
133 "varlink", /* Type name */
134 sizeof(swig_varlinkobject
), /* Basic size */
137 (printfunc
) swig_varlink_print
, /* Print */
138 (getattrfunc
) swig_varlink_getattr
, /* get attr */
139 (setattrfunc
) swig_varlink_setattr
, /* Set attr */
141 (reprfunc
) swig_varlink_repr
, /* tp_repr */
142 0, /* tp_as_number */
143 0, /* tp_as_mapping*/
147 /* Create a variable linking object for use later */
149 SWIGSTATICRUNTIME(PyObject
*)
150 SWIG_newvarlink(void)
152 swig_varlinkobject
*result
= 0;
153 result
= PyMem_NEW(swig_varlinkobject
,1);
154 varlinktype
.ob_type
= &PyType_Type
; /* Patch varlinktype into a PyType */
155 result
->ob_type
= &varlinktype
;
156 /* _Py_NewReference(result); Does not seem to be necessary */
158 result
->maxvars
= 64;
159 result
->vars
= (swig_globalvar
**) malloc(64*sizeof(swig_globalvar
*));
161 result
->ob_refcnt
= 0;
162 Py_XINCREF((PyObject
*) result
);
163 return ((PyObject
*) result
);
166 SWIGSTATICRUNTIME(void)
167 SWIG_addvarlink(PyObject
*p
, char *name
,
168 PyObject
*(*get_attr
)(void), int (*set_attr
)(PyObject
*p
))
170 swig_varlinkobject
*v
;
171 v
= (swig_varlinkobject
*) p
;
173 if (v
->nvars
>= v
->maxvars
-1) {
174 v
->maxvars
= 2*v
->maxvars
;
175 v
->vars
= (swig_globalvar
**) realloc(v
->vars
,v
->maxvars
*sizeof(swig_globalvar
*));
176 if (v
->vars
== NULL
) {
177 fprintf(stderr
,"SWIG : Fatal error in initializing Python module.\n");
181 v
->vars
[v
->nvars
] = (swig_globalvar
*) malloc(sizeof(swig_globalvar
));
182 v
->vars
[v
->nvars
]->name
= (char *) malloc(strlen(name
)+1);
183 strcpy(v
->vars
[v
->nvars
]->name
,name
);
184 v
->vars
[v
->nvars
]->get_attr
= get_attr
;
185 v
->vars
[v
->nvars
]->set_attr
= set_attr
;
187 v
->vars
[v
->nvars
] = 0;
190 /* -----------------------------------------------------------------------------
191 * Pointer type-checking
192 * ----------------------------------------------------------------------------- */
194 /* SWIG pointer structure */
195 typedef struct SwigPtrType
{
196 char *name
; /* Datatype name */
197 int len
; /* Length (used for optimization) */
198 void *(*cast
)(void *); /* Pointer casting function */
199 struct SwigPtrType
*next
; /* Linked list pointer */
202 /* Pointer cache structure */
204 int stat
; /* Status (valid) bit */
205 SwigPtrType
*tp
; /* Pointer to type structure */
206 char name
[256]; /* Given datatype name */
207 char mapped
[256]; /* Equivalent name */
210 static int SwigPtrMax
= 64; /* Max entries that can be currently held */
211 static int SwigPtrN
= 0; /* Current number of entries */
212 static int SwigPtrSort
= 0; /* Status flag indicating sort */
213 static int SwigStart
[256]; /* Starting positions of types */
214 static SwigPtrType
*SwigPtrTable
= 0; /* Table containing pointer equivalences */
217 #define SWIG_CACHESIZE 8
218 #define SWIG_CACHEMASK 0x7
219 static SwigCacheType SwigCache
[SWIG_CACHESIZE
];
220 static int SwigCacheIndex
= 0;
221 static int SwigLastCache
= 0;
223 /* Sort comparison function */
224 static int swigsort(const void *data1
, const void *data2
) {
225 SwigPtrType
*d1
= (SwigPtrType
*) data1
;
226 SwigPtrType
*d2
= (SwigPtrType
*) data2
;
227 return strcmp(d1
->name
,d2
->name
);
230 /* Register a new datatype with the type-checker */
231 SWIGSTATICRUNTIME(void)
232 SWIG_RegisterMapping(char *origtype
, char *newtype
, void *(*cast
)(void *)) {
234 SwigPtrType
*t
= 0,*t1
;
236 /* Allocate the pointer table if necessary */
238 SwigPtrTable
= (SwigPtrType
*) malloc(SwigPtrMax
*sizeof(SwigPtrType
));
242 if (SwigPtrN
>= SwigPtrMax
) {
243 SwigPtrMax
= 2*SwigPtrMax
;
244 SwigPtrTable
= (SwigPtrType
*) realloc((char *) SwigPtrTable
,SwigPtrMax
*sizeof(SwigPtrType
));
246 for (i
= 0; i
< SwigPtrN
; i
++) {
247 if (strcmp(SwigPtrTable
[i
].name
,origtype
) == 0) {
248 t
= &SwigPtrTable
[i
];
253 t
= &SwigPtrTable
[SwigPtrN
++];
255 t
->len
= strlen(t
->name
);
260 /* Check for existing entries */
262 if ((strcmp(t
->name
,newtype
) == 0)) {
263 if (cast
) t
->cast
= cast
;
268 t1
= (SwigPtrType
*) malloc(sizeof(SwigPtrType
));
270 t1
->len
= strlen(t1
->name
);
277 /* Make a pointer value string */
278 SWIGSTATICRUNTIME(void)
279 SWIG_MakePtr(char *c
, const void *ptr
, char *type
) {
280 static char hex
[17] = "0123456789abcdef";
284 p
= (unsigned long) ptr
;
300 /* Function for getting a pointer value */
301 SWIGSTATICRUNTIME(char *)
302 SWIG_GetPtr(char *c
, void **ptr
, char *t
)
305 char temp_type
[256], *name
;
306 int i
, len
, start
, end
;
308 SwigCacheType
*cache
;
312 /* Pointer values must start with leading underscore */
315 if (strcmp(c
,"NULL") == 0) return (char *) 0;
319 /* Extract hex value from pointer */
321 if ((d
>= '0') && (d
<= '9'))
322 p
= (p
<< 4) + (d
- '0');
323 else if ((d
>= 'a') && (d
<= 'f'))
324 p
= (p
<< 4) + (d
- ('a'-10));
330 if ((!t
) || (strcmp(t
,c
)==0)) return (char *) 0;
333 qsort((void *) SwigPtrTable
, SwigPtrN
, sizeof(SwigPtrType
), swigsort
);
334 for (i
= 0; i
< 256; i
++) SwigStart
[i
] = SwigPtrN
;
335 for (i
= SwigPtrN
-1; i
>= 0; i
--) SwigStart
[(int) (SwigPtrTable
[i
].name
[1])] = i
;
336 for (i
= 255; i
>= 1; i
--) {
337 if (SwigStart
[i
-1] > SwigStart
[i
])
338 SwigStart
[i
-1] = SwigStart
[i
];
341 for (i
= 0; i
< SWIG_CACHESIZE
; i
++) SwigCache
[i
].stat
= 0;
343 /* First check cache for matches. Uses last cache value as starting point */
344 cache
= &SwigCache
[SwigLastCache
];
345 for (i
= 0; i
< SWIG_CACHESIZE
; i
++) {
346 if (cache
->stat
&& (strcmp(t
,cache
->name
) == 0) && (strcmp(c
,cache
->mapped
) == 0)) {
348 if (cache
->tp
->cast
) *ptr
= (*(cache
->tp
->cast
))(*ptr
);
351 SwigLastCache
= (SwigLastCache
+1) & SWIG_CACHEMASK
;
352 if (!SwigLastCache
) cache
= SwigCache
;
355 /* Type mismatch. Look through type-mapping table */
356 start
= SwigStart
[(int) t
[1]];
357 end
= SwigStart
[(int) t
[1]+1];
358 sp
= &SwigPtrTable
[start
];
360 /* Try to find a match */
361 while (start
<= end
) {
362 if (strncmp(t
,sp
->name
,sp
->len
) == 0) {
366 /* Try to find entry for our given datatype */
368 if (tp
->len
>= 255) {
371 strcpy(temp_type
,tp
->name
);
372 strncat(temp_type
,t
+len
,255-tp
->len
);
373 if (strcmp(c
,temp_type
) == 0) {
374 strcpy(SwigCache
[SwigCacheIndex
].mapped
,c
);
375 strcpy(SwigCache
[SwigCacheIndex
].name
,t
);
376 SwigCache
[SwigCacheIndex
].stat
= 1;
377 SwigCache
[SwigCacheIndex
].tp
= tp
;
378 SwigCacheIndex
= SwigCacheIndex
& SWIG_CACHEMASK
;
379 /* Get pointer value */
381 if (tp
->cast
) *ptr
= (*(tp
->cast
))(*ptr
);
393 /* New object-based GetPointer function. This uses the Python abstract
394 * object interface to automatically dereference the 'this' attribute
395 * of shadow objects. */
397 SWIGSTATICRUNTIME(char *)
398 SWIG_GetPtrObj(PyObject
*obj
, void **ptr
, char *type
) {
399 PyObject
*sobj
= obj
;
401 if (!PyString_Check(obj
)) {
402 if (!PyInstance_Check(obj
) || !(sobj
= PyObject_GetAttrString(obj
,"this")))
404 // sobj = PyObject_GetAttrString(obj,"this");
405 // if (!sobj) return "";
407 str
= PyString_AsString(sobj
);
408 return SWIG_GetPtr(str
,ptr
,type
);