1 /* ----------------------------------------------------------------------------- 2 * php.swg 3 * 4 * PHP configuration file 5 * ----------------------------------------------------------------------------- */ 6 7 %runtime "swigrun.swg" // Common C API type-checking code 8 %runtime "phprun.swg" // PHP runtime functions 9 10 %include <phpinit.swg> // PHP initialization routine. 11 12 %include <globalvar.i> // Global variables. 13 %include <const.i> 14 15 // use %init %{ "/*code goes here*/ " %} 16 // or %minit %{ "/* code goes here*/ " %} to 17 // insert code in the PHP_MINIT_FUNCTION 18 #define %minit %insert("init") 19 20 // use %rinit %{ "/* code goes here*/ " %} to 21 // insert code in the PHP_RINIT_FUNCTION 22 #define %rinit %insert("rinit") 23 24 // use %shutdown %{ " /*code goes here*/ " %} to 25 // insert code in the PHP_MSHUTDOWN_FUNCTION 26 #define %shutdown %insert("shutdown") 27 #define %mshutdown %insert("shutdown") 28 29 // use %rshutdown %{ " /*code goes here*/" %} to 30 // insert code in the PHP_RSHUTDOWN_FUNCTION 31 #define %rshutdown %insert("rshutdown") 32 33 /* Typemaps for input parameters by value */ 34 35 %include <utils.i> 36 37 %pass_by_val(bool,CONVERT_BOOL_IN); 38 39 %pass_by_val(size_t, CONVERT_INT_IN); 40 41 %pass_by_val(enum SWIGTYPE, CONVERT_INT_IN); 42 43 %pass_by_val(signed int, CONVERT_INT_IN); 44 %pass_by_val(int,CONVERT_INT_IN); 45 %pass_by_val(unsigned int,CONVERT_INT_IN); 46 47 %pass_by_val(signed short, CONVERT_INT_IN); 48 %pass_by_val(short,CONVERT_INT_IN); 49 %pass_by_val(unsigned short, CONVERT_INT_IN); 50 51 %pass_by_val(signed long, CONVERT_INT_IN); 52 %pass_by_val(long, CONVERT_INT_IN); 53 %pass_by_val(unsigned long, CONVERT_INT_IN); 54 55 %pass_by_val(signed long long, CONVERT_LONG_LONG_IN); 56 %pass_by_val(long long, CONVERT_LONG_LONG_IN); 57 %pass_by_val(unsigned long long, CONVERT_UNSIGNED_LONG_LONG_IN); 58 59 %pass_by_val(signed char, CONVERT_INT_IN); 60 %pass_by_val(char, CONVERT_CHAR_IN); 61 %pass_by_val(unsigned char, CONVERT_INT_IN); 62 63 %pass_by_val(float, CONVERT_FLOAT_IN); 64 65 %pass_by_val(double, CONVERT_FLOAT_IN); 66 67 %pass_by_val(char *, CONVERT_STRING_IN); 68 %typemap(in) char *& = const char *&; 69 %typemap(directorout) char *& = const char *&; 70 71 // char array can be in/out, though the passed string may not be big enough... 72 // so we have to size it 73 %typemap(in) char[ANY] 74 { 75 convert_to_string_ex($input); 76 $1 = ($1_ltype) Z_STRVAL_PP($input); 77 } 78 79 %typemap(in) (char *STRING, int LENGTH), (char *STRING, size_t LENGTH) { 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 *const& ($*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 = ($1_ltype)&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) long long 198 %{ 199 if ((long long)LONG_MIN <= $1 && $1 <= (long long)LONG_MAX) { 200 return_value->value.lval = (long)($1); 201 return_value->type = IS_LONG; 202 } else { 203 char temp[256]; 204 sprintf(temp, "%lld", (long long)$1); 205 ZVAL_STRING(return_value, temp, 1); 206 } 207 %} 208 %typemap(out) unsigned long long 209 %{ 210 if ($1 <= (unsigned long long)LONG_MAX) { 211 return_value->value.lval = (long)($1); 212 return_value->type = IS_LONG; 213 } else { 214 char temp[256]; 215 sprintf(temp, "%llu", (unsigned long long)$1); 216 ZVAL_STRING(return_value, temp, 1); 217 } 218 %} 219 220 %typemap(out) const int &, 221 const unsigned int &, 222 const short &, 223 const unsigned short &, 224 const long &, 225 const unsigned long &, 226 const signed char &, 227 const unsigned char &, 228 const bool &, 229 const size_t &, 230 const enum SWIGTYPE & 231 { 232 ZVAL_LONG(return_value,*$1); 233 } 234 235 %typemap(out) const long long & 236 %{ 237 if ((long long)LONG_MIN <= *$1 && *$1 <= (long long)LONG_MAX) { 238 return_value->value.lval = (long)(*$1); 239 return_value->type = IS_LONG; 240 } else { 241 char temp[256]; 242 sprintf(temp, "%lld", (long long)(*$1)); 243 ZVAL_STRING(return_value, temp, 1); 244 } 245 %} 246 %typemap(out) const unsigned long long & 247 %{ 248 if (*$1 <= (unsigned long long)LONG_MAX) { 249 return_value->value.lval = (long)(*$1); 250 return_value->type = IS_LONG; 251 } else { 252 char temp[256]; 253 sprintf(temp, "%llu", (unsigned long long)(*$1)); 254 ZVAL_STRING(return_value, temp, 1); 255 } 256 %} 257 258 %typemap(directorin) int, 259 unsigned int, 260 short, 261 unsigned short, 262 long, 263 unsigned long, 264 signed char, 265 unsigned char, 266 size_t, 267 enum SWIGTYPE 268 { 269 ZVAL_LONG($input,$1); 270 } 271 272 %typemap(directorin) char *, char [] 273 { 274 if(!$1) { 275 ZVAL_NULL($input); 276 } else { 277 ZVAL_STRING($input, (char *)$1, 1); 278 } 279 } 280 281 %typemap(out) bool 282 { 283 ZVAL_BOOL(return_value,($1)?1:0); 284 } 285 286 %typemap(out) const bool & 287 { 288 ZVAL_BOOL(return_value,(*$1)?1:0); 289 } 290 291 %typemap(directorin) bool 292 { 293 ZVAL_BOOL($input,($1)?1:0); 294 } 295 296 %typemap(out) float, 297 double 298 { 299 ZVAL_DOUBLE(return_value,$1); 300 } 301 302 %typemap(out) const float &, 303 const double & 304 { 305 ZVAL_DOUBLE(return_value,*$1); 306 } 307 308 %typemap(directorin) float, 309 double 310 { 311 ZVAL_DOUBLE($input,$1); 312 } 313 314 %typemap(out) char 315 { 316 ZVAL_STRINGL(return_value,&$1, 1, 1); 317 } 318 319 %typemap(out) const char & 320 { 321 ZVAL_STRINGL(return_value,&*$1, 1, 1); 322 } 323 324 %typemap(out) char *, 325 char [] 326 { 327 if(!$1) { 328 ZVAL_NULL(return_value); 329 } else { 330 ZVAL_STRING(return_value, (char *)$1, 1); 331 } 332 } 333 334 %typemap(out) char *& 335 { 336 if(!*$1) { 337 ZVAL_NULL(return_value); 338 } else { 339 ZVAL_STRING(return_value, (char *)*$1, 1); 340 } 341 } 342 343 %typemap(out) SWIGTYPE *, 344 SWIGTYPE [], 345 SWIGTYPE & 346 %{ 347 SWIG_SetPointerZval(return_value, (void *)$1, $1_descriptor, $owner); 348 %} 349 350 %typemap(out) SWIGTYPE *const& 351 %{ 352 SWIG_SetPointerZval(return_value, (void *)*$1, $*1_descriptor, $owner); 353 %} 354 355 %typemap(directorin) SWIGTYPE *, 356 SWIGTYPE [], 357 SWIGTYPE & 358 %{ 359 SWIG_SetPointerZval($input, (void *)&$1, $1_descriptor, ($owner)|2); 360 %} 361 362 %typemap(out, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*) 363 { 364 void * p = emalloc(sizeof($1)); 365 memcpy(p, &$1, sizeof($1)); 366 zval * resource; 367 MAKE_STD_ZVAL(resource); 368 ZEND_REGISTER_RESOURCE(resource, p, swig_member_ptr); 369 370 SWIG_SetPointerZval(return_value, (void *)&$1, $1_descriptor, $owner); 371 } 372 373 %typemap(in, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*) 374 { 375 void * p = (void*)zend_fetch_resource($input TSRMLS_CC, -1, SWIG_MEMBER_PTR, NULL, 1, swig_member_ptr); 376 memcpy(&$1, p, sizeof($1)); 377 } 378 379 %typemap(out) SWIGTYPE *DYNAMIC, 380 SWIGTYPE &DYNAMIC 381 { 382 swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor, (void **) &$1); 383 SWIG_SetPointerZval(return_value, (void *)$1, ty, $owner); 384 } 385 386 %typemap(out) SWIGTYPE 387 #ifdef __cplusplus 388 { 389 $&1_ltype resultobj = new $1_ltype((const $1_ltype &) $1); 390 SWIG_SetPointerZval(return_value, (void *)resultobj, $&1_descriptor, 1); 391 } 392 #else 393 { 394 $&1_ltype resultobj = ($&1_ltype) emalloc(sizeof($1_type)); 395 memcpy(resultobj, &$1, sizeof($1_type)); 396 SWIG_SetPointerZval(return_value, (void *)resultobj, $&1_descriptor, 1); 397 } 398 #endif 399 400 %typemap(directorin) SWIGTYPE 401 { 402 SWIG_SetPointerZval($input, SWIG_as_voidptr(&$1), $&1_descriptor, 2); 403 } 404 405 %typemap(out) void ""; 406 407 %typemap(out) char [ANY] 408 { 409 int len = 0; 410 while (len < $1_dim0 && $1[len]) ++len; 411 RETVAL_STRINGL($1, len, 1); 412 } 413 414 // This typecheck does hard checking for proper argument type. If you want 415 // an argument to be converted from a different PHP type, you must convert 416 // it yourself before passing it (e.g. (string)4.7 or (int)"6"). 417 %define %php_typecheck(_type,_prec,is) 418 %typemap(typecheck,precedence=_prec) _type, const _type & 419 " $1 = (Z_TYPE_PP($input) == is); " 420 %enddef 421 422 %php_typecheck(int,SWIG_TYPECHECK_INTEGER,IS_LONG) 423 %php_typecheck(unsigned int,SWIG_TYPECHECK_UINT32,IS_LONG) 424 %php_typecheck(short,SWIG_TYPECHECK_INT16,IS_LONG) 425 %php_typecheck(unsigned short,SWIG_TYPECHECK_UINT16,IS_LONG) 426 %php_typecheck(long,SWIG_TYPECHECK_INT32,IS_LONG) 427 %php_typecheck(unsigned long,SWIG_TYPECHECK_UINT32,IS_LONG) 428 %php_typecheck(long long,SWIG_TYPECHECK_INT64,IS_LONG) 429 %php_typecheck(unsigned long long,SWIG_TYPECHECK_UINT64,IS_LONG) 430 %php_typecheck(signed char,SWIG_TYPECHECK_INT8,IS_LONG) 431 %php_typecheck(unsigned char,SWIG_TYPECHECK_UINT8,IS_LONG) 432 %php_typecheck(size_t,SWIG_TYPECHECK_SIZE,IS_LONG) 433 %php_typecheck(enum SWIGTYPE,SWIG_TYPECHECK_INTEGER,IS_LONG) 434 %php_typecheck(bool,SWIG_TYPECHECK_BOOL,IS_BOOL) 435 %php_typecheck(float,SWIG_TYPECHECK_FLOAT,IS_DOUBLE) 436 %php_typecheck(double,SWIG_TYPECHECK_DOUBLE,IS_DOUBLE) 437 %php_typecheck(char,SWIG_TYPECHECK_CHAR,IS_STRING) 438 439 %typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) char *, char *&, char [] 440 " $1 = (Z_TYPE_PP($input) == IS_STRING); " 441 442 %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE 443 { 444 void *tmp; 445 _v = (SWIG_ConvertPtr(*$input, (void **)&tmp, $&1_descriptor, 0) >= 0); 446 } 447 448 %typecheck(SWIG_TYPECHECK_POINTER) 449 SWIGTYPE *, 450 SWIGTYPE [], 451 SWIGTYPE &, 452 SWIGTYPE *const& 453 { 454 void *tmp; 455 _v = (SWIG_ConvertPtr(*$input, (void**)&tmp, $1_descriptor, 0) >= 0); 456 } 457 458 %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *const& 459 { 460 void *tmp; 461 _v = (SWIG_ConvertPtr(*$input, (void**)&tmp, $*1_descriptor, 0) >= 0); 462 } 463 464 %typecheck(SWIG_TYPECHECK_VOIDPTR) void * 465 { 466 void *tmp; 467 _v = (SWIG_ConvertPtr(*$input, (void**)&tmp, 0, 0) >= 0); 468 } 469 470 /* Exception handling */ 471 472 %typemap(throws) int, 473 long, 474 short, 475 unsigned int, 476 unsigned long, 477 unsigned short { 478 zend_throw_exception(NULL, const_cast<char*>("C++ $1_type exception thrown"), $1 TSRMLS_CC); 479 return; 480 } 481 482 %typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY] %{ 483 (void)$1; 484 zend_throw_exception(NULL, const_cast<char*>("C++ $1_type exception thrown"), 0 TSRMLS_CC); 485 return; 486 %} 487 488 %typemap(throws) char * %{ 489 zend_throw_exception(NULL, const_cast<char*>($1), 0 TSRMLS_CC); 490 return; 491 %} 492 493 /* Array reference typemaps */ 494 %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } 495 496 /* const pointers */ 497 %apply SWIGTYPE * { SWIGTYPE *const } 498 499 500 /* php keywords */ 501 %include <phpkw.swg> 502