2
* Copyright (c) 2004 Mellanox Technologies LTD. All rights reserved.
4
* This software is available to you under a choice of one of two
5
* licenses. You may choose to be licensed under the terms of the GNU
6
* General Public License (GPL) Version 2, available from the file
7
* COPYING in the main directory of this source tree, or the
8
* OpenIB.org BSD license below:
10
* Redistribution and use in source and binary forms, with or
11
* without modification, are permitted provided that the following
14
* - Redistributions of source code must retain the above
15
* copyright notice, this list of conditions and the following
18
* - Redistributions in binary form must reproduce the above
19
* copyright notice, this list of conditions and the following
20
* disclaimer in the documentation and/or other materials
21
* provided with the distribution.
23
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36
// the type of map holding alternate object mangling function and reverse one
37
// note we hold it by the original mangled type
38
// the type of map holding alternate object mangling function and reverse one
39
// note we hold it by the original mangled type
40
struct less_char_array : public binary_function<const char *, const char *, bool> {
41
bool operator() (const char * x, const char * y) const { return (strcmp(x,y) < 0); }
44
#define charp_getname_map map<const char *, int (*)(Tcl_Obj *, void *,char *type), less_char_array >
45
#define charp_getobjp_map map<const char *, int (*)(Tcl_Obj *, void **), less_char_array >
47
// two maps - for in and out of C++ space
48
charp_getname_map SWIG_AlternateObjMangling;
49
charp_getobjp_map SWIG_AlternateNameToObj;
51
/*---------------------------------------------------------------------
52
* void SWIG_SetPointerObj(Tcl_Obj *objPtr, void *ptr, char *type)
54
* Sets a Tcl object to a pointer value.
55
* ptr = void pointer value
56
* type = string representing type
58
*---------------------------------------------------------------------*/
60
void SWIG_SetPointerObj(Tcl_Obj *objPtr, void *_ptr, char *type) {
62
// if we have an alternate mangling use it:
63
charp_getname_map::const_iterator I = SWIG_AlternateObjMangling.find(type);
64
if (I != SWIG_AlternateObjMangling.end()) {
65
int (*getName)(Tcl_Obj *, void *, char *type) = (*I).second;
66
if (getName(objPtr, _ptr, type)) {
67
cerr << "-E- Fail to convert object to string\n";
72
static char _hex[16] =
73
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
74
'a', 'b', 'c', 'd', 'e', 'f'};
76
char _result[20], *_r; /* Note : a 64-bit hex number = 16 digits */
79
_p = (unsigned long) _ptr;
91
Tcl_SetStringObj(objPtr,_temp,-1);
93
Tcl_SetStringObj(objPtr,"NULL",-1);
96
Tcl_AppendToObj(objPtr,type,-1);
99
/*---------------------------------------------------------------------
100
* char *SWIG_GetPointerObj(Tcl_Interp *interp, Tcl_Obj *objPtr, void **ptr, char *type)
102
* Attempts to extract a pointer value from our pointer type.
103
* Upon failure, returns a string corresponding to the actual datatype.
104
* Upon success, returns NULL and sets the pointer value in ptr.
105
*---------------------------------------------------------------------*/
108
char *SWIG_GetPointerObj(Tcl_Interp *interp, Tcl_Obj *objPtr, void **ptr, char *_t) {
114
SwigCacheType *cache;
119
// if alternate mangling is defined use it:
120
charp_getobjp_map::const_iterator I = SWIG_AlternateNameToObj.find(_t);
121
if (I != SWIG_AlternateNameToObj.end()) {
122
int (* getObjByName)(Tcl_Obj *, void **) = (*I).second;
123
if (getObjByName(objPtr, ptr)) {
124
cerr << "-E- fail to get object by name\n";
125
return Tcl_GetStringFromObj(objPtr, &i);
130
/* Extract the pointer value as a string */
131
_c = Tcl_GetStringFromObj(objPtr, &i);
133
/* Pointer values must start with leading underscore */
136
/* Extract hex value from pointer */
138
if ((*_c >= '0') && (*_c <= '9'))
139
_p = (_p << 4) + (*_c - '0');
140
else if ((*_c >= 'a') && (*_c <= 'f'))
141
_p = (_p << 4) + ((*_c - 'a') + 10);
150
qsort((void *) SwigPtrTable, SwigPtrN, sizeof(SwigPtrType), swigsort);
151
for (i = 0; i < 256; i++) {
152
SwigStart[i] = SwigPtrN;
154
for (i = SwigPtrN-1; i >= 0; i--) {
155
SwigStart[(int) (SwigPtrTable[i].name[1])] = i;
157
for (i = 255; i >= 1; i--) {
158
if (SwigStart[i-1] > SwigStart[i])
159
SwigStart[i-1] = SwigStart[i];
162
for (i = 0; i < SWIG_CACHESIZE; i++)
163
SwigCache[i].stat = 0;
166
/* First check cache for matches. Uses last cache value as starting point */
167
cache = &SwigCache[SwigLastCache];
168
for (i = 0; i < SWIG_CACHESIZE; i++) {
170
if (strcmp(_t,cache->name) == 0) {
171
if (strcmp(_c,cache->mapped) == 0) {
174
if (cache->tp->cast) *ptr = (*(cache->tp->cast))(*ptr);
179
SwigLastCache = (SwigLastCache+1) & SWIG_CACHEMASK;
180
if (!SwigLastCache) cache = SwigCache;
183
/* We have a type mismatch. Will have to look through our type
184
mapping table to figure out whether or not we can accept this datatype */
186
start = SwigStart[(int) _t[1]];
187
end = SwigStart[(int) _t[1]+1];
188
sp = &SwigPtrTable[start];
189
while (start < end) {
190
if (swigcmp(_t,sp) == 0) break;
194
if (start >= end) sp = 0;
195
/* Try to find a match for this */
197
while (swigcmp(_t,sp) == 0) {
201
/* Try to find entry for our given datatype */
203
if (tp->len >= 255) {
206
strcpy(temp_type,tp->name);
207
strncat(temp_type,_t+len,255-tp->len);
208
if (strcmp(_c,temp_type) == 0) {
210
strcpy(SwigCache[SwigCacheIndex].mapped,_c);
211
strcpy(SwigCache[SwigCacheIndex].name,_t);
212
SwigCache[SwigCacheIndex].stat = 1;
213
SwigCache[SwigCacheIndex].tp = tp;
214
SwigCacheIndex = SwigCacheIndex & SWIG_CACHEMASK;
216
/* Get pointer value */
218
if (tp->cast) *ptr = (*(tp->cast))(*ptr);
224
/* Hmmm. Didn't find it this time */
227
/* Didn't find any sort of match for this data.
228
Get the pointer value and return the received type */
232
/* Found a match on the first try. Return pointer value */
237
/* No type specified. Good luck */
242
if (strcmp (_c, "NULL") == 0) {