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

« back to all changes in this revision

Viewing changes to Lib/php4/php4run.swg

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2006-12-20 14:43:24 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20061220144324-bps3kb06xp5oy9w1
Tags: 1.3.31-1ubuntu1
* Merge from debian unstable, remaining changes:
  - drop support for pike
  - use php5 instead of php4
  - clean Runtime/ as well
  - force a few environment variables

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
 
47
47
#define SWIG_PHP_Arg_Error_Msg(argnum,extramsg) "Error in argument " #argnum " "#extramsg
48
48
 
49
 
#define SWIG_PHP_Error(code,msg) ErrorCode() = code; ErrorMsg() = msg; SWIG_fail;
 
49
#define SWIG_PHP_Error(code,msg) do { SWIG_ErrorCode() = code; SWIG_ErrorMsg() = msg; SWIG_fail; } while (0)
50
50
 
51
51
#define SWIG_contract_assert(expr,msg) \
52
52
  if (!(expr) ) { zend_printf("Contract Assert Failed %s\n",msg ); } else
63
63
} swig_object_wrapper;
64
64
 
65
65
/* empty zend destructor for types without one */
66
 
static ZEND_RSRC_DTOR_FUNC(SWIG_landfill) {};
 
66
static ZEND_RSRC_DTOR_FUNC(SWIG_landfill) { (void)rsrc; }
67
67
 
68
 
#define SWIG_SetPointerZval(a,b,c,d) SWIG_ZTS_SetPointerZval(a,b,c,d, SWIG_module_entry TSRMLS_CC)
 
68
#define SWIG_SetPointerZval(a,b,c,d) SWIG_ZTS_SetPointerZval(a,b,c,d TSRMLS_CC)
69
69
 
70
70
static void
71
 
SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject, zend_module_entry* module_entry TSRMLS_DC) {
 
71
SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject TSRMLS_DC) {
72
72
  swig_object_wrapper *value=NULL;
73
73
  /*
74
74
   * First test for Null pointers.  Return those as PHP native NULL
85
85
    value->newobject=newobject;
86
86
    ZEND_REGISTER_RESOURCE(z, value, *(int *)(type->clientdata));
87
87
    return;
88
 
  } else { /* have to deal with old fashioned string pointer?
89
 
              but this should not get this far */
90
 
    zend_error(E_ERROR, "Type: %s not registered with zend",type->name);
91
88
  }
 
89
  zend_error(E_ERROR, "Type: %s not registered with zend",type->name);
92
90
}
93
91
 
94
 
/* This is a new pointer conversion routine
95
 
   Taking the native pointer p (which would have been converted from the old
96
 
   string pointer) and it's php type id, and it's type name (which also would
97
 
   have come from the old string pointer) it converts it to ptr calling 
98
 
   appropriate casting functions according to ty
99
 
   Sadly PHP has no API to find a type name from a type id, only from an instance
100
 
   of a resource of the type id, so we have to pass type_name as well.
 
92
/* This pointer conversion routine takes the native pointer p (along with
 
93
   its type name) and converts it by calling appropriate casting functions
 
94
   according to ty.  The resultant pointer is returned, or NULL is returned
 
95
   if the pointer can't be cast.
 
96
 
 
97
   Sadly PHP has no API to find a type name from a type id, only from an
 
98
   instance of a resource of the type id, so we have to pass type_name as well.
 
99
 
101
100
   The two functions which might call this are:
102
101
   SWIG_ZTS_ConvertResourcePtr which gets the type name from the resource
103
102
   and the registered zend destructors for which we have one per type each
104
103
   with the type name hard wired in. */
105
 
static int
106
 
SWIG_ZTS_ConvertResourceData(void * p, int type, const char *type_name, void **ptr, swig_type_info *ty TSRMLS_DC) {
 
104
static void *
 
105
SWIG_ZTS_ConvertResourceData(void * p, const char *type_name, swig_type_info *ty TSRMLS_DC) {
107
106
  swig_cast_info *tc;
108
107
 
109
 
  if (ty) {
110
 
    if (! type_name) {  
111
 
      /* can't convert p to ptr type ty if we don't know what type p is */
112
 
      return -1;
113
 
    } else {
114
 
      /* convert and cast p from type_name to ptr as ty
115
 
         Need to sort out const-ness, can SWIG_TypeCast really not take a const? */
116
 
      tc = SWIG_TypeCheck((char *)type_name,ty);
117
 
      if (!tc) return -1;
118
 
      *ptr = SWIG_TypeCast(tc, (void*)p);
119
 
    }
120
 
  } else {
 
108
  if (!ty) {
121
109
    /* They don't care about the target type, so just pass on the pointer! */
122
 
    *ptr = (void *) p;
123
 
  }
124
 
  return 0;
 
110
    return p;
 
111
  }
 
112
 
 
113
  if (! type_name) {  
 
114
    /* can't convert p to ptr type ty if we don't know what type p is */
 
115
    return NULL;
 
116
  }
 
117
 
 
118
  /* convert and cast p from type_name to ptr as ty. */
 
119
  tc = SWIG_TypeCheck(type_name, ty);
 
120
  if (!tc) return NULL;
 
121
  return SWIG_TypeCast(tc, p);
125
122
}
126
123
 
127
 
/* This function fills ptr with a pointer of type ty by extracting the pointer
128
 
   and type info from the resource in z.  z must be a resource
 
124
/* This function returns a pointer of type ty by extracting the pointer
 
125
   and type info from the resource in z.  z must be a resource.
 
126
   If it fails, NULL is returned.
129
127
   It uses SWIG_ZTS_ConvertResourceData to do the real work. */
130
 
static int
131
 
SWIG_ZTS_ConvertResourcePtr(zval *z, void **ptr, swig_type_info *ty, int flags TSRMLS_DC) {
 
128
static void *
 
129
SWIG_ZTS_ConvertResourcePtr(zval *z, swig_type_info *ty, int flags TSRMLS_DC) {
132
130
  swig_object_wrapper *value;
133
131
  void *p;
134
132
  int type;
135
133
  char *type_name;
136
134
 
137
 
  value = (swig_object_wrapper *) zend_list_find(z->value.lval,&type);
 
135
  value = (swig_object_wrapper *) zend_list_find(z->value.lval, &type);
138
136
  if ( flags && SWIG_POINTER_DISOWN ) {
139
137
    value->newobject = 0;
140
138
  }
141
139
  p = value->ptr;
142
 
  if (type==-1) return -1;
 
140
  if (type==-1) return NULL;
143
141
 
144
142
  type_name=zend_rsrc_list_get_rsrc_type(z->value.lval TSRMLS_CC);
145
143
 
146
 
  return SWIG_ZTS_ConvertResourceData(p,type,type_name,ptr,ty TSRMLS_CC);
 
144
  return SWIG_ZTS_ConvertResourceData(p, type_name, ty TSRMLS_CC);
147
145
}
148
146
 
149
 
/* We allow passing of a STRING or RESOURCE pointing to the object
150
 
   or an OBJECT whose _cPtr is a string or resource pointing to the object
151
 
   STRING pointers are very depracated */
 
147
/* We allow passing of a RESOURCE pointing to the object or an OBJECT whose
 
148
   _cPtr is a resource pointing to the object */
152
149
static int
153
150
SWIG_ZTS_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags TSRMLS_DC) {
154
 
   char *c;
155
 
   zval *val;
156
 
   
157
 
   if(z == NULL) {
158
 
        *ptr = 0;
159
 
        return 0;
160
 
   }
161
 
 
162
 
   if (z->type==IS_OBJECT) {
163
 
     zval ** _cPtr;
164
 
     if (zend_hash_find(HASH_OF(z),"_cPtr",sizeof("_cPtr"),(void**)&_cPtr)==SUCCESS) {
165
 
       /* Don't co-erce to string if it isn't */
166
 
       if ((*_cPtr)->type==IS_STRING) c = Z_STRVAL_PP(_cPtr);
167
 
       else if ((*_cPtr)->type==IS_RESOURCE) {
168
 
         return SWIG_ZTS_ConvertResourcePtr(*_cPtr,ptr,ty, flags TSRMLS_CC);
169
 
       } else goto type_error; /* _cPtr was not string or resource property */
170
 
     } else goto type_error; /* can't find property _cPtr */
171
 
   } else if (z->type==IS_RESOURCE) {
172
 
     return SWIG_ZTS_ConvertResourcePtr(z,ptr,ty, flags TSRMLS_CC);
173
 
   } if (z->type==IS_NULL ) {
174
 
     *ptr = 0;
175
 
     return 0;
176
 
   } else goto type_error;
177
 
 
178
 
type_error:
179
 
 
180
 
    return -1;
 
151
  if (z == NULL) {
 
152
    *ptr = 0;
 
153
    return 0;
 
154
  }
 
155
 
 
156
  switch (z->type) {
 
157
    case IS_OBJECT: {
 
158
      zval ** _cPtr;
 
159
      if (zend_hash_find(HASH_OF(z),"_cPtr",sizeof("_cPtr"),(void**)&_cPtr)==SUCCESS) {
 
160
        if ((*_cPtr)->type==IS_RESOURCE) {
 
161
          *ptr = SWIG_ZTS_ConvertResourcePtr(*_cPtr, ty, flags TSRMLS_CC);
 
162
          return (*ptr == NULL ? -1 : 0);
 
163
        }
 
164
      }
 
165
      break;
 
166
    }
 
167
    case IS_RESOURCE:
 
168
      *ptr = SWIG_ZTS_ConvertResourcePtr(z, ty, flags TSRMLS_CC);
 
169
      return (*ptr == NULL ? -1 : 0);
 
170
    case IS_NULL:
 
171
      *ptr = 0;
 
172
      return 0;
 
173
  }
 
174
 
 
175
  return -1;
181
176
}
182
177
 
183
178
static char const_name[] = "swig_runtime_data_type_pointer";