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

« back to all changes in this revision

Viewing changes to Lib/chicken/chicken.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:
11
11
%}
12
12
 
13
13
%insert(runtime) "swigrun.swg";            // Common C API type-checking code
14
 
%insert(runtime) "common.swg";          // Common type-checking code
15
14
%insert(runtime) "chickenrun.swg";      // CHICKEN run-time code
16
15
 
17
16
/* -----------------------------------------------------------------------------
79
78
  $result = to_scheme (convtype ($varname));
80
79
%}
81
80
 
 
81
%typemap(throws) type_
 
82
%{
 
83
  SWIG_Chicken_ThrowException(to_scheme ( convtype ($1)));
 
84
%}
 
85
 
82
86
#else
83
87
 
84
88
%typemap(out) type_ 
85
89
%{
 
90
  {
86
91
  C_word *space = C_alloc(storage_);
87
92
  $result = to_scheme (&space, convtype ($1));
 
93
  }
88
94
%}
89
95
 
90
96
/* References to primitive types.  Return by value */
91
97
 
92
98
%typemap(out) const type_ &
93
99
%{
94
 
  $result = to_scheme (convtype (*$1));
 
100
  {
 
101
  C_word *space = C_alloc(storage_);
 
102
  $result = to_scheme (&space, convtype (*$1));
 
103
  }
95
104
%}
96
105
 
97
106
/* --- Variable output --- */
98
107
%typemap(varout) type_ 
99
108
%{
 
109
  {
100
110
  C_word *space = C_alloc(storage_);
101
111
  $result = to_scheme (&space, convtype ($varname));
 
112
  }
 
113
%}
 
114
 
 
115
%typemap(throws) type_
 
116
%{
 
117
  {
 
118
  C_word *space = C_alloc(storage_);
 
119
  SWIG_Chicken_ThrowException(to_scheme (&space, convtype ($1)));
 
120
  }
102
121
%}
103
122
 
104
123
#endif
105
124
 
106
125
/* --- Constants --- */
107
126
 
108
 
#if ("type_" == "char") || ("type_" == "unsigned char") || ("type_" == "signed char")
109
 
%typemap(constcode) type_
110
 
"static const $1_type $result = '$value';"
111
 
#else
112
127
%typemap(constcode) type_
113
128
"static const $1_type $result = $value;"
114
 
#endif
115
129
 
116
130
%enddef
117
131
 
118
 
