~ubuntu-branches/ubuntu/hardy/swig1.3/hardy

« back to all changes in this revision

Viewing changes to Lib/swigrun.swg

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:16:04 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205011604-ygx904it6413k3go
Tags: 1.3.27-1ubuntu1
Resynchronise with Debian again, for the new subversion packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
/* This should only be incremented when either the layout of swig_type_info changes,
10
10
   or for whatever reason, the runtime changes incompatibly */
11
 
#define SWIG_RUNTIME_VERSION "1"
 
11
#define SWIG_RUNTIME_VERSION "2"
12
12
 
13
13
/* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */
14
14
#ifdef SWIG_TYPE_TABLE
15
 
#define SWIG_QUOTE_STRING(x) #x
16
 
#define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x)
17
 
#define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE)
18
 
#else
19
 
#define SWIG_TYPE_TABLE_NAME
20
 
#endif
21
 
 
22
 
#include <string.h>
23
 
 
24
 
#ifndef SWIGINLINE
25
 
#if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
26
 
#  define SWIGINLINE inline
27
 
#else
28
 
#  define SWIGINLINE
29
 
#endif
 
15
# define SWIG_QUOTE_STRING(x) #x
 
16
# define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x)
 
17
# define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE)
 
18
#else
 
19
# define SWIG_TYPE_TABLE_NAME
30
20
#endif
31
21
 
32
22
/*
37
27
  But only do this if is strictly necessary, ie, if you have problems
38
28
  with your compiler or so.
39
29
*/
 
30
 
40
31
#ifndef SWIGRUNTIME
41
 
#define SWIGRUNTIME static
 
32
# define SWIGRUNTIME SWIGINTERN
42
33
#endif
 
34
 
43
35
#ifndef SWIGRUNTIMEINLINE
44
 
#define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE
 
36
# define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE
45
37
#endif
46
38
 
 
39
#include <string.h>
 
40
 
47
41
#ifdef __cplusplus
48
42
extern "C" {
49
43
#endif
51
45
typedef void *(*swig_converter_func)(void *);
52
46
typedef struct swig_type_info *(*swig_dycast_func)(void **);
53
47
 
 
48
/* Structure to store inforomation on one type */
54
49
typedef struct swig_type_info {
55
 
  const char             *name;
56
 
  swig_converter_func     converter;
57
 
  const char             *str;
58
 
  void                   *clientdata;
59
 
  swig_dycast_func        dcast;
60
 
  struct swig_type_info  *next;
61
 
  struct swig_type_info  *prev;
 
50
  const char             *name;                 /* mangled name of this type */
 
51
  const char             *str;                  /* human readable name of this type */
 
52
  swig_dycast_func        dcast;                /* dynamic cast function down a hierarchy */
 
53
  struct swig_cast_info  *cast;                 /* linked list of types that can cast into this type */
 
54
  void                   *clientdata;           /* language specific type data */
62
55
} swig_type_info;
63
56
 
 
57
/* Structure to store a type and conversion function used for casting */
 
58
typedef struct swig_cast_info {
 
59
  swig_type_info         *type;                 /* pointer to type that is equivalent to this type */
 
60
  swig_converter_func     converter;            /* function to cast the void pointers */
 
61
  struct swig_cast_info  *next;                 /* pointer to next cast in linked list */
 
62
  struct swig_cast_info  *prev;                 /* pointer to the previous cast */
 
63
} swig_cast_info;
 
64
 
 
65
/* Structure used to store module information
 
66
 * Each module generates one structure like this, and the runtime collects
 
67
 * all of these structures and stores them in a circularly linked list.*/
 
68
typedef struct swig_module_info {
 
69
  swig_type_info         **types;               /* Array of pointers to swig_type_info structures that are in this module */
 
70
  size_t                 size;                  /* Number of types in this module */
 
71
  struct swig_module_info *next;                /* Pointer to next element in circularly linked list */
 
72
  swig_type_info         **type_initial;        /* Array of initially generated type structures */
 
73
  swig_cast_info         **cast_initial;        /* Array of initially generated casting structures */
 
74
  void                    *clientdata;          /* Language specific module data */
 
75
} swig_module_info;
 
76
 
 
77
 
64
78
/* 
65
79
  Compare two type names skipping the space characters, therefore
66
80
  "char*" == "char *" and "Class<int>" == "Class<int >", etc.
74
88
  for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) {
75
89
    while ((*f1 == ' ') && (f1 != l1)) ++f1;
76
90
    while ((*f2 == ' ') && (f2 != l2)) ++f2;
77
 
    if (*f1 != *f2) return *f1 - *f2;
 
91
    if (*f1 != *f2) return (int)(*f1 - *f2);
78
92
  }
79
93
  return (l1 - f1) - (l2 - f2);
80
94
}
81
95
 
82
96
/*
83
97
  Check type equivalence in a name list like <name1>|<name2>|...
 
98
  Return 0 if not equal, 1 if equal
84
99
*/
85
100
SWIGRUNTIME int
86
101
SWIG_TypeEquiv(const char *nb, const char *tb) {
91
106
    for (nb = ne; *ne; ++ne) {
92
107
      if (*ne == '|') break;
93
108
    }
94
 
    equiv = SWIG_TypeNameComp(nb, ne, tb, te) == 0;
 
109
    equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0;
95
110
    if (*ne) ++ne;
96
111
  }
97
112
  return equiv;
98
113
}
99
114
 
