Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * php4.swg | |
3 | * | |
4 | * PHP 4 configuration file | |
5 | * | |
6 | */ | |
7 | ||
8 | %runtime "swigrun.swg" // Common C API type-checking code | |
9 | %runtime "php4run.swg" // Php4 runtime functions | |
10 | ||
11 | %include "php4init.swg" // Php4 initialization routine. | |
12 | ||
13 | %include "globalvar.i" // Global variables. | |
14 | %include "const.i" | |
15 | ||
16 | // use %init %{ "/*code goes here*/ " %} | |
17 | // or %minit %{ "/* code goes here*/ " %} to | |
18 | // insert code in the PHP_MINIT_FUNCTION | |
19 | #define %minit %insert("init") | |
20 | ||
21 | // use %rinit %{ "/* code goes here*/ " %} to | |
22 | // insert code in the PHP_RINIT_FUNCTION | |
23 | #define %rinit %insert("rinit") | |
24 | ||
25 | // use %shutdown %{ " /*code goes here*/ " %} to | |
26 | // insert code in the PHP_MSHUTDOWN_FUNCTION | |
27 | #define %shutdown %insert("shutdown") | |
28 | #define %mshutdown %insert("shutdown") | |
29 | ||
30 | // use %rshutdown %{ " /*code goes here*/" %} to | |
31 | // insert code in the PHP_RSHUTDOWN_FUNCTION | |
32 | #define %rshutdown %insert("rshutdown") | |
33 | ||
34 | /* Typemaps for input parameters by value */ | |
35 | ||
36 | %include "utils.i" | |
37 | ||
38 | %pass_by_val(bool,CONVERT_BOOL_IN); | |
39 | ||
40 | %pass_by_val(size_t, CONVERT_INT_IN); | |
41 | ||
42 | %pass_by_val(enum SWIGTYPE, CONVERT_INT_IN); | |
43 | ||
44 | %pass_by_val(signed int, CONVERT_INT_IN); | |
45 | %pass_by_val(int,CONVERT_INT_IN); | |
46 | %pass_by_val(unsigned int,CONVERT_INT_IN); | |
47 | ||
48 | %pass_by_val(signed short, CONVERT_INT_IN); | |
49 | %pass_by_val(short,CONVERT_INT_IN); | |
50 | %pass_by_val(unsigned short, CONVERT_INT_IN); | |
51 | ||
52 | %pass_by_val(signed long, CONVERT_INT_IN); | |
53 | %pass_by_val(long, CONVERT_INT_IN); | |
54 | %pass_by_val(unsigned long, CONVERT_INT_IN); | |
55 | ||
56 | %pass_by_val(signed char, CONVERT_INT_IN); | |
57 | %pass_by_val(char, CONVERT_CHAR_IN); | |
58 | %pass_by_val(unsigned char, CONVERT_INT_IN); | |
59 | ||
60 | %pass_by_val(float, CONVERT_FLOAT_IN); | |
61 | ||
62 | %pass_by_val(double, CONVERT_FLOAT_IN); | |
63 | ||
64 | %pass_by_val(char *, CONVERT_STRING_IN); | |
65 | ||
66 | // char array can be in/out, though the passed string may not be big enough... | |
67 | // so we have to size it | |
68 | %typemap(in) char[ANY] | |
69 | { | |
70 | convert_to_string_ex($input); | |
71 | $1 = ($1_ltype) Z_STRVAL_PP($input); | |
72 | } | |
73 | ||
74 | /* Object passed by value. Convert to a pointer */ | |
75 | %typemap(in) SWIGTYPE ($&1_ltype tmp) | |
76 | { | |
77 | if(SWIG_ConvertPtr(*$input, (void **) &tmp, $&1_descriptor, 0) < 0) { | |
78 | SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); | |
79 | } | |
80 | $1 = *tmp; | |
81 | } | |
82 | ||
83 | %typemap(in) SWIGTYPE *, | |
84 | SWIGTYPE [], | |
85 | SWIGTYPE & | |
86 | { | |
87 | /* typemap(in) SWIGTYPE * */ | |
88 | if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, 0) < 0) { | |
89 | SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); | |
90 | } | |
91 | } | |
92 | %typemap(in) SWIGTYPE *DISOWN | |
93 | { | |
94 | /* typemap(in) SWIGTYPE *DISOWN */ | |
95 | if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) { | |
96 | SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); | |
97 | } | |
98 | } | |
99 | %typemap(argout) SWIGTYPE *, | |
100 | SWIGTYPE [], | |
101 | SWIGTYPE&; | |
102 | ||
103 | %typemap(in) void * | |
104 | { | |
105 | if(SWIG_ConvertPtr(*$input, (void **) &$1, 0, 0) < 0) { | |
106 | /* Allow NULL from php for void* */ | |
107 | if ((*$input)->type==IS_NULL) $1=0; | |
108 | else | |
109 | SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); | |
110 | } | |
111 | } | |
112 | ||
113 | /* Special case when void* is passed by reference so it can be made to point | |
114 | to opaque api structs */ | |
115 | %typemap(in) void ** ($*1_ltype ptr, int force), | |
116 | void *& ($*1_ltype ptr, int force) | |
117 | { | |
118 | /* If they pass NULL by reference, make it into a void* | |
119 | This bit should go in arginit if arginit support init-ing scripting args */ | |
120 | if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, 0) < 0) { | |
121 | /* So... we didn't get a ref or ptr, but we'll accept NULL by reference */ | |
122 | if ((*$input)->type==IS_NULL && PZVAL_IS_REF(*$input)) { | |
123 | #ifdef __cplusplus | |
124 | ptr=new $*1_ltype; | |
125 | #else | |
126 | ptr=($*1_ltype) calloc(1,sizeof($*1_ltype)); | |
127 | #endif | |
128 | $1=&ptr; | |
129 | /* have to passback arg$arg too */ | |
130 | force=1; | |
131 | } else { /* wasn't a pre/ref/thing, OR anything like an int thing */ | |
132 | force=0; | |
133 | SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); | |
134 | } | |
135 | } else force=0; | |
136 | } | |
137 | %typemap(argout) void **, | |
138 | void *& | |
139 | { | |
140 | if (force$argnum) { | |
141 | SWIG_SetPointerZval( *$input, (void*) ptr$argnum, $*1_descriptor, 1); | |
142 | } | |
143 | } | |
144 | ||
145 | /* Typemap for output values */ | |
146 | ||
147 | %typemap(out) int, | |
148 | unsigned int, | |
149 | short, | |
150 | unsigned short, | |
151 | long, | |
152 | unsigned long, | |
153 | signed char, | |
154 | unsigned char, | |
155 | bool, | |
156 | size_t, | |
157 | enum SWIGTYPE | |
158 | { | |
159 | ZVAL_LONG(return_value,$1); | |
160 | } | |
161 | ||
162 | %typemap(out) bool | |
163 | { | |
164 | ZVAL_BOOL(return_value,($1)?1:0); | |
165 | } | |
166 | ||
167 | %typemap(out) float, | |
168 | double | |
169 | { | |
170 | ZVAL_DOUBLE(return_value,$1); | |
171 | } | |
172 | ||
173 | %typemap(out) char | |
174 | { | |
175 | // out char | |
176 | ZVAL_STRINGL(return_value,&$1, 1, 1); | |
177 | } | |
178 | ||
179 | %typemap(out) char *, | |
180 | char [] | |
181 | { | |
182 | if(!$1) { | |
183 | ZVAL_NULL(return_value); | |
184 | } else { | |
185 | ZVAL_STRING(return_value,$1, 1); | |
186 | } | |
187 | } | |
188 | ||
189 | %typemap(out) SWIGTYPE *, | |
190 | SWIGTYPE [], | |
191 | SWIGTYPE & | |
192 | { | |
193 | SWIG_SetPointerZval(return_value, (void *)$1, $1_descriptor, $owner); | |
194 | } | |
195 | ||
196 | %typemap(out) SWIGTYPE *DYNAMIC, | |
197 | SWIGTYPE &DYNAMIC | |
198 | { | |
199 | swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor, (void **) &$1); | |
200 | SWIG_SetPointerZval(return_value, (void *)$1, ty, $owner); | |
201 | } | |
202 | ||
203 | %typemap(out) SWIGTYPE | |
204 | #ifdef __cplusplus | |
205 | { | |
206 | $&1_ltype resultobj = new $1_ltype(($1_ltype &) $1); | |
207 | SWIG_SetPointerZval(return_value, (void *)resultobj, $&1_descriptor, 1); | |
208 | } | |
209 | #else | |
210 | { | |
211 | $&1_ltype resultobj = ($&1_ltype) emalloc(sizeof($1_type)); | |
212 | memmove(resultobj, &$1, sizeof($1_type)); | |
213 | SWIG_SetPointerZval(return_value, (void *)resultobj, $&1_descriptor, 1); | |
214 | } | |
215 | #endif | |
216 | ||
217 | %typemap(out) void ""; | |
218 | ||
219 | %typemap(out) char [ANY] | |
220 | { | |
221 | RETVAL_STRINGL($1,$1_dim0,1); | |
222 | } | |
223 | ||
224 | // This typecheck would do hard checking for proper argument type. | |
225 | //%define %php_typecheck(_type,_prec,is) | |
226 | //%typemap(typecheck,precedence=_prec) _type | |
227 | // " $1 = Z_TYPE_PP($input) == is ? 1 : 0; " | |
228 | //%enddef | |
229 | ||
230 | %define %php_typecheck(_type,_prec,is) | |
231 | %typemap(typecheck,precedence=_prec) _type | |
232 | " $1 = (Z_TYPE_PP($input) == IS_LONG || | |
233 | Z_TYPE_PP($input) == IS_DOUBLE || | |
234 | Z_TYPE_PP($input) == IS_STRING) ? 1 : 0; " | |
235 | %enddef | |
236 | ||
237 | %php_typecheck(int,SWIG_TYPECHECK_INTEGER,IS_LONG) | |
238 | %php_typecheck(unsigned int,SWIG_TYPECHECK_UINT32,IS_LONG) | |
239 | %php_typecheck(short,SWIG_TYPECHECK_INT16,IS_LONG) | |
240 | %php_typecheck(unsigned short,SWIG_TYPECHECK_UINT16,IS_LONG) | |
241 | %php_typecheck(long,SWIG_TYPECHECK_INT64,IS_LONG) | |
242 | %php_typecheck(unsigned long,SWIG_TYPECHECK_UINT64,IS_LONG) | |
243 | %php_typecheck(signed char,SWIG_TYPECHECK_INT8,IS_LONG) | |
244 | %php_typecheck(unsigned char,SWIG_TYPECHECK_UINT8,IS_LONG) | |
245 | %php_typecheck(size_t,SWIG_TYPECHECK_INT16,IS_LONG) | |
246 | %php_typecheck(enum SWIGTYPE,SWIG_TYPECHECK_INT8,IS_LONG) | |
247 | %php_typecheck(bool,SWIG_TYPECHECK_BOOL,IS_BOOL) | |
248 | ||
249 | %php_typecheck(char,SWIG_TYPECHECK_CHAR,IS_STRING) | |
250 | %php_typecheck(char *,SWIG_TYPECHECK_STRING,IS_STRING) | |
251 | %php_typecheck(char [],SWIG_TYPECHECK_STRING,IS_STRING) | |
252 | ||
253 | %php_typecheck(float,SWIG_TYPECHECK_FLOAT,IS_DOUBLE) | |
254 | %php_typecheck(double,SWIG_TYPECHECK_BOOL,IS_DOUBLE) | |
255 | ||
256 | %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE | |
257 | " /* typecheck SWIGTYPE */ " | |
258 | ||
259 | %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, | |
260 | SWIGTYPE [], | |
261 | SWIGTYPE & | |
262 | { | |
263 | /* typecheck SWIGTYPE * */ | |
264 | void *tmp; | |
265 | _v = (SWIG_ConvertPtr( *$input, (void**)&tmp, $1_descriptor, 0) < 0)? 0:1; | |
266 | } | |
267 | ||
268 | %typecheck(SWIG_TYPECHECK_VOIDPTR) void * | |
269 | " /* tyepcheck void * */ " | |
270 | ||
271 | ||
272 | /* Exception handling */ | |
273 | ||
274 | %typemap(throws) int, | |
275 | long, | |
276 | short, | |
277 | unsigned int, | |
278 | unsigned long, | |
279 | unsigned short { | |
280 | char error_msg[256]; | |
281 | sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1); | |
282 | SWIG_PHP_Error(E_ERROR, error_msg); | |
283 | } | |
284 | ||
285 | %typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY] %{ | |
286 | (void)$1; | |
287 | SWIG_PHP_Error(E_ERROR, "C++ $1_type exception thrown"); | |
288 | %} | |
289 | ||
290 | %typemap(throws) char * %{ | |
291 | SWIG_PHP_Error(E_ERROR, (char *)$1); | |
292 | %} | |
293 | ||
294 | ||
295 | /* php keywords */ | |
296 | /* please test and activate */ | |
297 | //%include "phpkw.swg" |