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

« back to all changes in this revision

Viewing changes to Lib/mzscheme/mzscheme.swg

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Landschoff
  • Date: 2002-03-29 01:56:07 UTC
  • Revision ID: james.westby@ubuntu.com-20020329015607-c0wt03xu8oy9ioj7
Tags: upstream-1.3.11
ImportĀ upstreamĀ versionĀ 1.3.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*-c-*- */
 
2
 
 
3
/* SWIG pointer structure */
 
4
 
 
5
#ifdef __cplusplus
 
6
extern "C" {
 
7
#endif
 
8
 
 
9
struct SwigCast {
 
10
  struct SwigPtrType *type;               /* Type in SwigPtrTbl             */
 
11
  void               *(*cast)(void *);    /* Pointer casting function       */
 
12
  struct SwigCast    *next;               /* Linked list pointer            */
 
13
};
 
14
 
 
15
struct SwigPtrType {
 
16
  const char         *name;               /* Datatype name                  */
 
17
  const char         *prettyname;         /* Pretty datatype name           */
 
18
  struct SwigCast    *cast;               /* List of compatible types       */
 
19
};
 
20
 
 
21
struct swig_proxy {
 
22
    Scheme_Type type;
 
23
    SwigPtrType *ptrtype;
 
24
    void *object;
 
25
};
 
26
 
 
27
/* Pointer table */
 
28
static SwigPtrType **SwigPtrTbl = 0;    /* Sorted table */
 
29
static int SwigPtrMax  = 64;            /* Max entries that can be held */
 
30
                                        /* (may be adjusted dynamically) */
 
31
static int SwigPtrN    = 0;             /* Current number of entries */
 
32
static int SwigPtrSort = 0;             /* Status flag indicating sort */
 
33
 
 
34
/* Sort comparison function */
 
35
static int
 
36
swigsort (const void *data1, const void *data2)
 
37
{
 
38
  SwigPtrType *type1 = * (SwigPtrType **) data1;
 
39
  SwigPtrType *type2 = * (SwigPtrType **) data2;
 
40
  return strcmp(type1->name, type2->name);
 
41
}
 
42
 
 
43
/* Register a new datatype with the type-checker */
 
44
SWIGSTATIC SwigPtrType *
 
45
SWIG_RegisterType (const char *type, const char *prettyname)
 
46
{
 
47
  int i;
 
48
  struct SwigPtrType **t;
 
49
 
 
50
  /* Allocate the pointer table if necessary */
 
51
  if (!SwigPtrTbl) {
 
52
    SwigPtrTbl = (SwigPtrType **) malloc(SwigPtrMax*sizeof(SwigPtrType *));
 
53
    SwigPtrN = 0;
 
54
  }
 
55
  /* Grow the table if necessary */
 
56
  if (SwigPtrN >= SwigPtrMax) {
 
57
    SwigPtrMax = 2*SwigPtrMax;
 
58
    SwigPtrTbl = (SwigPtrType **) realloc((char *) SwigPtrTbl,
 
59
                                          SwigPtrMax*sizeof(SwigPtrType *));
 
60
  }
 
61
  /* Look up type */
 
62
  for (i = 0; i < SwigPtrN; i++)
 
63
    if (strcmp(SwigPtrTbl[i]->name,type) == 0) {
 
64
      if (prettyname!=NULL)
 
65
        SwigPtrTbl[i]->prettyname = prettyname;
 
66
      return SwigPtrTbl[i];
 
67
    }
 
68
  t = SwigPtrTbl + SwigPtrN;
 
69
  *t = (SwigPtrType *) malloc(sizeof(SwigPtrType));
 
70
  (*t)->name = type;
 
71
  (*t)->prettyname = prettyname;
 
72
  (*t)->cast = NULL;
 
73
  SwigPtrN++;
 
74
  SwigPtrSort = 0; 
 
75
  return *t;
 
76
}
 
77
 
 
78
/* Register two data types and their mapping with the type checker. */
 
79
SWIGSTATIC void
 
80
SWIG_RegisterMapping (const char *origtype, const char *newtype, void *(*cast)(void *))
 
81
{
 
82
  struct SwigPtrType *t = SWIG_RegisterType(origtype, NULL);
 
83
 
 
84
  if (newtype!=NULL) {
 
85
    struct SwigPtrType *t1 = SWIG_RegisterType(newtype, NULL);
 
86
    struct SwigCast *c;
 
87
    /* Check for existing cast */
 
88
    for (c = t->cast; c && c->type!=t1; c=c->next) /* nothing */;
 
89
    if (c) {
 
90
      if (cast) c->cast = cast;
 
91
    }
 
92
    else {
 
93
      c = (struct SwigCast *) malloc(sizeof(struct SwigCast));
 
94
      c->type = t1;
 
95
      c->cast = cast;
 
96
      c->next = t->cast;
 
97
      t->cast = c;
 
98
    }
 
99
  }
 
100
}
 
101
 
 
102
/* Sort table */
 
103
 
 
104
static void
 
105
SWIG_SortTable (void)
 
106
{
 
107
  qsort ((void *) SwigPtrTbl, SwigPtrN, sizeof(struct SwigPtrTbl *), swigsort);
 
108
  /* Indicate that everything is sorted */
 
109
  SwigPtrSort = 1;
 
110
}
 
111
 
 
112
/* Look up pointer-type entry in table */
 
113
 
 
114
static int
 
115
swigcmp (const void *key, const void *data)
 
116
{
 
117
  char *k = (char *) key;
 
118
  SwigPtrType *t = *(SwigPtrType **) data;
 
119
  return strcmp(k, t->name);
 
120
}
 
121
 
 
122
static SwigPtrType *
 
123
SWIG_GetPtrType (const char *_t)
 
124
{
 
125
  SwigPtrType **result;
 
126
  if (!SwigPtrSort) SWIG_SortTable();
 
127
  result = (SwigPtrType **) bsearch(_t, SwigPtrTbl, SwigPtrN,
 
128
                                    sizeof(SwigPtrType *), swigcmp);
 
129
  if (result!=NULL) return *result;
 
130
  else return NULL;
 
131
}
 
132
 
 
133
/* Cast a pointer if possible; returns 1 if successful */
 
134
 
 
135
static int
 
136
SWIG_Cast (void *source, SwigPtrType *source_type,
 
137
           void **ptr, SwigPtrType *dest_type)
 
138
{
 
139
  if (dest_type != source_type) {
 
140
    /* We have a type mismatch.  Will have to look through our type
 
141
       mapping table to figure out whether or not we can accept this
 
142
       datatype.  */
 
143
    struct SwigCast *c;
 
144
    for (c = dest_type->cast;
 
145
         c && c->type!=source_type; c = c->next) /* nothing */;
 
146
    if (c) {
 
147
      /* Get pointer value. */
 
148
      if (c->cast) *ptr = (*(c->cast))(source);
 
149
      else *ptr = source;
 
150
      return -1;
 
151
    }
 
152
    /* Didn't find any sort of match for this data.
 
153
       Get the pointer value and return false.  */
 
154
    *ptr = source;
 
155
    return 0;
 
156
  } else {
 
157
    /* Found a match on the first try.  Return pointer value.  */
 
158
    *ptr = source;
 
159
    return -1;
 
160
  }
 
161
}
 
162
 
 
163
/* Function for getting a pointer value */
 
164
 
 
165
static Scheme_Type swig_type;
 
166
int swig_initialized_p = 0;
 
167
 
 
168
SWIGSTATIC Scheme_Object *
 
169
SWIG_MakePtr(void *c_pointer, swig_type_info *type) {
 
170
    struct swig_proxy *new_proxy;
 
171
    new_proxy = (struct swig_proxy *) scheme_malloc(sizeof(struct swig_proxy));
 
172
    new_proxy->type = swig_type;
 
173
    new_proxy->ptrtype = type->ptrtype;
 
174
    new_proxy->object = (void *) c_pointer;
 
175
    return (Scheme_Object *) new_proxy;
 
176
}
 
177
 
 
178
/* Return 0 if successful. */
 
179
SWIGSTATIC int
 
180
SWIG_GetPtr(Scheme_Object *s, void **result, swig_type_info *type)
 
181
{
 
182
  if (SCHEME_NULLP(s)) {
 
183
    *result = NULL;
 
184
    return 0;
 
185
  }
 
186
  else if (SCHEME_TYPE(s) == swig_type) {
 
187
    struct swig_proxy *proxy = (struct swig_proxy *) s;
 
188
    if (type) {
 
189
      return !SWIG_Cast(proxy->object, proxy->ptrtype,
 
190
                        result, type->ptrtype);
 
191
    }
 
192
    else {
 
193
      *result = proxy->object;
 
194
      return 0;
 
195
    }
 
196
  }
 
197
  return -1;
 
198
}
 
199
 
 
200
SWIGSTATIC void *
 
201
SWIG_MustGetPtr_ (Scheme_Object *s,  swig_type_info *type,
 
202
                  int argnum, const char *func_name,
 
203
                  int argc, Scheme_Object **argv)
 
204
{
 
205
  void *result;
 
206
  if (SWIG_GetPtr(s, &result, type) != 0) {
 
207
    /* type mismatch */
 
208
    scheme_wrong_type(func_name, type->str, argnum, argc, argv);
 
209
  }
 
210
  return result;
 
211
}
 
212
 
 
213
SWIGSTATIC
 
214
void SWIG_RegisterTypes(swig_type_info **table,
 
215
                        swig_type_info **init)
 
216
{
 
217
  if (!swig_initialized_p) {
 
218
    swig_type = scheme_make_type((char *) "swig");
 
219
    swig_initialized_p = 1;
 
220
  }
 
221
  for (; *init; table++, init++) {
 
222
    swig_type_info *type = *table = *init;
 
223
    const char *origname = type->name;
 
224
    /* Register datatype itself and store pointer back */
 
225
    type->ptrtype = SWIG_RegisterType(origname, type->str);
 
226
    /* Register compatible types */
 
227
    for (type++; type->name; type++)
 
228
      SWIG_RegisterMapping(origname, type->name, type->converter);
 
229
  }    
 
230
}
 
231
 
 
232
static Scheme_Object *
 
233
swig_package_values(int num, Scheme_Object **values)
 
234
{
 
235
    /* ignore first value if void */
 
236
    if (num > 0 && SCHEME_VOIDP(values[0]))
 
237
        num--, values++;
 
238
    if (num == 0) return scheme_void;
 
239
    else if (num == 1) return values[0];
 
240
    else return scheme_values(num, values);
 
241
}
 
242
 
 
243
static void *
 
244
swig_malloc(size_t size, const char *func_name)
 
245
{
 
246
  void *p = malloc(size);
 
247
  if (p == NULL) {
 
248
    scheme_signal_error("swig-memory-error");
 
249
  }
 
250
  else return p;
 
251
}
 
252
 
 
253
#ifdef __cplusplus
 
254
}
 
255
#endif
 
256