Add overload Support.

Use in house SWIG_overload_dispatch for class overloaded methods.
This commit is contained in:
Nihal 2017-07-11 21:08:13 +05:30
commit a71b349204
3 changed files with 290 additions and 43 deletions

View file

@ -119,9 +119,9 @@
%typemap(in) SWIGTYPE &
%{
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");
}
/*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 &&
@ -482,8 +482,11 @@
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE
{
void *tmp;
_v = (SWIG_ConvertPtr(&$input, (void **)&tmp, $&1_descriptor, 0) >= 0);
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);
}
%typecheck(SWIG_TYPECHECK_POINTER)
@ -493,20 +496,29 @@
SWIGTYPE &&,
SWIGTYPE *const&
{
void *tmp;
_v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $1_descriptor, 0) >= 0);
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);
}
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *const&
{
void *tmp;
_v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $*1_descriptor, 0) >= 0);
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);
}
%typecheck(SWIG_TYPECHECK_VOIDPTR) void *
{
void *tmp;
_v = (SWIG_ConvertPtr(&$input, (void**)&tmp, 0, 0) >= 0);
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);
}
/* Exception handling */

View file

@ -257,3 +257,47 @@ SWIG_SetZval( zval *zv, int object, int class_obj ,void *ptr, swig_type_info *ty
SWIG_SetPointerZval(zv,ptr,type,class_obj);
}
}
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;
}