22
22
You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for
23
23
creating a static or dynamic library from the SWIG runtime code.
24
24
In 99.9% of the cases, SWIG just needs to declare them as 'static'.
26
26
But only do this if strictly necessary, ie, if you have problems
27
27
with your compiler or suchlike.
48
48
#define SWIG_POINTER_OWN 0x1
52
52
Flags/methods for returning states.
54
The SWIG conversion methods, as ConvertPtr, return an integer
54
The SWIG conversion methods, as ConvertPtr, return an integer
55
55
that tells if the conversion was successful or not. And if not,
56
56
an error code can be returned (see swigerrors.swg for the codes).
58
58
Use the following macros/flags to set or process the returning
61
61
In old versions of SWIG, code such as the following was usually written:
63
63
if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) {
94
94
I.e., now SWIG_ConvertPtr can return new objects and you can
95
95
identify the case and take care of the deallocation. Of course that
96
96
also requires SWIG_ConvertPtr to return new result values, such as
98
int SWIG_ConvertPtr(obj, ptr,...) {
100
if (<need new object>) {
101
*ptr = <ptr to new allocated object>;
104
*ptr = <ptr to old object>;
98
int SWIG_ConvertPtr(obj, ptr,...) {
100
if (<need new object>) {
101
*ptr = <ptr to new allocated object>;
104
*ptr = <ptr to old object>;
112
112
Of course, returning the plain '0(success)/-1(fail)' still works, but you can be
124
124
food(1) // cast rank '1' (1 -> 1.0)
125
125
fooi(1) // cast rank '0'
127
127
just use the SWIG_AddCast()/SWIG_CheckState()
131
131
#define SWIG_ERROR (-1)
132
132
#define SWIG_IsOK(r) (r >= 0)
133
#define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError)
133
#define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError)
135
135
/* The CastRankLimit says how many bits are used for the cast rank */
136
136
#define SWIG_CASTRANKLIMIT (1 << 8)
162
162
# define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1)
163
163
# define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK)
164
SWIGINTERNINLINE int SWIG_AddCast(int r) {
164
SWIGINTERNINLINE int SWIG_AddCast(int r) {
165
165
return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r;
167
SWIGINTERNINLINE int SWIG_CheckState(int r) {
168
return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0;
167
SWIGINTERNINLINE int SWIG_CheckState(int r) {
168
return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0;
170
170
#else /* no cast-rank mode */
171
# define SWIG_AddCast
171
# define SWIG_AddCast(r) (r)
172
172
# define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0)
234
234
Check type equivalence in a name list like <name1>|<name2>|...
235
Return 0 if equal, -1 if nb < tb, 1 if nb > tb
238
SWIG_TypeCmp(const char *nb, const char *tb) {
240
const char* te = tb + strlen(tb);
242
while (equiv != 0 && *ne) {
243
for (nb = ne; *ne; ++ne) {
244
if (*ne == '|') break;
246
equiv = SWIG_TypeNameComp(nb, ne, tb, te);
253
Check type equivalence in a name list like <name1>|<name2>|...
235
254
Return 0 if not equal, 1 if equal
238
257
SWIG_TypeEquiv(const char *nb, const char *tb) {
240
const char* te = tb + strlen(tb);
242
while (!equiv && *ne) {
243
for (nb = ne; *ne; ++ne) {
244
if (*ne == '|') break;
246
equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0;
253
Check type equivalence in a name list like <name1>|<name2>|...
254
Return 0 if equal, -1 if nb < tb, 1 if nb > tb
257
SWIG_TypeCompare(const char *nb, const char *tb) {
259
const char* te = tb + strlen(tb);
261
while (!equiv && *ne) {
262
for (nb = ne; *ne; ++ne) {
263
if (*ne == '|') break;
265
equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0;
258
return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0;
273
262
Check the typename
383
372
swig_cast_info *cast = ti->cast;
384
373
/* if (ti->clientdata == clientdata) return; */
385
374
ti->clientdata = clientdata;
388
377
if (!cast->converter) {
389
378
swig_type_info *tc = cast->type;
390
379
if (!tc->clientdata) {
391
380
SWIG_TypeClientData(tc, clientdata);
394
383
cast = cast->next;
399
388
SWIG_TypeClientData(ti, clientdata);
404
393
Search for a swig_type_info structure only by mangled name
405
394
Search is a O(log #types)
407
We start searching at module start, and finish searching when start == end.
396
We start searching at module start, and finish searching when start == end.
408
397
Note: if start == end at the beginning of the function, we go all the way around
409
398
the circular list.
411
400
SWIGRUNTIME swig_type_info *
412
SWIG_MangledTypeQueryModule(swig_module_info *start,
413
swig_module_info *end,
401
SWIG_MangledTypeQueryModule(swig_module_info *start,
402
swig_module_info *end,
414
403
const char *name) {
415
404
swig_module_info *iter = start;
419
408
register size_t r = iter->size - 1;
421
410
/* since l+r >= 0, we can (>> 1) instead (/ 2) */
422
register size_t i = (l + r) >> 1;
411
register size_t i = (l + r) >> 1;
423
412
const char *iname = iter->types[i]->name;
425
414
register int compare = strcmp(name, iname);
427
416
return iter->types[i];
428
417
} else if (compare < 0) {
448
437
Search for a swig_type_info structure for either a mangled name or a human readable name.
449
438
It first searches the mangled names of the types, which is a O(log #types)
450
439
If a type is not found it then searches the human readable names, which is O(#types).
452
We start searching at module start, and finish searching when start == end.
441
We start searching at module start, and finish searching when start == end.
453
442
Note: if start == end at the beginning of the function, we go all the way around
454
443
the circular list.
456
445
SWIGRUNTIME swig_type_info *
457
SWIG_TypeQueryModule(swig_module_info *start,
458
swig_module_info *end,
446
SWIG_TypeQueryModule(swig_module_info *start,
447
swig_module_info *end,
459
448
const char *name) {
460
449
/* STEP 1: Search the name field using binary search */
461
450
swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name);
509
498
uu = ((d - '0') << 4);
510
499
else if ((d >= 'a') && (d <= 'f'))
511
500
uu = ((d - ('a'-10)) << 4);
513
502
return (char *) 0;
515
504
if ((d >= '0') && (d <= '9'))
517
506
else if ((d >= 'a') && (d <= 'f'))
518
507
uu |= (d - ('a'-10));
520
509
return (char *) 0;
527
516
Pack 'void *' into a string buffer.
529
518
SWIGRUNTIME char *