63
63
} swig_object_wrapper;
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; }
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)
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;
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));
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);
89
zend_error(E_ERROR, "Type: %s not registered with zend",type->name);
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.
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.
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. */
106
SWIG_ZTS_ConvertResourceData(void * p, int type, const char *type_name, void **ptr, swig_type_info *ty TSRMLS_DC) {
105
SWIG_ZTS_ConvertResourceData(void * p, const char *type_name, swig_type_info *ty TSRMLS_DC) {
107
106
swig_cast_info *tc;
111
/* can't convert p to ptr type ty if we don't know what type p is */
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);
118
*ptr = SWIG_TypeCast(tc, (void*)p);
121
109
/* They don't care about the target type, so just pass on the pointer! */
114
/* can't convert p to ptr type ty if we don't know what type p is */
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);
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. */
131
SWIG_ZTS_ConvertResourcePtr(zval *z, void **ptr, swig_type_info *ty, int flags TSRMLS_DC) {
129
SWIG_ZTS_ConvertResourcePtr(zval *z, swig_type_info *ty, int flags TSRMLS_DC) {
132
130
swig_object_wrapper *value;
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;
142
if (type==-1) return -1;
140
if (type==-1) return NULL;
144
142
type_name=zend_rsrc_list_get_rsrc_type(z->value.lval TSRMLS_CC);
146
return SWIG_ZTS_ConvertResourceData(p,type,type_name,ptr,ty TSRMLS_CC);
144
return SWIG_ZTS_ConvertResourceData(p, type_name, ty TSRMLS_CC);
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 */
153
150
SWIG_ZTS_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags TSRMLS_DC) {
162
if (z->type==IS_OBJECT) {
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 ) {
176
} else goto type_error;
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);
168
*ptr = SWIG_ZTS_ConvertResourcePtr(z, ty, flags TSRMLS_CC);
169
return (*ptr == NULL ? -1 : 0);
183
178
static char const_name[] = "swig_runtime_data_type_pointer";