Merge branch 'master' into gsoc2017-php7-classes-via-c-api

This commit is contained in:
Olly Betts 2021-03-26 12:00:59 +13:00
commit 2ba0f82720
16 changed files with 111 additions and 65 deletions

View file

@ -3,41 +3,41 @@
you have:
---- geometry.h --------
struct Geometry {
enum GeomType{
POINT,
CIRCLE
};
virtual ~Geometry() {}
struct Geometry {
enum GeomType{
POINT,
CIRCLE
};
virtual ~Geometry() {}
virtual int draw() = 0;
//
// Factory method for all the Geometry objects
//
static Geometry *create(GeomType i);
};
struct Point : Geometry {
int draw() { return 1; }
double width() { return 1.0; }
};
struct Circle : Geometry {
int draw() { return 2; }
double radius() { return 1.5; }
};
static Geometry *create(GeomType i);
};
struct Point : Geometry {
int draw() { return 1; }
double width() { return 1.0; }
};
struct Circle : Geometry {
int draw() { return 2; }
double radius() { return 1.5; }
};
//
// Factory method for all the Geometry objects
//
Geometry *Geometry::create(GeomType type) {
switch (type) {
case POINT: return new Point();
case CIRCLE: return new Circle();
default: return 0;
}
}
switch (type) {
case POINT: return new Point();
case CIRCLE: return new Circle();
default: return 0;
}
}
---- geometry.h --------
@ -57,16 +57,16 @@
NOTES: remember to fully qualify all the type names and don't
use %factory inside a namespace declaration, ie, instead of
namespace Foo {
%factory(Geometry *Geometry::create, Point, Circle);
}
use
%factory(Foo::Geometry *Foo::Geometry::create, Foo::Point, Foo::Circle);
%factory(Foo::Geometry *Foo::Geometry::create, Foo::Point, Foo::Circle);
*/
/* for loop for macro with one argument */
@ -90,14 +90,14 @@
/* for loop for macro with two arguments */
%define %formacro_2(macro,...)%_formacro_2(macro, __VA_ARGS__, __fordone__)%enddef
%define %_factory_dispatch(Type)
%define %_factory_dispatch(Type)
if (!dcast) {
Type *dobj = dynamic_cast<Type *>($1);
if (dobj) {
dcast = 1;
zend_object *std = $descriptor(Type)##_ce->create_object($descriptor(Type)##_ce);
SWIG_SetZval(return_value, $needNewFlow, $owner, SWIG_as_voidptr(dobj), $descriptor(Type *), std);
}
}
}%enddef
%define %factory(Method,Types...)

View file

@ -176,7 +176,8 @@
%{
if (SWIG_ConvertPtr(&$input, (void **) &$1, 0, 0) < 0) {
/* Allow NULL from php for void* */
if (Z_ISNULL($input)) $1=0;
if (Z_ISNULL($input))
$1=0;
else
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor");
}

View file

@ -55,6 +55,7 @@ PHPKW(endwhile);
PHPKW(extends);
PHPKW(final);
PHPKW(finally);
PHPKW(fn); // as of PHP 7.4
PHPKW(for);
PHPKW(foreach);
PHPKW(function);
@ -65,6 +66,7 @@ PHPKW(implements);
PHPKW(instanceof);
PHPKW(insteadof);
PHPKW(interface);
PHPKW(match); // as of PHP 8.0
PHPKW(namespace);
PHPKW(new);
PHPKW(or);

View file

@ -154,7 +154,7 @@ SWIG_ConvertResourceData(void * p, const char *type_name, swig_type_info *ty) {
return p;
}
if (! type_name) {
if (! type_name) {
/* can't convert p to ptr type ty if we don't know what type p is */
return NULL;
}

View file

@ -7,4 +7,3 @@
%include <std/std_except.i>
%apply size_t { std::size_t };

View file

@ -35,7 +35,7 @@ namespace std {
map();
map(const map& other);
unsigned int size() const;
void clear();
%extend {

View file

@ -112,5 +112,3 @@ namespace std {
%define specialize_std_vector(T)
#warning "specialize_std_vector - specialization for type T no longer needed"
%enddef

View file

@ -7,4 +7,3 @@
%include <std_vector.i>
%include <std_map.i>
%include <std_pair.i>