Fix the easiest warnings in the generated code.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9212 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Olly Betts 2006-07-11 04:53:33 +00:00
commit afa9552b5c
2 changed files with 74 additions and 78 deletions

View file

@ -63,12 +63,12 @@ typedef struct _swig_object_wrapper {
} swig_object_wrapper; } swig_object_wrapper;
/* empty zend destructor for types without one */ /* empty zend destructor for types without one */
static ZEND_RSRC_DTOR_FUNC(SWIG_landfill) {}; static ZEND_RSRC_DTOR_FUNC(SWIG_landfill) { (void)rsrc; }
#define SWIG_SetPointerZval(a,b,c,d) SWIG_ZTS_SetPointerZval(a,b,c,d, SWIG_module_entry TSRMLS_CC) #define SWIG_SetPointerZval(a,b,c,d) SWIG_ZTS_SetPointerZval(a,b,c,d TSRMLS_CC)
static void static void
SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject, zend_module_entry* module_entry TSRMLS_DC) { SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject TSRMLS_DC) {
swig_object_wrapper *value=NULL; swig_object_wrapper *value=NULL;
/* /*
* First test for Null pointers. Return those as PHP native NULL * First test for Null pointers. Return those as PHP native NULL
@ -85,99 +85,95 @@ SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject,
value->newobject=newobject; value->newobject=newobject;
ZEND_REGISTER_RESOURCE(z, value, *(int *)(type->clientdata)); ZEND_REGISTER_RESOURCE(z, value, *(int *)(type->clientdata));
return; return;
} else { /* have to deal with old fashioned string pointer?
but this should not get this far */
zend_error(E_ERROR, "Type: %s not registered with zend",type->name);
} }
zend_error(E_ERROR, "Type: %s not registered with zend",type->name);
} }
/* This is a new pointer conversion routine /* This pointer conversion routine takes the native pointer p (along with
Taking the native pointer p (which would have been converted from the old its type name) and converts it by calling appropriate casting functions
string pointer) and its php type id, and its type name (which also would according to ty. The resultant pointer is returned, or NULL is returned
have come from the old string pointer) it converts it to ptr calling if the pointer can't be cast.
appropriate casting functions according to ty
Sadly PHP has no API to find a type name from a type id, only from an instance Sadly PHP has no API to find a type name from a type id, only from an
of a resource of the type id, so we have to pass type_name as well. instance of a resource of the type id, so we have to pass type_name as well.
The two functions which might call this are: The two functions which might call this are:
SWIG_ZTS_ConvertResourcePtr which gets the type name from the resource SWIG_ZTS_ConvertResourcePtr which gets the type name from the resource
and the registered zend destructors for which we have one per type each and the registered zend destructors for which we have one per type each
with the type name hard wired in. */ with the type name hard wired in. */
static int static void *
SWIG_ZTS_ConvertResourceData(void * p, int type, const char *type_name, void **ptr, swig_type_info *ty TSRMLS_DC) { SWIG_ZTS_ConvertResourceData(void * p, const char *type_name, swig_type_info *ty TSRMLS_DC) {
swig_cast_info *tc; swig_cast_info *tc;
if (ty) { if (!ty) {
if (! type_name) {
/* can't convert p to ptr type ty if we don't know what type p is */
return -1;
} else {
/* convert and cast p from type_name to ptr as ty
Need to sort out const-ness, can SWIG_TypeCast really not take a const? */
tc = SWIG_TypeCheck((char *)type_name,ty);
if (!tc) return -1;
*ptr = SWIG_TypeCast(tc, (void*)p);
}
} else {
/* They don't care about the target type, so just pass on the pointer! */ /* They don't care about the target type, so just pass on the pointer! */
*ptr = (void *) p; return p;
} }
return 0;
if (! type_name) {
/* can't convert p to ptr type ty if we don't know what type p is */
return NULL;
}
/* convert and cast p from type_name to ptr as ty
Need to sort out const-ness, can SWIG_TypeCast really not take a const? */
tc = SWIG_TypeCheck((char *)type_name,ty);
if (!tc) return NULL;
return SWIG_TypeCast(tc, p);
} }
/* This function fills ptr with a pointer of type ty by extracting the pointer /* This function returns a pointer of type ty by extracting the pointer
and type info from the resource in z. z must be a resource and type info from the resource in z. z must be a resource.
If it fails, NULL is returned.
It uses SWIG_ZTS_ConvertResourceData to do the real work. */ It uses SWIG_ZTS_ConvertResourceData to do the real work. */
static int static void *
SWIG_ZTS_ConvertResourcePtr(zval *z, void **ptr, swig_type_info *ty, int flags TSRMLS_DC) { SWIG_ZTS_ConvertResourcePtr(zval *z, swig_type_info *ty, int flags TSRMLS_DC) {
swig_object_wrapper *value; swig_object_wrapper *value;
void *p; void *p;
int type; int type;
char *type_name; char *type_name;
value = (swig_object_wrapper *) zend_list_find(z->value.lval,&type); value = (swig_object_wrapper *) zend_list_find(z->value.lval, &type);
if ( flags && SWIG_POINTER_DISOWN ) { if ( flags && SWIG_POINTER_DISOWN ) {
value->newobject = 0; value->newobject = 0;
} }
p = value->ptr; p = value->ptr;
if (type==-1) return -1; if (type==-1) return NULL;
type_name=zend_rsrc_list_get_rsrc_type(z->value.lval TSRMLS_CC); type_name=zend_rsrc_list_get_rsrc_type(z->value.lval TSRMLS_CC);
return SWIG_ZTS_ConvertResourceData(p,type,type_name,ptr,ty TSRMLS_CC); return SWIG_ZTS_ConvertResourceData(p, type_name, ty TSRMLS_CC);
} }
/* We allow passing of a STRING or RESOURCE pointing to the object /* We allow passing of a RESOURCE pointing to the object or an OBJECT whose
or an OBJECT whose _cPtr is a string or resource pointing to the object _cPtr is a resource pointing to the object */
STRING pointers are very depracated */
static int static int
SWIG_ZTS_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags TSRMLS_DC) { SWIG_ZTS_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags TSRMLS_DC) {
char *c; if (z == NULL) {
zval *val; *ptr = 0;
return 0;
if(z == NULL) { }
*ptr = 0;
return 0;
}
if (z->type==IS_OBJECT) { switch (z->type) {
zval ** _cPtr; case IS_OBJECT: {
if (zend_hash_find(HASH_OF(z),"_cPtr",sizeof("_cPtr"),(void**)&_cPtr)==SUCCESS) { zval ** _cPtr;
/* Don't co-erce to string if it isn't */ if (zend_hash_find(HASH_OF(z),"_cPtr",sizeof("_cPtr"),(void**)&_cPtr)==SUCCESS) {
if ((*_cPtr)->type==IS_STRING) c = Z_STRVAL_PP(_cPtr); if ((*_cPtr)->type==IS_RESOURCE) {
else if ((*_cPtr)->type==IS_RESOURCE) { *ptr = SWIG_ZTS_ConvertResourcePtr(*_cPtr, ty, flags TSRMLS_CC);
return SWIG_ZTS_ConvertResourcePtr(*_cPtr,ptr,ty, flags TSRMLS_CC); return (ptr == NULL ? -1 : 0);
} else goto type_error; /* _cPtr was not string or resource property */ }
} else goto type_error; /* can't find property _cPtr */ }
} else if (z->type==IS_RESOURCE) { break;
return SWIG_ZTS_ConvertResourcePtr(z,ptr,ty, flags TSRMLS_CC); }
} if (z->type==IS_NULL ) { case IS_RESOURCE:
*ptr = 0; *ptr = SWIG_ZTS_ConvertResourcePtr(z, ty, flags TSRMLS_CC);
return 0; return (ptr == NULL ? -1 : 0);
} else goto type_error; case IS_NULL:
*ptr = 0;
return 0;
}
type_error: return -1;
return -1;
} }
static char const_name[] = "swig_runtime_data_type_pointer"; static char const_name[] = "swig_runtime_data_type_pointer";

