~ubuntu-branches/ubuntu/maverick/swig1.3/maverick

« back to all changes in this revision

Viewing changes to Lib/php4/utils.i

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:16:04 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205011604-ygx904it6413k3go
Tags: 1.3.27-1ubuntu1
Resynchronise with Debian again, for the new subversion packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
4
 
 
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);
14
 
    } else {
15
 
      #if SIZE
16
 
      // SIZE
17
 
      ZVAL_STRINGL(*$arg,BUFFER$argnum, SIZE, 1);
18
 
      #else
19
 
      // Measure length
20
 
      ZVAL_STRING(*$arg,BUFFER$argnum, 1);
21
 
      #endif
22
 
    }
23
 
  }  
24
 
%enddef
25
 
 
26
 
%define 
27
 
_strbuf_in(BUFFER)
28
 
  // _strbuf_in 
29
 
  if(! SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor) < 0) {
30
 
    /* Using a _p_ SWIG pointer, so they will have to manage size themselves */
31
 
    force=0;
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) {
38
 
       
39
 
    // Only pass back if we can...
40
 
    if (PZVAL_IS_REF(*$input)) force=1;
41
 
    else force=0;
42
 
 
43
 
    convert_to_string_ex($input);
44
 
    // Init temp buffer
45
 
    strncpy((char *)temp,Z_STRVAL_PP($input),sizeof(BUFFER));
46
 
    $1=temp;
47
 
  } else {
48
 
    force=0;
49
 
    $1=NULL;
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);
51
 
  }
52
 
%enddef
53
 
 
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) {
60
 
  _strbuf_in(temp)
61
 
  $2=sizeof(temp);
62
 
}
63
 
%typemap(argout) (BUFFER, SIZE) {
64
 
  _strbuf_out((char *)temp,strlen(temp))
65
 
}
66
 
%enddef
67
 
 
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) %{
73
 
        _strbuf_in(temp)
74
 
%}
75
 
%typemap(argout) TYPE %{
76
 
        _strbuf_out((char *)temp,$1_dim0);
77
 
%}
78
 
%enddef
79
 
 
80
 
%define strarraysize_inout(TYPE,SIZE) 
81
 
%typemap(in) TYPE ($*1_ltype temp[SIZE], int force) %{
82
 
        _strbuf_in(temp)
83
 
%}
84
 
%typemap(argout) TYPE %{
85
 
        _strbuf_out((char *)temp,SIZE);
86
 
%}
87
 
%enddef
88
 
 
89
 
%define strbuf_inout(BUFFER,MAXSIZE)
90
 
%typemap(in) (BUFFER) ($*1_ltype temp[MAXSIZE], int force) {
91
 
        _strbuf_in(temp)
92
 
}
93
 
%typemap(argout) (BUFFER) {
94
 
  _strbuf_out(temp,strlen(temp))
95
 
}
96
 
%enddef
97
 
 
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);
102
 
%enddef
103
 
 
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
115
 
      $1 = NULL;
116
 
      force=0;
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)) {
124
 
      TYPE_IN($input);
125
 
      intr = ($*1_ltype) (*$input)->value.lval;
126
 
      $1 = &intr;
127
 
      /* have to passback arg$arg too */
128
 
      force=1;
129
 
    } else {  /* wasn't a pre/ref/thing, OR anything like an int thing */
130
 
      force=0;
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);
132
 
    }
133
 
  } else force=0;
134
 
%}
135
 
 
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);
140
 
    } else {
141
 
       TYPE_OUT(*$arg,intr$argnum);     
142
 
    }
143
 
  }
144
 
%}
145
 
%enddef
 
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_INT_OUT(lvar,invar)
 
13
  lvar = (t) Z_LVAL_PP(invar);
 
14
%enddef
 
15
 
 
16
%define CONVERT_FLOAT_IN(lvar,t,invar)
 
17
  convert_to_double_ex(invar);
 
18
  lvar = (t) Z_DVAL_PP(invar);
 
19
%enddef
 
20
 
 
21
%define CONVERT_CHAR_IN(lvar,t,invar)
 
22
  convert_to_string_ex(invar);
 
23
  lvar = (t) *Z_STRVAL_PP(invar);
 
24
%enddef
 
25
 
 
26
%define CONVERT_STRING_IN(lvar,t,invar)
 
27
  convert_to_string_ex(invar);
 
28
  lvar = (t) Z_STRVAL_PP(invar);
 
29
%enddef
 
30
 
 
31
%define %pass_by_val( TYPE, CONVERT_IN )
 
32
%typemap(in) TYPE
 
33
{
 
34
  CONVERT_IN($1,$1_ltype,$input);
 
35
}
 
36
%enddef
 
37
 
 
38
%fragment("t_output_helper","header") %{
 
39
void
 
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 );
 
44
    return;
 
45
  }
 
46
  if ( (*target)->type == IS_NULL ) {
 
47
    REPLACE_ZVAL_VALUE(target,o,1);
 
48
    return;
 
49
  }
 
50
  zval *tmp;
 
51
  tmp = *target;
 
52
  zval_copy_ctor(tmp);
 
53
  array_init(*target);
 
54
  add_next_index_zval( *target, tmp);
 
55
  add_next_index_zval( *target, o);
 
56
 
 
57
}
 
58
%}
 
 
b'\\ No newline at end of file'