100
115
/*
101
 
  Register a type mapping with the type-checking
 
116
  Check type equivalence in a name list like <name1>|<name2>|...
 
117
  Return 0 if equal, -1 if nb < tb, 1 if nb > tb
102
118
*/
103
 
SWIGRUNTIME swig_type_info *
104
 
SWIG_TypeRegisterTL(swig_type_info **tl, swig_type_info *ti) {
105
 
  swig_type_info *tc, *head, *ret, *next;
106
 
  /* Check to see if this type has already been registered */
107
 
  tc = *tl;
108
 
  while (tc) {
109
 
    /* check simple type equivalence */
110
 
    int typeequiv = (strcmp(tc->name, ti->name) == 0);   
111
 
    /* check full type equivalence, resolving typedefs */
112
 
    if (!typeequiv) {
113
 
      /* only if tc is not a typedef (no '|' on it) */
114
 
      if (tc->str && ti->str && !strstr(tc->str,"|")) {
115
 
        typeequiv = SWIG_TypeEquiv(ti->str,tc->str);
116
 
      }
117
 
    }
118
 
    if (typeequiv) {
119
 
      /* Already exists in the table.  Just add additional types to the list */
120
 
      if (ti->clientdata) tc->clientdata = ti->clientdata;
121
 
      head = tc;
122
 
      next = tc->next;
123
 
      goto l1;
124
 
    }
125
 
    tc = tc->prev;
126
 
  }
127
 
  head = ti;
128
 
  next = 0;
129
 
 
130
 
  /* Place in list */
131
 
  ti->prev = *tl;
132
 
  *tl = ti;
133
 
 
134
 
  /* Build linked lists */
135
 
  l1:
136
 
  ret = head;
137
 
  tc = ti + 1;
138
 
  /* Patch up the rest of the links */
139
 
  while (tc->name) {
140
 
    head->next = tc;
141
 
    tc->prev = head;
142
 
    head = tc;
143
 
    tc++;
144
 
  }
145
 
  if (next) next->prev = head;
146
 
  head->next = next;
147
 
 
148
 
  return ret;
 
119
SWIGRUNTIME int
 
120
SWIG_TypeCompare(const char *nb, const char *tb) {
 
121
  int equiv = 0;
 
122
  const char* te = tb + strlen(tb);
 
123
  const char* ne = nb;
 
124
  while (!equiv && *ne) {
 
125
    for (nb = ne; *ne; ++ne) {
 
126
      if (*ne == '|') break;
 
127
    }
 
128
    equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0;
 
129
    if (*ne) ++ne;
 
130
  }
 
131
  return equiv;
149
132
}
150
133
 
 
134
 
 
135
/* think of this as a c++ template<> or a scheme macro */
 
136
#define SWIG_TypeCheck_Template(comparison, ty)         \
 
137
  if (ty) {                                             \
 
138
    swig_cast_info *iter = ty->cast;                    \
 
139
    while (iter) {                                      \
 
140
      if (comparison) {                                 \
 
141
        if (iter == ty->cast) return iter;              \
 
142
        /* Move iter to the top of the linked list */   \
 
143
        iter->prev->next = iter->next;                  \
 
144
        if (iter->next)                                 \
 
145
          iter->next->prev = iter->prev;                \
 
146
        iter->next = ty->cast;                          \
 
147
        iter->prev = 0;                                 \
 
148
        if (ty->cast) ty->cast->prev = iter;            \
 
149
        ty->cast = iter;                                \
 
150
        return iter;                                    \
 
151
      }                                                 \
 
152
      iter = iter->next;                                \
 
153
    }                                                   \
 
154
  }                                                     \
 
155
  return 0
 
156
 
151
157
/*
152
158
  Check the typename
153
159
*/
154
 
SWIGRUNTIME swig_type_info *
 
160
SWIGRUNTIME swig_cast_info *
155
161
SWIG_TypeCheck(const char *c, swig_type_info *ty) {
156
 
  swig_type_info *s;
157
 
  if (!ty) return 0;        /* Void pointer */
158
 
  s = ty->next;             /* First element always just a name */
159
 
  do {
160
 
    if (strcmp(s->name,c) == 0) {
161
 
      if (s == ty->next) return s;
162
 
      /* Move s to the top of the linked list */
163
 
      s->prev->next = s->next;
164
 
      if (s->next) {
165
 
        s->next->prev = s->prev;
166
 
      }
167
 
      /* Insert s as second element in the list */
168
 
      s->next = ty->next;
169
 
      if (ty->next) ty->next->prev = s;
170
 
      ty->next = s;
171
 
      s->prev = ty;
172
 
      return s;
173
 
    }
174
 
    s = s->next;
175
 
  } while (s && (s != ty->next));
176
 
  return 0;
 
162
  SWIG_TypeCheck_Template(strcmp(iter->type->name, c) == 0, ty);
 
163
}
 
164
 
 
165
/* Same as previous function, except strcmp is replaced with a pointer comparison */
 
166
SWIGRUNTIME swig_cast_info *
 
167
SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *into) {
 
168
  SWIG_TypeCheck_Template(iter->type == from, into);
177
169
}
178
170
 
