Overload resolution now works in PHP out of the box.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9305 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
29098f6ad2
commit
3dc5e0e91a
6 changed files with 28 additions and 20 deletions
|
|
@ -1,6 +1,14 @@
|
|||
Version 1.3.30 (in progress)
|
||||
============================
|
||||
|
||||
09/20/2006: olly
|
||||
*** POTENTIAL INCOMPATIBILITY ***
|
||||
[php] Overload resolution now works. However to allow this, SWIG
|
||||
generated wrappers no longer coerce PHP types (which reverts a change
|
||||
made in 1.3.26). So for example, if a method takes a string, you
|
||||
can no longer pass a number without explicitly converting it to a
|
||||
string in PHP using: (string)x
|
||||
|
||||
09/20/2006: olly
|
||||
[php] Previously -noproxy was required when wrapping some C code
|
||||
to avoid SWIG generating new_XXX methods. Now proxy classes are
|
||||
|
|
|
|||
|
|
@ -42,6 +42,10 @@ char *overloaded(double d) {
|
|||
return "Overloaded with double";
|
||||
}
|
||||
|
||||
char *overloaded(const char * str) {
|
||||
return "Overloaded with char *";
|
||||
}
|
||||
|
||||
char *overloaded( const Circle& ) {
|
||||
return "Overloaded with Circle";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ public:
|
|||
}
|
||||
virtual ~Shape() {
|
||||
nshapes--;
|
||||
};
|
||||
double x, y;
|
||||
}
|
||||
double x, y;
|
||||
void move(double dx, double dy);
|
||||
virtual double area(void) = 0;
|
||||
virtual double perimeter(void) = 0;
|
||||
|
|
@ -22,8 +22,8 @@ class Circle : public Shape {
|
|||
private:
|
||||
double radius;
|
||||
public:
|
||||
Circle(double r) : radius(r) { };
|
||||
~Circle() { };
|
||||
Circle(double r) : radius(r) { }
|
||||
~Circle() { }
|
||||
virtual double area(void);
|
||||
virtual double perimeter(void);
|
||||
};
|
||||
|
|
@ -32,7 +32,7 @@ class Square : public Shape {
|
|||
private:
|
||||
double width;
|
||||
public:
|
||||
Square(double w) : width(w) { };
|
||||
Square(double w) : width(w) { }
|
||||
~Square() { }
|
||||
virtual double area(void);
|
||||
virtual double perimeter(void);
|
||||
|
|
@ -40,6 +40,7 @@ public:
|
|||
|
||||
char *overloaded( int i );
|
||||
char *overloaded( double d );
|
||||
char *overloaded( const char * str );
|
||||
char *overloaded( const Circle& );
|
||||
char *overloaded( const Shape& );
|
||||
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ print " Square = (" . $s->x . "," . $s->y . ")\n";
|
|||
# ----- Call some methods -----
|
||||
|
||||
print "\nHere are some properties of the shapes:\n";
|
||||
foreach (array(1,2.1,"3.6",$c,$s) as $o) {
|
||||
foreach (array(1, 2.1, "quick brown fox", $c, $s) as $o) {
|
||||
print " ".get_class($o)." $o\n";
|
||||
print " overloaded= " . overloaded($o) . "\n";
|
||||
print " overloaded = " . overloaded($o) . "\n";
|
||||
}
|
||||
|
||||
# Need to unset($o) or else we hang on to a reference to the Square object.
|
||||
|
|
|
|||
|
|
@ -229,17 +229,12 @@
|
|||
RETVAL_STRINGL($1,$1_dim0,1);
|
||||
}
|
||||
|
||||
// This typecheck would do hard checking for proper argument type.
|
||||
//%define %php_typecheck(_type,_prec,is)
|
||||
//%typemap(typecheck,precedence=_prec) _type
|
||||
// " $1 = Z_TYPE_PP($input) == is ? 1 : 0; "
|
||||
//%enddef
|
||||
|
||||
// This typecheck does hard checking for proper argument type. If you want
|
||||
// an argument to be converted from a different PHP type, you must convert
|
||||
// it yourself before passing it (e.g. (string)4.7 or (int)"6").
|
||||
%define %php_typecheck(_type,_prec,is)
|
||||
%typemap(typecheck,precedence=_prec) _type
|
||||
" $1 = (Z_TYPE_PP($input) == IS_LONG ||
|
||||
Z_TYPE_PP($input) == IS_DOUBLE ||
|
||||
Z_TYPE_PP($input) == IS_STRING) ? 1 : 0; "
|
||||
" $1 = (Z_TYPE_PP($input) == is); "
|
||||
%enddef
|
||||
|
||||
%php_typecheck(int,SWIG_TYPECHECK_INTEGER,IS_LONG)
|
||||
|
|
@ -269,11 +264,11 @@
|
|||
SWIGTYPE &
|
||||
{
|
||||
void *tmp;
|
||||
_v = (SWIG_ConvertPtr( *$input, (void**)&tmp, $1_descriptor, 0) < 0)? 0:1;
|
||||
_v = (SWIG_ConvertPtr( *$input, (void**)&tmp, $1_descriptor, 0) >= 0);
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_VOIDPTR) void *
|
||||
" /* tyepcheck void * */ "
|
||||
" /* typecheck void * */ "
|
||||
|
||||
|
||||
/* Exception handling */
|
||||
|
|
|
|||
|
|
@ -159,14 +159,14 @@ SWIG_ZTS_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags TSRMLS_DC
|
|||
if (zend_hash_find(HASH_OF(z),"_cPtr",sizeof("_cPtr"),(void**)&_cPtr)==SUCCESS) {
|
||||
if ((*_cPtr)->type==IS_RESOURCE) {
|
||||
*ptr = SWIG_ZTS_ConvertResourcePtr(*_cPtr, ty, flags TSRMLS_CC);
|
||||
return (ptr == NULL ? -1 : 0);
|
||||
return (*ptr == NULL ? -1 : 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IS_RESOURCE:
|
||||
*ptr = SWIG_ZTS_ConvertResourcePtr(z, ty, flags TSRMLS_CC);
|
||||
return (ptr == NULL ? -1 : 0);
|
||||
return (*ptr == NULL ? -1 : 0);
|
||||
case IS_NULL:
|
||||
*ptr = 0;
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue