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

« back to all changes in this revision

Viewing changes to Lib/guile/typemaps.i

  • 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
/* typemaps.i --- guile-specific typemaps -*- c -*-
 
2
   Copyright (C) 2000 Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de>
 
3
 
 
4
   $Header: /cvs/projects/SWIG/Lib/guile/typemaps.i,v 1.17.2.6.2.8 2002/01/28 03:39:30 beazley Exp $  */
 
5
 
 
6
/* (11/24/2001) Note to Matthias:
 
7
 
 
8
   I've replaced all of the documentation related typemaps (indoc, varindoc, outdoc, argoutdoc, ...)
 
9
   with a typemap parameter of "doc".  For example:
 
10
 
 
11
   %typemap(in, doc="<integer>") int {
 
12
      ...
 
13
   }
 
14
 
 
15
   This is somewhat more sane to handle when multi-argument typemaps are used.  For example:
 
16
 
 
17
   %typemap(in, doc="<buffer>") (char *data, int len) {
 
18
       ...
 
19
   }
 
20
 
 
21
   See guile.cxx for details of how the typemap parameters actually get accessed.
 
22
 
 
23
   Also, it's no longer necessary to specify typemaps for 'const' qualifiers.  They
 
24
   now get matched against non-const versions.
 
25
 
 
26
   Feel free to delete this comment after you've read it.
 
27
 
 
28
                         --- Dave
 
29
*/
 
30
 
 
31
/* Pointers */
 
32
 
 
33
%typemap(in) SWIGTYPE * {
 
34
  if (SWIG_Guile_GetPtr($input, (void **) &$1, $descriptor))
 
35
    scm_wrong_type_arg(FUNC_NAME, $argnum, $input);
 
36
}
 
37
 
 
38
%typemap(in) void * {
 
39
  if (SWIG_Guile_GetPtr($input, (void **) &$1, NULL))
 
40
    scm_wrong_type_arg(FUNC_NAME, $argnum, $input);
 
41
}
 
42
 
 
43
%typemap(varin) SWIGTYPE * {
 
44
  if (SWIG_Guile_GetPtr($input, (void **) &$1, $descriptor))
 
45
    scm_wrong_type_arg(FUNC_NAME, 1, $input);
 
46
}
 
47
 
 
48
%typemap(varin) void * {
 
49
  if (SWIG_Guile_GetPtr($input, (void **) &$1, NULL))
 
50
    scm_wrong_type_arg(FUNC_NAME, 1, $input);
 
51
}
 
52
 
 
53
%typemap(out) SWIGTYPE * {
 
54
    $result = SWIG_Guile_MakePtr ($1, $descriptor);
 
55
}
 
56
    
 
57
%typemap(varout) SWIGTYPE * {
 
58
    $result = SWIG_Guile_MakePtr ($1, $descriptor);
 
59
}
 
60
 
 
61
/* Pass-by-value */
 
62
 
 
63
%typemap(in) SWIGTYPE($&1_ltype argp) {
 
64
  if (SWIG_Guile_GetPtr($input, (void **) &argp, $1_descriptor))
 
65
    scm_wrong_type_arg(FUNC_NAME,$argnum,$input);
 
66
  $1 = *argp;
 
67
}
 
68
 
 
69
%typemap(varin) SWIGTYPE {
 
70
  $&1_ltype argp;
 
71
  if (SWIG_Guile_GetPtr($input, (void **) &argp, $1_descriptor))
 
72
    scm_wrong_type_arg(FUNC_NAME,1,$input);
 
73
  $1 = *argp;
 
74
}
 
75
 
 
76
%typemap(out) SWIGTYPE 
 
77
#ifdef __cplusplus
 