179
171
/*
180
172
  Cast a pointer up an inheritance hierarchy
181
173
*/
182
174
SWIGRUNTIMEINLINE void *
183
 
SWIG_TypeCast(swig_type_info *ty, void *ptr) {
 
175
SWIG_TypeCast(swig_cast_info *ty, void *ptr) {
184
176
  return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr);
185
177
}
186
178
 
227
219
    return type->name;
228
220
}
229
221
 
230
 
/*
231
 
  Search for a swig_type_info structure
232
 
*/
233
 
SWIGRUNTIME swig_type_info *
234
 
SWIG_TypeQueryTL(swig_type_info *tl, const char *name) {
235
 
  swig_type_info *ty = tl;
236
 
  while (ty) {
237
 
    if (ty->str && (SWIG_TypeEquiv(ty->str,name))) return ty;
238
 
    if (ty->name && (strcmp(name,ty->name) == 0)) return ty;
239
 
    ty = ty->prev;
240
 
  }
241
 
  return 0;
242
 
}
243
 
 
244
222
/* 
245
223
   Set the clientdata field for a type
246
224
*/
247
225
SWIGRUNTIME void
248
 
SWIG_TypeClientDataTL(swig_type_info *tl, swig_type_info *ti, void *clientdata) {
249
 
  swig_type_info *tc, *equiv;
250
 
  if (ti->clientdata) return;
 
226
SWIG_TypeClientData(swig_type_info *ti, void *clientdata) {
 
227
  swig_cast_info *cast = ti->cast;
251
228
  /* if (ti->clientdata == clientdata) return; */
252
229
  ti->clientdata = clientdata;
253
 
  equiv = ti->next;
254
 
  while (equiv) {
255
 
    if (!equiv->converter) {
256
 
      tc = tl;
257
 
      while (tc) {
258
 
        if ((strcmp(tc->name, equiv->name) == 0))
259
 
          SWIG_TypeClientDataTL(tl,tc,clientdata);
260
 
        tc = tc->prev;
 
230
  
 
231
  while (cast) {
 
232
    if (!cast->converter) {
 
233
      swig_type_info *tc = cast->type;
 
234
      if (!tc->clientdata) {
 
235
        SWIG_TypeClientData(tc, clientdata);
261
236
      }
 
237
    }    
 
238
    cast = cast->next;
 
239
  }
 
240
}
 
241
 
 
242
/*
 
243
  Search for a swig_type_info structure only by mangled name
 
244
  Search is a O(log #types)
 
245
  
 
246
  We start searching at module start, and finish searching when start == end.  
 
247
  Note: if start == end at the beginning of the function, we go all the way around
 
248
  the circular list.
 
249
*/
 
250
SWIGRUNTIME swig_type_info *
 
251
SWIG_MangledTypeQueryModule(swig_module_info *start, 
 
252
                            swig_module_info *end, 
 
253
                            const char *name) {
 
254
  swig_module_info *iter = start;
 
255
  do {
 
256
    if (iter->size) {
 
257
      register size_t l = 0;
 
258
      register size_t r = iter->size - 1;
 
259
      do {
 
260
        /* since l+r >= 0, we can (>> 1) instead (/ 2) */
 
261
        register size_t i = (l + r) >> 1; 
 
262
        const char *iname = iter->types[i]->name;
 
263
        if (iname) {
 
264
          register int compare = strcmp(name, iname);
 
265
          if (compare == 0) {       
 
266
            return iter->types[i];
 
267
          } else if (compare < 0) {
 
268
            if (i) {
 
269
              r = i - 1;
 
270
            } else {
 
271
              break;
 
272
            }
 
273
          } else if (compare > 0) {
 
274
            l = i + 1;
 
275
          }
 
276
        } else {
 
277
          break; /* should never happen */
 
278
        }
 
279
      } while (l <= r);
262
280
    }
263
 
    equiv = equiv->next;
 
281
    iter = iter->next;
 
282
  } while (iter != end);
 
283
  return 0;
 
284
}
 
285
 
 
286
/*
 
287
  Search for a swig_type_info structure for either a mangled name or a human readable name.
 
288
  It first searches the mangled names of the types, which is a O(log #types)
 
289
  If a type is not found it then searches the human readable names, which is O(#types).
 
290
  
 
291
  We start searching at module start, and finish searching when start == end.  
 
292
  Note: if start == end at the beginning of the function, we go all the way around
 
293
  the circular list.
 
294
*/
 
295
SWIGRUNTIME swig_type_info *
 
296
SWIG_TypeQueryModule(swig_module_info *start, 
 
297
                     swig_module_info *end, 
 
298
                     const char *name) {
 
299
  /* STEP 1: Search the name field using binary search */
 
300
  swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name);
 
301
  if (ret) {
 
302
    return ret;
 
303
  } else {
 
304
    /* STEP 2: If the type hasn't been found, do a complete search
 
305
       of the str field (the human readable name) */
 
306
    swig_module_info *iter = start;
 
307
    do {
 
308
      register size_t i = 0;
 
309
      for (; i < iter->size; ++i) {
 
310
        if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name)))
 
311
          return iter->types[i];
 
312
      }
 
313
      iter = iter->next;
 
314
    } while (iter != end);
264
315
  }
 
316
  
 
317
  /* neither found a match */
 
318
  return 0;
265
319
}
266
320
 
 
321
 