SIMPLE_TYPEMAP(int, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
119
 
SIMPLE_TYPEMAP(enum SWIGTYPE, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
120
 
SIMPLE_TYPEMAP(short, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
121
 
SIMPLE_TYPEMAP(long, C_flonum_magnitude, C_flonum, C_swig_is_flonum, (double), C_SIZEOF_FLONUM);
122
 
SIMPLE_TYPEMAP(long long, C_flonum_magnitude, C_flonum, C_swig_is_flonum, (double), C_SIZEOF_FLONUM);
123
 
SIMPLE_TYPEMAP(unsigned int, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
124
 
SIMPLE_TYPEMAP(unsigned short, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
125
 
SIMPLE_TYPEMAP(unsigned long, C_flonum_magnitude, C_flonum, C_swig_is_flonum, (double), C_SIZEOF_FLONUM);
126
 
SIMPLE_TYPEMAP(unsigned long long, C_flonum_magnitude, C_flonum, C_swig_is_flonum, (double), C_SIZEOF_FLONUM);
127
 
SIMPLE_TYPEMAP(unsigned char, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
128
 
SIMPLE_TYPEMAP(signed char, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
 
132
SIMPLE_TYPEMAP(int, C_num_to_int, C_fix, C_swig_is_number, (int), 0);
 
133
//SIMPLE_TYPEMAP(enum SWIGTYPE, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
 
134
SIMPLE_TYPEMAP(short, C_num_to_int, C_fix, C_swig_is_number, (int), 0);
 
135
SIMPLE_TYPEMAP(long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
 
136
SIMPLE_TYPEMAP(long long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
 
137
SIMPLE_TYPEMAP(unsigned int, C_num_to_unsigned_int, C_fix, C_swig_is_number, (int), 0);
 
138
SIMPLE_TYPEMAP(unsigned short, C_num_to_unsigned_int, C_fix, C_swig_is_number, (int), 0);
 
139
SIMPLE_TYPEMAP(unsigned long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
 
140
SIMPLE_TYPEMAP(unsigned long long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
 
141
SIMPLE_TYPEMAP(unsigned char, C_character_code, C_make_character, C_swig_is_char, (unsigned int), 0);
 
142
SIMPLE_TYPEMAP(signed char, C_character_code, C_make_character, C_swig_is_char, (int), 0);
129
143
SIMPLE_TYPEMAP(char, C_character_code, C_make_character, C_swig_is_char, (char), 0);
130
144
SIMPLE_TYPEMAP(bool, C_truep, C_mk_bool, C_swig_is_bool, (bool), 0);
131
 
SIMPLE_TYPEMAP(float, C_flonum_magnitude, C_flonum, C_swig_is_flonum, (double), C_SIZEOF_FLONUM);
132
 
SIMPLE_TYPEMAP(double, C_flonum_magnitude, C_flonum, C_swig_is_flonum, (double), C_SIZEOF_FLONUM);
 
145
SIMPLE_TYPEMAP(float, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEOF_FLONUM);
 
146
SIMPLE_TYPEMAP(double, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEOF_FLONUM);
 
147
 
 
148
/* enum SWIGTYPE */
 
149
%apply int { enum SWIGTYPE };
 
150
%apply const int& { const enum SWIGTYPE& };
 
151
 
 
152
%typemap(varin) enum SWIGTYPE
 
153
{
 
154
  if (!C_swig_is_fixnum($input) && sizeof(int) != sizeof($1)) {
 
155
    swig_barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, "enum variable '$name' can not be set");
 
156
  }
 
157
  *((int *)(void *)&$1) = C_unfix($input);
 
158
}
 
159
 
133
160
 
134
161
/* --- Input arguments --- */
135
162
 
150
177
%typemap(freearg) char * "if ($1 != NULL) { free ($1); }"
151
178
 
152
179
/* Pointers, references, and arrays */
153
 
%typemap(in) SWIGTYPE *, SWIGTYPE [], SWIGTYPE &  {
154
 
   $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, 0);
 
180
%typemap(in,closcode="(slot-ref $input 'swig-this)") SWIGTYPE *, SWIGTYPE [], SWIGTYPE &  {
 
181
   $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, $disown);
 
182
}
 
183
 
 
184
%typemap(in,closcode="(slot-ref $input 'swig-this)") SWIGTYPE *DISOWN {
 
185
  $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, SWIG_POINTER_DISOWN);
155
186
}
156
187
 
157
188
/* Void pointer.  Accepts any kind of pointer */
160
191
}
161
192
 
162
193
%typemap(varin) SWIGTYPE * {
163
 
  $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, 0);
 
194
  $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, SWIG_POINTER_DISOWN);
164
195
}
165
196
 
166
197
%typemap(varin) SWIGTYPE & {
184
215
  $1 = SWIG_MustGetPtr($input, NULL, 1, 0);
185
216
}
186
217
 
187
 
%typemap(out) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
 
218
%typemap(out,chickenfastproxy="1") SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
188
219
  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
189
 
  $result = SWIG_NewPointerObj ($1, $descriptor, $owner);
 
220
  $result = SWIG_NewPointerObjProxy($1, $descriptor, $owner, $proxy);
190
221
}
191
222
 
192
 
%typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC {
 
223
%typemap(out,chickenfastproxy="1") SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC {
193
224
  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
194
225
  swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor,(void **) &$1);
195
 
  $result = SWIG_NewPointerObj ($1, ty, $owner);
 
226
  $result = SWIG_NewPointerObjProxy($1, ty, $owner, $proxy);
196
227
}
197
228
    
198
 
%typemap(varout) SWIGTYPE *, SWIGTYPE [] {
 
229
%typemap(varout,chickenfastproxy="1") SWIGTYPE *, SWIGTYPE [] {
199
230
  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
200
 
  $result = SWIG_NewPointerObj ($varname, $descriptor, 0);
 
231
  $result = SWIG_NewPointerObjProxy($varname, $descriptor, 0, 0);
201
232
}
202
233
 
203
 
%typemap(varout) SWIGTYPE & {
 
234
%typemap(varout,chickenfastproxy="1") SWIGTYPE & {
204
235
  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
205
 
  $result = SWIG_NewPointerObj((void *) &$varname, $1_descriptor, 0);
 
236
  $result = SWIG_NewPointerObjProxy((void *) &$varname, $1_descriptor, 0, 0);
206
237
}
207
238
 
208
239
/* Pass-by-value */
209
240
 
210
 
%typemap(in) SWIGTYPE($&1_ltype argp) {
 
241
%typemap(in,closcode="(slot-ref $input 'swig-this)") SWIGTYPE($&1_ltype argp) {
211
242
  argp = ($&1_ltype)SWIG_MustGetPtr($input, $&1_descriptor, $argnum, 0);
212
243
  $1 = *argp;
213
244
}
218
249
  $1 = *argp;
219
250
}
220
251
 
221
 
%typemap(out) SWIGTYPE 
 
252
%typemap(out,chickenfastproxy="1") SWIGTYPE 
222
253
#ifdef __cplusplus
223
254
{
224
255
  $&1_ltype resultptr;
225
256
  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
226
257
  resultptr = new $1_ltype(($1_ltype &) $1);
227
 
  $result =  SWIG_NewPointerObj (resultptr, $&1_descriptor, 1);
 
258
  $result =  SWIG_NewPointerObjProxy(resultptr, $&1_descriptor, 1, $proxy);
228
259
229
260
#else
230
261
{
232
263
  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
233
264
  resultptr = ($&1_ltype) malloc(sizeof($1_type));
234
265
  memmove(resultptr, &$1, sizeof($1_type));
235
 
  $result = SWIG_NewPointerObj(resultptr, $&1_descriptor, 1);
 
266
  $result = SWIG_NewPointerObjProxy(resultptr, $&1_descriptor, 1,$proxy);
236
267
}
237
268
#endif
238
269
 
239
 
%typemap(varout) SWIGTYPE 
 
270
%typemap(varout,chickenfastproxy="1") SWIGTYPE 
240
271
#ifdef __cplusplus
241
272
{
242
273
  $&1_ltype resultptr;
243
274
  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
244
275
  resultptr = new $1_ltype(($1_ltype&) $1);
245
 
  $result =  SWIG_NewPointerObj (resultptr, $&1_descriptor, 0);
 
276
  $result =  SWIG_NewPointerObjProxy(resultptr, $&1_descriptor, 0, 0);
246
277
247
278
#else
248
279
{
250
281
  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
251
282
  resultptr = ($&1_ltype) malloc(sizeof($1_type));
252
283
  memmove(resultptr, &$1, sizeof($1_type));
253
 
  $result = SWIG_NewPointerObj(resultptr, $&1_descriptor, 0);
 
284
  $result = SWIG_NewPointerObjProxy(resultptr, $&1_descriptor, 0, 0);
254
285
}
255
286
#endif
256
287
 
284
315
  }
285
316
}
286
317
 
 
318
%typemap(throws) char *
 
319
 
320
  if ($1 == NULL) {
 
321
    SWIG_Chicken_ThrowException(C_SCHEME_FALSE);
 
322
  } else {
 
323
    int string_len = strlen($1);
 
324
    C_word *string_space = C_alloc(C_SIZEOF_STRING(string_len));
 
325
    SWIG_Chicken_ThrowException(C_string(&string_space, string_len, (char *) $1));
 
326
  }
 
327
}
 
328
 
287
329
/* Void */
288
330
%typemap(out) void
289
331
%{
374
416
}
375
417
#endif
376
418
 
 
419
%typemap(varin) char [] {
 
420
  swig_barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, "C/C++ variable '$name' is read-only");
 
421
}
 
422
 
377
423
/* Special case for string array variables */
378
424
%typemap(varin) char [ANY] {
379
425
  if ($input == C_SCHEME_FALSE) {
380
 
    $1 = NULL;
 
426
    memset($1,0,$1_dim0*sizeof(char));
381
427
  }
382
428
  else if (!C_swig_is_string ($input)) {
383
429
    swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "C variable '$name ($1_ltype)'");
384
430
  }
385
431
  else {
386
432
    char *temp = C_c_string ($input);
387
 
    strncpy($1,temp,$1_dim0);
 
433
    strncpy($1,temp,$1_dim0*sizeof(char));
388
434
  }
389
435
}
390
436
 
395
441
 
396
442
/* Special typemap for character array return values */
397
443
%typemap(varout) char [ANY], const char [ANY] 
398
 
%{  if ($varname == C_SCHEME_FALSE) {
399
 
    $result = NULL;
400
 
  }
401
 
  else if (C_swig_is_string ($varname)) {
402
 
    $result = SWIG_MakeString ($varname);
 
444
%{  if ($varname == NULL) {
 
445
    $result = C_SCHEME_FALSE;
403
446
  }
404
447
  else {
405
 
     swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument #$argnum is not of type 'string'");    
406
 
  } %}
 
448
   const int string_len = strlen ($varname);
 
449
   C_word *string_space = C_alloc (C_SIZEOF_STRING (string_len));
 
450
   $result = C_string (&string_space, string_len, (char *) $varname);
 
451
  }
 
452
%}
407
453
 
408
454
 
409
455
/* --- Constants --- */
410
456
 
411
457
%typemap(constcode) char *
412
 
"static const char *$result = \"$value\";"
 
458
"static const char *$result = $value;"
413
459
 
414
460
%typemap(constcode) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
415
461
"static const void *$result = (void*) $value;"
435
481
}
436
482
 
437
483
/* ------------------------------------------------------------
438
 
 * ANSI C typemaps
439
 
 * ------------------------------------------------------------ */
440
 
 
441
 
%apply unsigned long { size_t };
442
 
 
443
 
/* ------------------------------------------------------------
444
484
 * CHICKEN types
445
485
 * ------------------------------------------------------------ */
446
486
 
506
546
  $1 = !SWIG_ConvertPtr($input, &ptr, 0, 0);
507
547
}
508
548
 
 
549
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE &
 
550
{
 
551
  void *ptr = 0;
 
552
  if (SWIG_ConvertPtr($input, &ptr, $descriptor, 0)) {
 
553
    /* error */
 
554
    $1 = 0;
 
555
  } else {
 
556
    $1 = (ptr != 0);
 
557
  }
 
558
}
 
559
 
 
560
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE 
 
561
{
 
562
  void *ptr = 0;
 
563
  if (SWIG_ConvertPtr($input, &ptr, $&descriptor, 0)) {
 
564
    /* error */
 
565
    $1 = 0;
 
566
  } else {
 
567
    $1 = (ptr != 0);
 
568
  }
 
569
}
 
570
 
 
571
 
509
572
/* ------------------------------------------------------------
510
573
 * Exception handling
511
574
 * ------------------------------------------------------------ */
512
575
 
513
 
/* TODO */
 
576
/* ------------------------------------------------------------
 
577
 * --- Exception handling ---
 
578
 * ------------------------------------------------------------ */
 
579
 
 
580
%typemap(throws) SWIGTYPE {
 
581
  $&ltype temp = new $ltype($1);
 
582
  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
 
583
  C_word ptr = SWIG_NewPointerObj(temp, $&descriptor,1);
 
584
  SWIG_Chicken_ThrowException(ptr);
 
585
}
 
586
 
 
587
%typemap(throws) SWIGTYPE * {
 
588
  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
 
589
  C_word ptr = SWIG_NewPointerObj((void *) $1, $descriptor, 0);
 
590
  SWIG_Chicken_ThrowException(ptr);
 
591
}
 
592
 
 
593
%typemap(throws) SWIGTYPE [ANY] {
 
594
  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
 
595
  C_word ptr = SWIG_NewPointerObj((void *) $1, $descriptor, 0);
 
596
  SWIG_Chicken_ThrowException(ptr);
 
597
}
 
598
 
 
599
%typemap(throws) SWIGTYPE & {
 
600
  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
 
601
  C_word ptr = SWIG_NewPointerObj((void *)&($1),$descriptor,0);
 
602
  SWIG_Chicken_ThrowException(ptr);
 
603
}
 
604
 
 
605
/* ------------------------------------------------------------
 
606
 * ANSI C typemaps
 
607
 * ------------------------------------------------------------ */
 
608
 
 
609
%apply unsigned long { size_t };
514
610
 
515
611
/* ------------------------------------------------------------
516
612
 * Overloaded operator support
575
671
extern "C" {
576
672
#endif
577
673
/* Chicken initialization function */
578
 
SWIGEXPORT(void) SWIG_init(int, C_word, C_word) C_noret;
 
674
SWIGEXPORT void SWIG_init(C_word, C_word, C_word) C_noret;
579
675
#ifdef __cplusplus
580
676
}
581
677
#endif
583
679
 
