]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxSWIG/Runtime/libtcl8.c
1 /**************************************************************************
6 * This file provides type-checked pointer support to Tcl 8.0.
7 **********************************************************************/
9 #if defined(_WIN32) || defined(__WIN32__)
10 # if defined(_MSC_VER)
11 # define SWIGEXPORT(a) __declspec(dllexport) a
13 # if defined(__BORLANDC__)
14 # define SWIGEXPORT(a) a _export
16 # define SWIGEXPORT(a) a
20 # define SWIGEXPORT(a) a
29 #define SWIGSTATICRUNTIME(a) SWIGEXPORT(a)
31 #define SWIGSTATICRUNTIME(a) static a
35 extern void SWIG_SetPointerObj(Tcl_Obj
*, void *, char *);
36 extern void SWIG_RegisterMapping(char *, char *, void *(*)(void *));
37 extern char *SWIG_GetPointerObj(Tcl_Interp
*, Tcl_Obj
*, void **, char *);
38 extern int SWIG_MakePtr(char *, const void *, char *);
39 extern void SWIG_RegisterType();
42 /* These are internal variables. Should be static */
44 typedef struct SwigPtrType
{
47 void *(*cast
)(void *);
48 struct SwigPtrType
*next
;
51 /* Pointer cache structure */
54 int stat
; /* Status (valid) bit */
55 SwigPtrType
*tp
; /* Pointer to type structure */
56 char name
[256]; /* Given datatype name */
57 char mapped
[256]; /* Equivalent name */
60 static int SwigPtrMax
= 64; /* Max entries that can be currently held */
61 static int SwigPtrN
= 0; /* Current number of entries */
62 static int SwigPtrSort
= 0; /* Status flag indicating sort */
63 static int SwigStart
[256]; /* Array containing start locations (for searching) */
64 static SwigPtrType
*SwigPtrTable
= 0; /* Table containing pointer equivalences */
68 #define SWIG_CACHESIZE 8
69 #define SWIG_CACHEMASK 0x7
70 static SwigCacheType SwigCache
[SWIG_CACHESIZE
];
71 static int SwigCacheIndex
= 0;
72 static int SwigLastCache
= 0;
74 /* Sort comparison function */
75 static int swigsort(const void *data1
, const void *data2
) {
76 SwigPtrType
*d1
= (SwigPtrType
*) data1
;
77 SwigPtrType
*d2
= (SwigPtrType
*) data2
;
78 return strcmp(d1
->name
,d2
->name
);
81 /* Binary Search function */
82 static int swigcmp(const void *key
, const void *data
) {
83 char *k
= (char *) key
;
84 SwigPtrType
*d
= (SwigPtrType
*) data
;
85 return strncmp(k
,d
->name
,d
->len
);
89 /*---------------------------------------------------------------------
90 * SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *))
92 * Register a new type-mapping with the type-checking system.
93 *---------------------------------------------------------------------*/
95 SWIGSTATICRUNTIME(void)
96 SWIG_RegisterMapping(char *origtype
, char *newtype
, void *(*cast
)(void *)) {
99 SwigPtrType
*t
= 0, *t1
;
102 SwigPtrTable
= (SwigPtrType
*) malloc(SwigPtrMax
*sizeof(SwigPtrType
));
105 if (SwigPtrN
>= SwigPtrMax
) {
106 SwigPtrMax
= 2*SwigPtrMax
;
107 SwigPtrTable
= (SwigPtrType
*) realloc(SwigPtrTable
,SwigPtrMax
*sizeof(SwigPtrType
));
109 for (i
= 0; i
< SwigPtrN
; i
++)
110 if (strcmp(SwigPtrTable
[i
].name
,origtype
) == 0) {
111 t
= &SwigPtrTable
[i
];
115 t
= &SwigPtrTable
[SwigPtrN
];
117 t
->len
= strlen(origtype
);
123 if (strcmp(t
->name
,newtype
) == 0) {
124 if (cast
) t
->cast
= cast
;
129 t1
= (SwigPtrType
*) malloc(sizeof(SwigPtrType
));
131 t1
->len
= strlen(newtype
);
139 /*---------------------------------------------------------------------
140 * void SWIG_SetPointerObj(Tcl_Obj *objPtr, void *ptr, char *type)
142 * Sets a Tcl object to a pointer value.
143 * ptr = void pointer value
144 * type = string representing type
146 *---------------------------------------------------------------------*/
148 SWIGSTATICRUNTIME(void)
149 SWIG_SetPointerObj(Tcl_Obj
*objPtr
, void *_ptr
, char *type
) {
150 static char _hex
[16] =
151 {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
152 'a', 'b', 'c', 'd', 'e', 'f'};
153 unsigned long _p
, _s
;
154 char _result
[20], *_r
; /* Note : a 64-bit hex number = 16 digits */
157 _p
= (unsigned long) _ptr
;
166 while (_r
>= _result
)
169 Tcl_SetStringObj(objPtr
,_temp
,-1);
171 Tcl_SetStringObj(objPtr
,"NULL",-1);
174 Tcl_AppendToObj(objPtr
,type
,-1);
177 /* This is for backwards compatibility */
179 SWIGSTATICRUNTIME(int)
180 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
;
189 _p
= (unsigned long) _ptr
;
199 while (_r
>= _result
)
211 /*---------------------------------------------------------------------
212 * char *SWIG_GetPointerObj(Tcl_Interp *interp, Tcl_Obj *objPtr, void **ptr, char *type)
214 * Attempts to extract a pointer value from our pointer type.
215 * Upon failure, returns a string corresponding to the actual datatype.
216 * Upon success, returns NULL and sets the pointer value in ptr.
217 *---------------------------------------------------------------------*/
219 SWIGSTATICRUNTIME(char *)
220 SWIG_GetPointerObj(Tcl_Interp
*interp
, Tcl_Obj
*objPtr
, void **ptr
, char *_t
) {
226 SwigCacheType
*cache
;
231 /* Extract the pointer value as a string */
232 _c
= Tcl_GetStringFromObj(objPtr
, &i
);
234 /* Pointer values must start with leading underscore */
237 /* Extract hex value from pointer */
239 if ((*_c
>= '0') && (*_c
<= '9'))
240 _p
= (_p
<< 4) + (*_c
- '0');
241 else if ((*_c
>= 'a') && (*_c
<= 'f'))
242 _p
= (_p
<< 4) + ((*_c
- 'a') + 10);
251 qsort((void *) SwigPtrTable
, SwigPtrN
, sizeof(SwigPtrType
), swigsort
);
252 for (i
= 0; i
< 256; i
++) {
253 SwigStart
[i
] = SwigPtrN
;
255 for (i
= SwigPtrN
-1; i
>= 0; i
--) {
256 SwigStart
[(int) (SwigPtrTable
[i
].name
[1])] = i
;
258 for (i
= 255; i
>= 1; i
--) {
259 if (SwigStart
[i
-1] > SwigStart
[i
])
260 SwigStart
[i
-1] = SwigStart
[i
];
263 for (i
= 0; i
< SWIG_CACHESIZE
; i
++)
264 SwigCache
[i
].stat
= 0;
267 /* First check cache for matches. Uses last cache value as starting point */
268 cache
= &SwigCache
[SwigLastCache
];
269 for (i
= 0; i
< SWIG_CACHESIZE
; i
++) {
271 if (strcmp(_t
,cache
->name
) == 0) {
272 if (strcmp(_c
,cache
->mapped
) == 0) {
275 if (cache
->tp
->cast
) *ptr
= (*(cache
->tp
->cast
))(*ptr
);
280 SwigLastCache
= (SwigLastCache
+1) & SWIG_CACHEMASK
;
281 if (!SwigLastCache
) cache
= SwigCache
;
284 /* We have a type mismatch. Will have to look through our type
285 mapping table to figure out whether or not we can accept this datatype */
287 start
= SwigStart
[(int) _t
[1]];
288 end
= SwigStart
[(int) _t
[1]+1];
289 sp
= &SwigPtrTable
[start
];
290 while (start
< end
) {
291 if (swigcmp(_t
,sp
) == 0) break;
295 if (start
> end
) sp
= 0;
296 /* Try to find a match for this */
297 while (start
<= end
) {
298 if (swigcmp(_t
,sp
) == 0) {
302 /* Try to find entry for our given datatype */
304 if (tp
->len
>= 255) {
307 strcpy(temp_type
,tp
->name
);
308 strncat(temp_type
,_t
+len
,255-tp
->len
);
309 if (strcmp(_c
,temp_type
) == 0) {
311 strcpy(SwigCache
[SwigCacheIndex
].mapped
,_c
);
312 strcpy(SwigCache
[SwigCacheIndex
].name
,_t
);
313 SwigCache
[SwigCacheIndex
].stat
= 1;
314 SwigCache
[SwigCacheIndex
].tp
= tp
;
315 SwigCacheIndex
= SwigCacheIndex
& SWIG_CACHEMASK
;
317 /* Get pointer value */
319 if (tp
->cast
) *ptr
= (*(tp
->cast
))(*ptr
);
328 /* Didn't find any sort of match for this data.
329 Get the pointer value and return the received type */
333 /* Found a match on the first try. Return pointer value */
338 /* No type specified. Good luck */
343 if (strcmp (_c
, "NULL") == 0) {
352 /*---------------------------------------------------------------------
353 * void SWIG_RegisterType()
355 * Registers our new datatype with an interpreter.
356 *---------------------------------------------------------------------*/
358 SWIGSTATICRUNTIME(void)
359 SWIG_RegisterType() {
360 /* Does nothing at the moment */