267
322
/* 
268
323
   Pack binary data into a string
269
324
*/
270
325
SWIGRUNTIME char *
271
326
SWIG_PackData(char *c, void *ptr, size_t sz) {
272
 
  static char hex[17] = "0123456789abcdef";
273
 
  unsigned char *u = (unsigned char *) ptr;
274
 
  const unsigned char *eu =  u + sz;
275
 
  register unsigned char uu;
 
327
  static const char hex[17] = "0123456789abcdef";
 
328
  register const unsigned char *u = (unsigned char *) ptr;
 
329
  register const unsigned char *eu =  u + sz;
276
330
  for (; u != eu; ++u) {
277
 
    uu = *u;
 
331
    register unsigned char uu = *u;
278
332
    *(c++) = hex[(uu & 0xf0) >> 4];
279
333
    *(c++) = hex[uu & 0xf];
280
334
  }
287
341
SWIGRUNTIME const char *
288
342
SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
289
343
  register unsigned char *u = (unsigned char *) ptr;
290
 
  register const unsigned char *eu =  u + sz;
 
344
  register const unsigned char *eu = u + sz;
291
345
  for (; u != eu; ++u) {
292
 
    register int d = *(c++);
 
346
    register char d = *(c++);
293
347
    register unsigned char uu = 0;
294
348
    if ((d >= '0') && (d <= '9'))
295
349
      uu = ((d - '0') << 4);
309
363
  return c;
310
364
}
311
365
 
312
 
/*
313
 
  This function will propagate the clientdata field of type to any new
314
 
  swig_type_info structures that have been added into the list of
315
 
  equivalent types.  It is like calling SWIG_TypeClientData(type,
316
 
  clientdata) a second time.
317
 
*/
318
 
SWIGRUNTIME void
319
 
SWIG_PropagateClientDataTL(swig_type_info *tl, swig_type_info *type) {
320
 
  swig_type_info *equiv = type->next;
321
 
  swig_type_info *tc;
322
 
  if (!type->clientdata) return;
323
 
  while (equiv) {
324
 
    if (!equiv->converter) {
325
 
      tc = tl;
326
 
      while (tc) {
327
 
        if ((strcmp(tc->name, equiv->name) == 0) && !tc->clientdata)
328
 
          SWIG_TypeClientDataTL(tl,tc, type->clientdata);
329
 
        tc = tc->prev;
330
 
      }
331
 
    }
332
 
    equiv = equiv->next;
333
 
  }
334
 
}
335
 
 
336
366
/* 
337
367
   Pack 'void *' into a string buffer.
338
368
*/