1 2 %define CONVERT_BOOL_IN(lvar,t,invar) 3 convert_to_boolean_ex(invar); 4 lvar = (t) Z_LVAL_PP(invar); 5 %enddef 6 7 %define CONVERT_INT_IN(lvar,t,invar) 8 convert_to_long_ex(invar); 9 lvar = (t) Z_LVAL_PP(invar); 10 %enddef 11 12 %define CONVERT_LONG_LONG_IN(lvar,t,invar) 13 switch ((*(invar))->type) { 14 case IS_DOUBLE: 15 lvar = (t) (*(invar))->value.dval; 16 break; 17 case IS_STRING: { 18 char * endptr; 19 errno = 0; 20 lvar = (t) strtoll((*(invar))->value.str.val, &endptr, 10); 21 if (*endptr && !errno) break; 22 /* FALL THRU */ 23 } 24 default: 25 convert_to_long_ex(invar); 26 lvar = (t) (*(invar))->value.lval; 27 } 28 %enddef 29 30 %define CONVERT_UNSIGNED_LONG_LONG_IN(lvar,t,invar) 31 switch ((*(invar))->type) { 32 case IS_DOUBLE: 33 lvar = (t) (*(invar))->value.dval; 34 break; 35 case IS_STRING: { 36 char * endptr; 37 errno = 0; 38 lvar = (t) strtoull((*(invar))->value.str.val, &endptr, 10); 39 if (*endptr && !errno) break; 40 /* FALL THRU */ 41 } 42 default: 43 convert_to_long_ex(invar); 44 lvar = (t) (*(invar))->value.lval; 45 } 46 %enddef 47 48 %define CONVERT_INT_OUT(lvar,invar) 49 lvar = (t) Z_LVAL_PP(invar); 50 %enddef 51 52 %define CONVERT_FLOAT_IN(lvar,t,invar) 53 convert_to_double_ex(invar); 54 lvar = (t) Z_DVAL_PP(invar); 55 %enddef 56 57 %define CONVERT_CHAR_IN(lvar,t,invar) 58 convert_to_string_ex(invar); 59 lvar = (t) *Z_STRVAL_PP(invar); 60 %enddef 61 62 %define CONVERT_STRING_IN(lvar,t,invar) 63 if ((*invar)->type==IS_NULL) { 64 lvar = (t) 0; 65 } else { 66 convert_to_string_ex(invar); 67 lvar = (t) Z_STRVAL_PP(invar); 68 } 69 %enddef 70 71 %define %pass_by_val( TYPE, CONVERT_IN ) 72 %typemap(in) TYPE 73 %{ 74 CONVERT_IN($1,$1_ltype,$input); 75 %} 76 %typemap(in) const TYPE & ($*1_ltype temp) 77 %{ 78 CONVERT_IN(temp,$*1_ltype,$input); 79 $1 = &temp; 80 %} 81 %typemap(directorout) TYPE 82 %{ 83 CONVERT_IN($result,$1_ltype,$input); 84 %} 85 %typemap(directorout) const TYPE & ($*1_ltype temp) 86 %{ 87 CONVERT_IN(temp,$*1_ltype,$input); 88 $result = &temp; 89 %} 90 %enddef 91 92 %fragment("t_output_helper","header") %{ 93 static void 94 t_output_helper( zval **target, zval *o) { 95 if ( (*target)->type == IS_ARRAY ) { 96 /* it's already an array, just append */ 97 add_next_index_zval( *target, o ); 98 return; 99 } 100 if ( (*target)->type == IS_NULL ) { 101 REPLACE_ZVAL_VALUE(target,o,1); 102 FREE_ZVAL(o); 103 return; 104 } 105 zval *tmp; 106 ALLOC_INIT_ZVAL(tmp); 107 *tmp = **target; 108 zval_copy_ctor(tmp); 109 array_init(*target); 110 add_next_index_zval( *target, tmp); 111 add_next_index_zval( *target, o); 112 113 } 114 %} 115