View file

@ -667,13 +667,13 @@ public:
Printf(s_header, "#define ErrorMsg() (%s_globals.error_msg)\n",module); Printf(s_header, "#define ErrorMsg() (%s_globals.error_msg)\n",module);
Printf(s_header, "#define ErrorCode() (%s_globals.error_code)\n",module); Printf(s_header, "#define ErrorCode() (%s_globals.error_code)\n",module);
Printf(s_header, "#endif\n\n" ); Printf(s_header, "#endif\n\n" );
Printf(s_header, "static void %s_init_globals(zend_%s_globals *%s_globals ) {\n",module,module,module); Printf(s_header, "static void %s_init_globals(zend_%s_globals *globals ) {\n",module,module);
Printf(s_header, " %s_globals->error_msg = default_error_msg;\n", module); Printf(s_header, " globals->error_msg = default_error_msg;\n");
Printf(s_header, " %s_globals->error_code = default_error_code;\n",module); Printf(s_header, " globals->error_code = default_error_code;\n");
Printf(s_header, "}\n"); Printf(s_header, "}\n");
Printf(s_header, "static void %s_destroy_globals(zend_%s_globals *%s_globals) { }\n",module,module,module); Printf(s_header, "static void %s_destroy_globals(zend_%s_globals * globals) { (void)globals; }\n",module,module);
Printf(s_header, "\n"); Printf(s_header, "\n");
Printf(s_header, "static void SWIG_ResetError() {\n"); Printf(s_header, "static void SWIG_ResetError() {\n");
@ -920,8 +920,6 @@ public:
Printf(tmp,"zval **argv[%d]", maxargs); Printf(tmp,"zval **argv[%d]", maxargs);
Wrapper_add_local(f,"argv",tmp); Wrapper_add_local(f,"argv",tmp);
Wrapper_add_local(f,"ii","int ii");
Printf(f->code,"argc = ZEND_NUM_ARGS();\n"); Printf(f->code,"argc = ZEND_NUM_ARGS();\n");
if ( has_this_ptr ) { if ( has_this_ptr ) {
@ -1068,9 +1066,11 @@ public:
int has_this_ptr = (wrapperType==memberfn && shadow && php_version == 4); int has_this_ptr = (wrapperType==memberfn && shadow && php_version == 4);
String * args = NewStringf("zval **args[%d]", num_arguments-has_this_ptr); if (num_arguments-has_this_ptr > 0) {
Wrapper_add_local(f, "args",args); String * args = NewStringf("zval **args[%d]", num_arguments-has_this_ptr);
Delete(args); args = NULL; Wrapper_add_local(f, "args",args);
Delete(args); args = NULL;
}
// This generated code may be called: // This generated code may be called:
// 1) as an object method, or // 1) as an object method, or
@ -2701,12 +2701,12 @@ public:
Printf(df->code," efree(value);\n"); Printf(df->code," efree(value);\n");
Printf(df->code," if (! newobject) return; /* can't delete it! */\n"); Printf(df->code," if (! newobject) return; /* can't delete it! */\n");
Printf(df->code," SWIG_ZTS_ConvertResourceData(ptr,rsrc->type,type_name,(void **) &arg1,SWIGTYPE%s TSRMLS_CC);\n", Printf(df->code," arg1 = (%s)SWIG_ZTS_ConvertResourceData(ptr,type_name,SWIGTYPE%s TSRMLS_CC);\n",
SwigType_manglestr(pt)); SwigType_lstr(pt, 0), SwigType_manglestr(pt));
Printf(df->code," if (! arg1) zend_error(E_ERROR, \"%s resource already free'd\");\n", Char(name)); Printf(df->code," if (! arg1) zend_error(E_ERROR, \"%s resource already free'd\");\n", Char(name));
emit_action(n,df); emit_action(n,df);
Printf(df->code,"}\n"); Printf(df->code,"}\n");
Wrapper_print(df,s_wrappers); Wrapper_print(df,s_wrappers);