78
{
 
79
  $&1_ltype resultptr;
 
80
  resultptr = new $1_ltype($1);
 
81
  $result =  SWIG_Guile_MakePtr (resultptr, $&1_descriptor);
 
82
 
83
#else
 
84
{
 
85
  $&1_ltype resultptr;
 
86
  resultptr = ($&1_ltype) malloc(sizeof($1_type));
 
87
  memmove(resultptr, &$1, sizeof($1_type));
 
88
  $result = SWIG_Guile_MakePtr(resultptr, $&1_descriptor);
 
89
}
 
90
#endif
 
91
 
 
92
%typemap(varout) SWIGTYPE 
 
93
#ifdef __cplusplus
 
94
{
 
95
  $&1_ltype resultptr;
 
96
  resultptr = new $1_ltype($1);
 
97
  $result =  SWIG_Guile_MakePtr (resultptr, $&1_descriptor);
 
98
 
99
#else
 
100
{
 
101
  $&1_ltype resultptr;
 
102
  resultptr = ($&1_ltype) malloc(sizeof($1_type));
 
103
  memmove(resultptr, &$1, sizeof($1_type));
 
104
  $result = SWIG_Guile_MakePtr(resultptr, $&1_descriptor);
 
105
}
 
106
#endif
 
107
 
 
108
/* C++ References */
 
109
 
 
110
#ifdef __cplusplus
 
111
 
 
112
%typemap(in) SWIGTYPE & {
 
113
  if (SWIG_Guile_GetPtr($input, (void **) &$1, $descriptor)!=0)
 
114
    scm_wrong_type_arg(FUNC_NAME, $argnum, $input);
 
115
}
 
116
 
 
117
%typemap(out) SWIGTYPE & {
 
118
  $result = SWIG_Guile_MakePtr ($1, $descriptor);
 
119
}
 
120
 
 
121
#endif
 
122
 
 
123
/* Arrays */
 
124
 
 
125
%typemap(in) SWIGTYPE[] {
 
126
  if (SWIG_Guile_GetPtr($input, (void **) &$1, $descriptor)!=0)
 
127
    scm_wrong_type_arg(FUNC_NAME, $argnum, $input);
 
128
}
 
129
 
 
130
%typemap(out) SWIGTYPE[] {
 
131
  $result = SWIG_Guile_MakePtr ($1, $descriptor);
 
132
}
 
133
 
 
134
/* Enums */
 
135
 
 
136
%typemap(in)     enum SWIGTYPE "$1 = gh_scm2int($input);";
 
137
%typemap(varin)  enum SWIGTYPE "$1 = gh_scm2int($input);";
 
138
%typemap(out)    enum SWIGTYPE "$result = gh_int2scm($1);";
 
139
%typemap(varout) enum SWIGTYPE "$result = gh_int2scm($1);";
 
140
 
 
141
/* The SIMPLE_MAP macro below defines the whole set of typemaps needed
 
142
   for simple types. */
 
143
 
 
144
%define SIMPLE_MAP(C_NAME, SCM_TO_C, C_TO_SCM, SCM_NAME)
 
145
 %typemap (in,     doc="($name <" #SCM_NAME ">)")      C_NAME {$1 = SCM_TO_C($input);}
 
146
 %typemap (varin,  doc="(new-value <" #SCM_NAME ">)")  C_NAME {$1 = SCM_TO_C($input);}
 
147
 %typemap (out,    doc="<" #SCM_NAME ">")              C_NAME {$result = C_TO_SCM($1);}
 
148
 %typemap (varout, doc="<" #SCM_NAME ">")              C_NAME {$result = C_TO_SCM($1);}
 
149
 %typemap (in, doc="($name <" #SCM_NAME ">)") C_NAME *INPUT(C_NAME temp) {
 
150
   temp = (C_NAME) SCM_TO_C($input); $1 = &temp;
 
151
 }
 
152
 %typemap (ignore)      C_NAME *OUTPUT (C_NAME temp)
 
153
   {$1 = &temp;}
 
154
 %typemap (argout,doc="($name <" #SCM_NAME ">)") C_NAME *OUTPUT
 
155
   {SWIG_APPEND_VALUE(C_TO_SCM(*$1));}
 
156
 
 
157
 %typemap (in)          C_NAME *BOTH = C_NAME *INPUT;
 
158
 %typemap (argout)      C_NAME *BOTH = C_NAME *OUTPUT;
 
159
 %typemap (in)          C_NAME *INOUT = C_NAME *INPUT;
 
160
 %typemap (argout)      C_NAME *INOUT = C_NAME *OUTPUT;
 
161
%enddef
 
162
 
 
163
 SIMPLE_MAP(bool, gh_scm2bool, gh_bool2scm, boolean);
 
164
 SIMPLE_MAP(char, gh_scm2char, gh_char2scm, char);
 
165
 SIMPLE_MAP(unsigned char, gh_scm2char, gh_char2scm, char);
 
166
 SIMPLE_MAP(int, gh_scm2int, gh_int2scm, integer);
 
167
 SIMPLE_MAP(short, gh_scm2int, gh_int2scm, integer);
 
168
 SIMPLE_MAP(long, gh_scm2long, gh_long2scm, integer);
 
169
 SIMPLE_MAP(ptrdiff_t, gh_scm2long, gh_long2scm, integer);
 
170
 SIMPLE_MAP(unsigned int, gh_scm2ulong, gh_ulong2scm, integer);
 
171
 SIMPLE_MAP(unsigned short, gh_scm2ulong, gh_ulong2scm, integer);
 
172
 SIMPLE_MAP(unsigned long, gh_scm2ulong, gh_ulong2scm, integer);
 
173
 SIMPLE_MAP(size_t, gh_scm2ulong, gh_ulong2scm, integer);
 
174
 SIMPLE_MAP(float, gh_scm2double, gh_double2scm, real);
 
175
 SIMPLE_MAP(double, gh_scm2double, gh_double2scm, real);
 
176
 SIMPLE_MAP(char *, SWIG_scm2str, gh_str02scm, string);
 
177
 SIMPLE_MAP(const char *, SWIG_scm2str, gh_str02scm, string);
 
178
 
 
179
/* GSWIG_scm2str makes a malloc'ed copy of the string, so get rid of it after
 
180
   the function call. */
 
181
 
 
182
%typemap (freearg) char * "if ($1) scm_must_free($1);";
 
183
%typemap (freearg) char **OUTPUT, char **BOTH "if (*$1) scm_must_free(*$1);"
 
184
 
 
185
/* But this shall not apply if we try to pass a single char by
 
186
   reference. */
 
187
 
 
188
%typemap (freearg) char *OUTPUT, char *BOTH "";
 
189
 
 
190
/* If we set a string variable, delete the old result first. */
 
191
 
 
192
%typemap (varin) char * {
 
193
    if ($1) free($1);
 
194
    $1 = SWIG_scm2str($input);
 
195
}
 
196
 
 
197
/* Void */
 
198
 
 
199
%typemap (out,doc="") void "gswig_result = GH_UNSPECIFIED;";
 
200
 
 
201
/* SCM is passed through */
 
202
 
 
203
typedef unsigned long SCM;
 
204
%typemap (in) SCM "$1=$input;";
 
205
%typemap (out) SCM "$result=$1;";
 
206
 
 
207
/* Some ANSI C typemaps */
 
208
 
 
209
%apply long { size_t };
 
210
 
 
211
/* typemaps.i ends here */
 
212
 
 
213
 
 
214
 
 
215
 
 
216