584
680
%insert(closprefix) "swigclosprefix.scm"
585
681
 
 
682
%insert(init) "swiginit.swg"
 
683
 
586
684
%insert(init) %{
587
685
/* CHICKEN initialization function */
588
 
static char *swig_type_ptr_name = "type_pointer" SWIG_TYPE_TABLE_NAME;
589
 
SWIGEXPORT(void)
590
 
SWIG_init(int argc, C_word closure, C_word continuation) {
591
 
  static int       typeinit = 0;
 
686
#ifdef __cplusplus
 
687
extern "C" {
 
688
#endif
 
689
SWIGEXPORT void SWIG_init(C_word argc, C_word closure, C_word continuation) {
592
690
  int       i;
593
691
  C_word sym;
594
692
  C_word tmp;
596
694
  C_word ret;
597
695
  C_word *return_vec;
598
696
 
599
 
  if (!typeinit) {
600
 
    /* lookup the type pointer... it is stored in it's own symbol table */
601
 
    C_SYMBOL_TABLE *stable = C_find_symbol_table("swig_runtime_data" SWIG_RUNTIME_VERSION);
602
 
    if (stable != NULL) {
603
 
      sym = SWIG_Chicken_LookupSymbol(swig_type_ptr_name, stable);
604
 
      if (C_truep(sym) && C_swig_is_ptr(sym)) {
605
 
        swig_type_list_handle = (swig_type_info **) C_block_item(sym, 0);
606
 
      }
607
 
    } else {
608
 
      C_word *a = C_alloc(C_SIZEOF_POINTER + C_SIZEOF_INTERNED_SYMBOL(C_strlen(swig_type_ptr_name)));
609
 
      stable = C_new_symbol_table("swig_runtime_data" SWIG_RUNTIME_VERSION, 16);
610
 
      sym = C_intern_in(&a, C_strlen(swig_type_ptr_name), swig_type_ptr_name, stable);
611
 
      C_mutate(&C_block_item(sym, 0), C_mpointer(&a, (void *) swig_type_list_handle));
612
 
    }
613
 
    
614
 
    for (i = 0; swig_types_initial[i]; i++) {
615
 
      swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]);
616
 
    }
617
 
    for (i = 0; swig_types_initial[i]; i++) {
618
 
      SWIG_PropagateClientData(swig_types[i]);
619
 
    }
620
 
    typeinit = 1;
621
 
    ret = C_SCHEME_TRUE;
622
 
  } else {
623
 
    ret = C_SCHEME_FALSE;
624
 
  }
 
697
  SWIG_InitializeModule(0);
 
698
  SWIG_PropagateClientData();
 
699
  ret = C_SCHEME_TRUE;
625
700
  
626
701
#if $veclength
627
702
  return_vec = C_alloc(C_SIZEOF_VECTOR($veclength));