1
// Contains operations useful in php typemaps
2
// typemaps don't support "subroutine" typemaps where one typemap can
3
// include another, so we define useful bodies here to include inother places
5
// _strbuf_out is designed to be included as part of an argout typemap
6
// and _strbuf_in which should be part of the in typemap for the same argument
7
// They share knowledge of the "force" temporary variable.
8
// You probably don't want to make direct use of _strbuf_out or _strbuf_in but
9
// you may want strbufsize_inout which uses these
10
%define _strbuf_out(BUFFER,SIZE)
11
if (force$argnum) { /* pass back arg$argnum through params ($arg) if we can */
12
if(! PZVAL_IS_REF(*$arg)) {
13
zend_error(E_WARNING, "Parameter %d of $symname wasn't passed by reference [argout TYPES *, TYPES &]",$argnum-argbase);
17
ZVAL_STRINGL(*$arg,BUFFER$argnum, SIZE, 1);
20
ZVAL_STRING(*$arg,BUFFER$argnum, 1);
29
if(! SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor) < 0) {
30
/* Using a _p_ SWIG pointer, so they will have to manage size themselves */
32
} else if ((*$input)->type==IS_STRING ||
33
(*$input)->type==IS_LONG ||
34
/* Null passed by reference means we want a value back */
35
(*$input)->type==IS_NULL ||
36
(*$input)->type==IS_BOOL ||
37
(*$input)->type==IS_DOUBLE) {
39
// Only pass back if we can...
40
if (PZVAL_IS_REF(*$input)) force=1;
43
convert_to_string_ex($input);
45
strncpy((char *)temp,Z_STRVAL_PP($input),sizeof(BUFFER));
50
zend_error(E_ERROR, "Type error in argument %d of $symname. Expected %s or at least something looking vaguely like a string hopefully passed by reference", $argnum-argbase, $1_descriptor->name);
54
// strbufsize_inout defines a typemap which
55
// Example: strbufsize_inout(UCHAR FAR * szErrorMsg, SWORD cbErrorMsgMax,1024)
56
// defines a typeemap for UCHAR FAR * szErrorMsg, SWORD cbErrorMsgMax with a
57
// max buffer size of 1024
58
%define strbufsize_inout(BUFFER,SIZE,MAXSIZE)
59
%typemap(in) (BUFFER, SIZE) ($*1_ltype temp[MAXSIZE], int force) {
63
%typemap(argout) (BUFFER, SIZE) {
64
_strbuf_out((char *)temp,strlen(temp))
68
// char array can be in/out, though the passed string may not be big enough...
69
// so we have to size it
70
// e.g. Do: strarray_inout(char [ANY])
71
%define strarray_inout(TYPE)
72
%typemap(in) TYPE ($*1_ltype temp[$1_dim0], int force) %{
75
%typemap(argout) TYPE %{
76
_strbuf_out((char *)temp,$1_dim0);
80
%define strarraysize_inout(TYPE,SIZE)
81
%typemap(in) TYPE ($*1_ltype temp[SIZE], int force) %{
84
%typemap(argout) TYPE %{
85
_strbuf_out((char *)temp,SIZE);
89
%define strbuf_inout(BUFFER,MAXSIZE)
90
%typemap(in) (BUFFER) ($*1_ltype temp[MAXSIZE], int force) {
93
%typemap(argout) (BUFFER) {
94
_strbuf_out(temp,strlen(temp))
98
/* Typemap for in/argout references
99
NOTE: we don't choose to use these for arrays yet, maybe later */
100
%define outLONG(ZVALARG,CARG)
101
ZVAL_LONG(*$arg,intr$argnum);
104
// Defines an on/argout typemap for ordinal types
105
//Usage: %typemap_inout_ord(bool,convert_to_boolean_ex,ZVAL_BOOL)
106
%define %typemap_inout_ord(TYPES,TYPE_IN,TYPE_OUT)
107
%typemap(in) TYPES * ($*1_ltype intr, int force),
108
TYPES & ($*1_ltype intr, int force) %{
109
/* inout typemap for TYPES using TYPE_IN and TYPE_OUT */
110
if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor) < 0) {
111
/* So... we didn't get a ref or ptr, but can it be reasonably
112
co-erced into what we were looking for a ref of or ptr to? */
113
if (!PZVAL_IS_REF(*$input) && (*$input)->type==IS_NULL) {
114
// null passed not by reference means pass NULL
117
} else if (PZVAL_IS_REF(*$input) &&
118
((*$input)->type==IS_STRING ||
119
(*$input)->type==IS_LONG ||
120
/* Null passed by reference means we want a value back */
121
(*$input)->type==IS_NULL ||
122
(*$input)->type==IS_BOOL ||
123
(*$input)->type==IS_DOUBLE)) {
125
intr = ($*1_ltype) (*$input)->value.lval;
127
/* have to passback arg$arg too */
129
} else { /* wasn't a pre/ref/thing, OR anything like an int thing */
131
zend_error(E_ERROR, "Type error in argument %d of $symname. Expected %s or at least something looking vaguely like a number hopefully passed by reference", $argnum-argbase, $1_descriptor->name);
136
%typemap(argout) TYPES *, TYPES & %{
137
if (force$argnum) { /* pass back arg$argnum through params ($arg) if we can */
138
if(! PZVAL_IS_REF(*$arg)) {
139
zend_error(E_WARNING, "Parameter %d of $symname wasn't passed by reference [argout TYPES *, TYPES &]",$argnum-argbase);
141
TYPE_OUT(*$arg,intr$argnum);
2
%define CONVERT_BOOL_IN(lvar,t,invar)
3
convert_to_boolean_ex(invar);
4
lvar = (t) Z_LVAL_PP(invar);
7
%define CONVERT_INT_IN(lvar,t,invar)
8
convert_to_long_ex(invar);
9
lvar = (t) Z_LVAL_PP(invar);
12
%define CONVERT_INT_OUT(lvar,invar)
13
lvar = (t) Z_LVAL_PP(invar);
16
%define CONVERT_FLOAT_IN(lvar,t,invar)
17
convert_to_double_ex(invar);
18
lvar = (t) Z_DVAL_PP(invar);
21
%define CONVERT_CHAR_IN(lvar,t,invar)
22
convert_to_string_ex(invar);
23
lvar = (t) *Z_STRVAL_PP(invar);
26
%define CONVERT_STRING_IN(lvar,t,invar)
27
convert_to_string_ex(invar);
28
lvar = (t) Z_STRVAL_PP(invar);
31
%define %pass_by_val( TYPE, CONVERT_IN )
34
CONVERT_IN($1,$1_ltype,$input);
38
%fragment("t_output_helper","header") %{
40
t_output_helper( zval **target, zval *o) {
41
if ( (*target)->type == IS_ARRAY ) {
42
/* it's already an array, just append */
43
add_next_index_zval( *target, o );
46
if ( (*target)->type == IS_NULL ) {
47
REPLACE_ZVAL_VALUE(target,o,1);
54
add_next_index_zval( *target, tmp);
55
add_next_index_zval( *target, o);
b'\\ No newline at end of file'