Refactor Code to use swig_object_wrapper for wrapping classes.
And use void * to store class pointers.
This commit is contained in:
parent
05c25a71d6
commit
4c55919975
3 changed files with 113 additions and 156 deletions
|
|
@ -119,9 +119,8 @@
|
|||
|
||||
%typemap(in) SWIGTYPE &
|
||||
%{
|
||||
/*if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL)
|
||||
if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL)
|
||||
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor");
|
||||
*/
|
||||
%}
|
||||
|
||||
%typemap(in) SWIGTYPE &&
|
||||
|
|
@ -142,8 +141,8 @@
|
|||
%typemap(in) SWIGTYPE *DISOWN
|
||||
%{
|
||||
if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) {
|
||||
Z_$upper_param_OBJ_P(&$input)->newobject = 0;
|
||||
$1 = Z_$upper_param_OBJ_P(&$input)->$lower_param_obj;
|
||||
Z_FETCH_OBJ_P(&$input)->newobject = 0;
|
||||
$1 = ($lower_param *)Z_FETCH_OBJ_P(&$input)->ptr;
|
||||
}
|
||||
else {
|
||||
if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0)
|
||||
|
|
@ -482,11 +481,8 @@
|
|||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE
|
||||
{
|
||||
if (Z_TYPE($input) == IS_OBJECT && SWIG_is_correct_object(&$input,$1_descriptor))
|
||||
_v = 1;
|
||||
else
|
||||
_v = 0;
|
||||
//_v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $1_descriptor, 0) >= 0);
|
||||
void *tmp;
|
||||
_v = (SWIG_ConvertPtr(&$input, (void **)&tmp, $1_descriptor, 0) >= 0);
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER)
|
||||
|
|
@ -496,29 +492,20 @@
|
|||
SWIGTYPE &&,
|
||||
SWIGTYPE *const&
|
||||
{
|
||||
if (Z_TYPE($input) == IS_OBJECT && SWIG_is_correct_object(&$input,$1_descriptor))
|
||||
_v = 1;
|
||||
else
|
||||
_v = 0;
|
||||
//_v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $1_descriptor, 0) >= 0);
|
||||
void *tmp;
|
||||
_v = (SWIG_ConvertPtr(&$input, (void **)&tmp, $1_descriptor, 0) >= 0);
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *const&
|
||||
{
|
||||
if (Z_TYPE($input) == IS_OBJECT && SWIG_is_correct_object(&$input,$1_descriptor))
|
||||
_v = 1;
|
||||
else
|
||||
_v = 0;
|
||||
//_v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $1_descriptor, 0) >= 0);
|
||||
void *tmp;
|
||||
_v = (SWIG_ConvertPtr(&$input, (void **)&tmp, $1_descriptor, 0) >= 0);
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_VOIDPTR) void *
|
||||
{
|
||||
if (Z_TYPE($input) == IS_OBJECT && SWIG_is_correct_object(&$input,$1_descriptor))
|
||||
_v = 1;
|
||||
else
|
||||
_v = 0;
|
||||
//_v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $1_descriptor, 0) >= 0);
|
||||
void *tmp;
|
||||
_v = (SWIG_ConvertPtr(&$input, (void **)&tmp, $1_descriptor, 0) >= 0);
|
||||
}
|
||||
|
||||
/* Exception handling */
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ static int default_error_code = E_ERROR;
|
|||
and need freeing, or not */
|
||||
typedef struct {
|
||||
void * ptr;
|
||||
zend_object std;
|
||||
HashTable *extras;
|
||||
int newobject;
|
||||
} swig_object_wrapper;
|
||||
|
||||
|
|
@ -258,46 +260,9 @@ SWIG_SetZval( zval *zv, int object, int class_obj ,void *ptr, swig_type_info *ty
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
is_derived_class(zend_class_entry *child_class, zend_class_entry *parent_class) /* {{{ */
|
||||
{
|
||||
child_class = child_class->parent;
|
||||
while (child_class) {
|
||||
if (child_class == parent_class) {
|
||||
return 1;
|
||||
}
|
||||
child_class = child_class->parent;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SWIG_is_correct_object (zval *zv, swig_type_info *ty) {
|
||||
|
||||
int return_value = 0;
|
||||
|
||||
int excess = strlen(strchr(SWIG_TypePrettyName(ty),' '));
|
||||
if (excess == 0)
|
||||
excess = strlen(strchr(SWIG_TypePrettyName(ty),'*'));
|
||||
|
||||
int needed_length = strlen(SWIG_TypePrettyName(ty))-excess;
|
||||
|
||||
char *ty_name = (char *)malloc(needed_length);
|
||||
memcpy(ty_name,SWIG_TypePrettyName(ty),needed_length);
|
||||
|
||||
zend_class_entry *lookup_ce = zend_lookup_class(zend_string_init(ty_name, needed_length , 0));
|
||||
zend_string *zend_class_name = zend_string_copy(Z_OBJ_P(zv)->ce->name);
|
||||
zend_class_entry *zval_ce = zend_lookup_class(zend_class_name);
|
||||
|
||||
if (!zval_ce || !lookup_ce)
|
||||
return 0;
|
||||
|
||||
if (strcmp(zend_class_name->val,ty_name)) {
|
||||
if (is_derived_class(zval_ce,lookup_ce))
|
||||
return_value = 1;
|
||||
}
|
||||
else
|
||||
return_value = 1;
|
||||
|
||||
return return_value;
|
||||
#define Z_FETCH_OBJ_P(zv) php_fetch_object(Z_OBJ_P(zv))
|
||||
|
||||
static inline
|
||||
swig_object_wrapper * php_fetch_object(zend_object *obj) {
|
||||
return (swig_object_wrapper *)((char *)obj - XtOffsetOf(swig_object_wrapper, std));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue