1/* ----------------------------------------------------------------------------- 2 * See the LICENSE file for information on copyright, usage and redistribution 3 * of SWIG, and the README file for authors - http://www.swig.org/release.html. 4 * 5 * php.swg 6 * 7 * PHP configuration file 8 * ----------------------------------------------------------------------------- */ 9 10%runtime "swigrun.swg" // Common C API type-checking code 11%runtime "phprun.swg" // PHP runtime functions 12 13%include <phpinit.swg> // PHP initialization routine. 14 15%include <globalvar.i> // Global variables. 16%include <const.i> 17 18// use %init %{ "/*code goes here*/ " %} 19// or %minit %{ "/* code goes here*/ " %} to 20// insert code in the PHP_MINIT_FUNCTION 21#define %minit %insert("init") 22 23// use %rinit %{ "/* code goes here*/ " %} to 24// insert code in the PHP_RINIT_FUNCTION 25#define %rinit %insert("rinit") 26 27// use %shutdown %{ " /*code goes here*/ " %} to 28// insert code in the PHP_MSHUTDOWN_FUNCTION 29#define %shutdown %insert("shutdown") 30#define %mshutdown %insert("shutdown") 31 32// use %rshutdown %{ " /*code goes here*/" %} to 33// insert code in the PHP_RSHUTDOWN_FUNCTION 34#define %rshutdown %insert("rshutdown") 35 36/* Typemaps for input parameters by value */ 37 38%include <utils.i> 39 40%pass_by_val(bool,CONVERT_BOOL_IN); 41 42%pass_by_val(size_t, CONVERT_INT_IN); 43 44%pass_by_val(enum SWIGTYPE, CONVERT_INT_IN); 45 46%pass_by_val(signed int, CONVERT_INT_IN); 47%pass_by_val(int,CONVERT_INT_IN); 48%pass_by_val(unsigned int,CONVERT_INT_IN); 49 50%pass_by_val(signed short, CONVERT_INT_IN); 51%pass_by_val(short,CONVERT_INT_IN); 52%pass_by_val(unsigned short, CONVERT_INT_IN); 53 54%pass_by_val(signed long, CONVERT_INT_IN); 55%pass_by_val(long, CONVERT_INT_IN); 56%pass_by_val(unsigned long, CONVERT_INT_IN); 57 58%pass_by_val(signed char, CONVERT_INT_IN); 59%pass_by_val(char, CONVERT_CHAR_IN); 60%pass_by_val(unsigned char, CONVERT_INT_IN); 61 62%pass_by_val(float, CONVERT_FLOAT_IN); 63 64%pass_by_val(double, CONVERT_FLOAT_IN); 65 66%pass_by_val(char *, CONVERT_STRING_IN); 67%typemap(in) char *& = const char *&; 68%typemap(directorout) char *& = const char *&; 69 70// char array can be in/out, though the passed string may not be big enough... 71// so we have to size it 72%typemap(in) char[ANY] 73{ 74 convert_to_string_ex($input); 75 $1 = ($1_ltype) Z_STRVAL_PP($input); 76} 77 78%typemap(in) (char *STRING, int LENGTH) 79{ 80 convert_to_string_ex($input); 81 $1 = ($1_ltype) Z_STRVAL_PP($input); 82 $2 = ($2_ltype) Z_STRLEN_PP($input); 83} 84 85/* Object passed by value. Convert to a pointer */ 86%typemap(in) SWIGTYPE ($&1_ltype tmp) 87{ 88 if(SWIG_ConvertPtr(*$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { 89 SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); 90 } 91 $1 = *tmp; 92} 93 94%typemap(directorout) SWIGTYPE ($&1_ltype tmp) 95{ 96 if(SWIG_ConvertPtr(*$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { 97 SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); 98 } 99 $result = *tmp; 100} 101 102%typemap(in) SWIGTYPE *, 103 SWIGTYPE [] 104{ 105 if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, 0) < 0) { 106 SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); 107 } 108} 109 110%typemap(in) SWIGTYPE & 111{ 112 if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) { 113 SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); 114 } 115} 116 117%typemap(in) SWIGTYPE *& ($*ltype temp) 118{ 119 if(SWIG_ConvertPtr(*$input, (void **) &temp, $*1_descriptor, 0) < 0) { 120 SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor"); 121 } 122 $1 = &temp; 123} 124 125%typemap(in) SWIGTYPE *DISOWN 126{ 127 if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) { 128 SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); 129 } 130} 131 132%typemap(argout) SWIGTYPE *, 133 SWIGTYPE [], 134 SWIGTYPE&; 135 136%typemap(in) void * 137{ 138 if(SWIG_ConvertPtr(*$input, (void **) &$1, 0, 0) < 0) { 139 /* Allow NULL from php for void* */ 140 if ((*$input)->type==IS_NULL) $1=0; 141 else 142 SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); 143 } 144} 145 146/* Special case when void* is passed by reference so it can be made to point 147 to opaque api structs */ 148%typemap(in) void ** ($*1_ltype ptr, int force), 149 void *& ($*1_ltype ptr, int force) 150{ 151 /* If they pass NULL by reference, make it into a void* 152 This bit should go in arginit if arginit support init-ing scripting args */ 153 if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, 0) < 0) { 154 /* So... we didn't get a ref or ptr, but we'll accept NULL by reference */ 155 if (!((*$input)->type==IS_NULL && PZVAL_IS_REF(*$input))) { 156 /* wasn't a pre/ref/thing, OR anything like an int thing */ 157 SWIG_PHP_Error(E_ERROR, "Type error in argument $arg of $symname."); 158 } 159 } 160 force=0; 161 if (arg1==NULL) { 162#ifdef __cplusplus 163 ptr=new $*1_ltype; 164#else 165 ptr=($*1_ltype) calloc(1,sizeof($*1_ltype)); 166#endif 167 $1=&ptr; 168 /* have to passback arg$arg too */ 169 force=1; 170 } 171} 172%typemap(argout) void **, 173 void *& 174{ 175 if (force$argnum) { 176 SWIG_SetPointerZval( *$input, (void*) ptr$argnum, $*1_descriptor, 1); 177 } 178} 179 180/* Typemap for output values */ 181 182%typemap(out) int, 183 unsigned int, 184 short, 185 unsigned short, 186 long, 187 unsigned long, 188 signed char, 189 unsigned char, 190 bool, 191 size_t, 192 enum SWIGTYPE 193{ 194 ZVAL_LONG(return_value,$1); 195} 196 197%typemap(out) const int &, 198 const unsigned int &, 199 const short &, 200 const unsigned short &, 201 const long &, 202 const unsigned long &, 203 const signed char &, 204 const unsigned char &, 205 const bool &, 206 const size_t &, 207 const enum SWIGTYPE & 208{ 209 ZVAL_LONG(return_value,*$1); 210} 211 212%typemap(directorin) int, 213 unsigned int, 214 short, 215 unsigned short, 216 long, 217 unsigned long, 218 signed char, 219 unsigned char, 220 size_t, 221 enum SWIGTYPE 222{ 223 ZVAL_LONG($input,$1_name); 224} 225 226%typemap(out) bool 227{ 228 ZVAL_BOOL(return_value,($1)?1:0); 229} 230 231%typemap(out) const bool & 232{ 233 ZVAL_BOOL(return_value,(*$1)?1:0); 234} 235 236%typemap(directorin) bool 237{ 238 ZVAL_BOOL($input,($1_name)?1:0); 239} 240 241%typemap(out) float, 242 double 243{ 244 ZVAL_DOUBLE(return_value,$1); 245} 246 247%typemap(out) const float &, 248 const double & 249{ 250 ZVAL_DOUBLE(return_value,*$1); 251} 252 253%typemap(directorin) float, 254 double 255{ 256 ZVAL_DOUBLE($input,$1_name); 257} 258 259%typemap(out) char 260{ 261 ZVAL_STRINGL(return_value,&$1, 1, 1); 262} 263 264%typemap(out) const char & 265{ 266 ZVAL_STRINGL(return_value,&*$1, 1, 1); 267} 268 269%typemap(out) char *, 270 char [] 271{ 272 if(!$1) { 273 ZVAL_NULL(return_value); 274 } else { 275 ZVAL_STRING(return_value, (char *)$1, 1); 276 } 277} 278 279%typemap(out) char *& 280{ 281 if(!*$1) { 282 ZVAL_NULL(return_value); 283 } else { 284 ZVAL_STRING(return_value, (char *)*$1, 1); 285 } 286} 287 288%typemap(out) SWIGTYPE *, 289 SWIGTYPE [], 290 SWIGTYPE & 291%{ 292 SWIG_SetPointerZval(return_value, (void *)$1, $1_descriptor, $owner); 293%} 294 295%typemap(out) SWIGTYPE *& 296%{ 297 SWIG_SetPointerZval(return_value, (void *)*$1, $*1_descriptor, $owner); 298%} 299 300%typemap(directorin) SWIGTYPE *, 301 SWIGTYPE [], 302 SWIGTYPE & 303%{ 304 SWIG_SetPointerZval($input, (void *)&$1_name, $1_descriptor, $owner); 305%} 306 307%typemap(out) SWIGTYPE *DYNAMIC, 308 SWIGTYPE &DYNAMIC 309{ 310 swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor, (void **) &$1); 311 SWIG_SetPointerZval(return_value, (void *)$1, ty, $owner); 312} 313 314%typemap(out) SWIGTYPE 315#ifdef __cplusplus 316{ 317 $&1_ltype resultobj = new $1_ltype((const $1_ltype &) $1); 318 SWIG_SetPointerZval(return_value, (void *)resultobj, $&1_descriptor, 1); 319} 320#else 321{ 322 $&1_ltype resultobj = ($&1_ltype) emalloc(sizeof($1_type)); 323 memcpy(resultobj, &$1, sizeof($1_type)); 324 SWIG_SetPointerZval(return_value, (void *)resultobj, $&1_descriptor, 1); 325} 326#endif 327 328%typemap(directorin) SWIGTYPE 329{ 330 SWIG_SetPointerZval($input, SWIG_as_voidptr(&$1_name), $&1_descriptor, 2); 331} 332 333/* Array reference typemaps */ 334%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } 335 336 337%typemap(out) void ""; 338 339%typemap(out) char [ANY] 340{ 341 int len = 0; 342 while (len < $1_dim0 && $1[len]) ++len; 343 RETVAL_STRINGL($1, len, 1); 344} 345 346// This typecheck does hard checking for proper argument type. If you want 347// an argument to be converted from a different PHP type, you must convert 348// it yourself before passing it (e.g. (string)4.7 or (int)"6"). 349%define %php_typecheck(_type,_prec,is) 350%typemap(typecheck,precedence=_prec) _type, const _type & 351 " $1 = (Z_TYPE_PP($input) == is); " 352%enddef 353 354%php_typecheck(int,SWIG_TYPECHECK_INTEGER,IS_LONG) 355%php_typecheck(unsigned int,SWIG_TYPECHECK_UINT32,IS_LONG) 356%php_typecheck(short,SWIG_TYPECHECK_INT16,IS_LONG) 357%php_typecheck(unsigned short,SWIG_TYPECHECK_UINT16,IS_LONG) 358%php_typecheck(long,SWIG_TYPECHECK_INT64,IS_LONG) 359%php_typecheck(unsigned long,SWIG_TYPECHECK_UINT64,IS_LONG) 360%php_typecheck(signed char,SWIG_TYPECHECK_INT8,IS_LONG) 361%php_typecheck(unsigned char,SWIG_TYPECHECK_UINT8,IS_LONG) 362%php_typecheck(size_t,SWIG_TYPECHECK_INT16,IS_LONG) 363%php_typecheck(enum SWIGTYPE,SWIG_TYPECHECK_INT8,IS_LONG) 364%php_typecheck(bool,SWIG_TYPECHECK_BOOL,IS_BOOL) 365%php_typecheck(float,SWIG_TYPECHECK_FLOAT,IS_DOUBLE) 366%php_typecheck(double,SWIG_TYPECHECK_BOOL,IS_DOUBLE) 367%php_typecheck(char,SWIG_TYPECHECK_CHAR,IS_STRING) 368 369%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) char *, char *&, char [] 370 " $1 = (Z_TYPE_PP($input) == IS_STRING); " 371 372%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE 373{ 374 void *tmp; 375 _v = (SWIG_ConvertPtr(*$input, (void **)&tmp, $&1_descriptor, 0) >= 0); 376} 377 378%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, 379 SWIGTYPE [], 380 SWIGTYPE &, 381 SWIGTYPE *& 382{ 383 void *tmp; 384 _v = (SWIG_ConvertPtr(*$input, (void**)&tmp, $1_descriptor, 0) >= 0); 385} 386 387%typecheck(SWIG_TYPECHECK_VOIDPTR) void * 388{ 389 void *tmp; 390 _v = (SWIG_ConvertPtr(*$input, (void**)&tmp, 0, 0) >= 0); 391} 392 393/* Exception handling */ 394 395%typemap(throws) int, 396 long, 397 short, 398 unsigned int, 399 unsigned long, 400 unsigned short { 401 char error_msg[256]; 402 sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1); 403 SWIG_PHP_Error(E_ERROR, error_msg); 404} 405 406%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY] %{ 407 (void)$1; 408 SWIG_PHP_Error(E_ERROR, "C++ $1_type exception thrown"); 409%} 410 411%typemap(throws) char * %{ 412 SWIG_PHP_Error(E_ERROR, (char *)$1); 413%} 414 415 416/* php keywords */ 417%include <phpkw.swg> 418