merge revisions 11243-11872 from trunk to gsoc2009-matevz
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@12162 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
commit
ab1cd03979
387 changed files with 12383 additions and 4412 deletions
|
|
@ -48,3 +48,6 @@
|
|||
c.module_number = module_number;
|
||||
zend_register_constant( &c TSRMLS_CC );
|
||||
}
|
||||
|
||||
/* Handled as a global variable. */
|
||||
%typemap(consttab) SWIGTYPE (CLASS::*) "";
|
||||
|
|
|
|||
198
Lib/php/director.swg
Normal file
198
Lib/php/director.swg
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* See the LICENSE file for information on copyright, usage and redistribution
|
||||
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
|
||||
*
|
||||
* director.swg
|
||||
*
|
||||
* This file contains support for director classes that proxy
|
||||
* method calls from C++ to PHP extensions.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef SWIG_DIRECTOR_PHP_HEADER_
|
||||
#define SWIG_DIRECTOR_PHP_HEADER_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
/*
|
||||
Use -DSWIG_DIRECTOR_STATIC if you prefer to avoid the use of the
|
||||
'Swig' namespace. This could be useful for multi-modules projects.
|
||||
*/
|
||||
#ifdef SWIG_DIRECTOR_STATIC
|
||||
/* Force anonymous (static) namespace */
|
||||
#define Swig
|
||||
#endif
|
||||
|
||||
namespace Swig {
|
||||
/* memory handler */
|
||||
struct GCItem
|
||||
{
|
||||
virtual ~GCItem() {}
|
||||
|
||||
virtual int get_own() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct GCItem_var
|
||||
{
|
||||
GCItem_var(GCItem *item = 0) : _item(item)
|
||||
{
|
||||
}
|
||||
|
||||
GCItem_var& operator=(GCItem *item)
|
||||
{
|
||||
GCItem *tmp = _item;
|
||||
_item = item;
|
||||
delete tmp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
~GCItem_var()
|
||||
{
|
||||
delete _item;
|
||||
}
|
||||
|
||||
GCItem * operator->() const
|
||||
{
|
||||
return _item;
|
||||
}
|
||||
|
||||
private:
|
||||
GCItem *_item;
|
||||
};
|
||||
|
||||
struct GCItem_Object : GCItem
|
||||
{
|
||||
GCItem_Object(int own) : _own(own)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~GCItem_Object()
|
||||
{
|
||||
}
|
||||
|
||||
int get_own() const
|
||||
{
|
||||
return _own;
|
||||
}
|
||||
|
||||
private:
|
||||
int _own;
|
||||
};
|
||||
|
||||
template <typename Type>
|
||||
struct GCItem_T : GCItem
|
||||
{
|
||||
GCItem_T(Type *ptr) : _ptr(ptr)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~GCItem_T()
|
||||
{
|
||||
delete _ptr;
|
||||
}
|
||||
|
||||
private:
|
||||
Type *_ptr;
|
||||
};
|
||||
|
||||
class Director {
|
||||
protected:
|
||||
zval *swig_self;
|
||||
typedef std::map<void*, GCItem_var> ownership_map;
|
||||
mutable ownership_map owner;
|
||||
public:
|
||||
Director(zval* self) : swig_self(self) {
|
||||
}
|
||||
|
||||
~Director() {
|
||||
for (ownership_map::iterator i = owner.begin(); i != owner.end(); i++) {
|
||||
owner.erase(i);
|
||||
}
|
||||
}
|
||||
|
||||
bool is_overriden_method(char *cname, char *lc_fname) {
|
||||
zval classname;
|
||||
zend_class_entry **ce;
|
||||
zend_function *mptr;
|
||||
int name_len = strlen(lc_fname);
|
||||
|
||||
ZVAL_STRING(&classname, cname, 0);
|
||||
if (zend_lookup_class(Z_STRVAL_P(&classname), Z_STRLEN_P(&classname), &ce TSRMLS_CC) != SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
if (zend_hash_find(&(*ce)->function_table, lc_fname, name_len + 1, (void**) &mptr) != SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
// common.scope points to the declaring class
|
||||
return strcmp(mptr->common.scope->name, cname);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
void swig_acquire_ownership(Type *vptr) const
|
||||
{
|
||||
if (vptr) {
|
||||
owner[vptr] = new GCItem_T<Type>(vptr);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* base class for director exceptions */
|
||||
class DirectorException {
|
||||
protected:
|
||||
std::string swig_msg;
|
||||
public:
|
||||
DirectorException(int code, const char *hdr, const char* msg)
|
||||
: swig_msg(hdr)
|
||||
{
|
||||
if (strlen(msg)) {
|
||||
swig_msg += " ";
|
||||
swig_msg += msg;
|
||||
}
|
||||
SWIG_ErrorCode() = code;
|
||||
SWIG_ErrorMsg() = swig_msg.c_str();
|
||||
}
|
||||
|
||||
static void raise(int code, const char *hdr, const char* msg)
|
||||
{
|
||||
throw DirectorException(code, hdr, msg);
|
||||
}
|
||||
};
|
||||
|
||||
/* attempt to call a pure virtual method via a director method */
|
||||
class DirectorPureVirtualException : public Swig::DirectorException
|
||||
{
|
||||
public:
|
||||
DirectorPureVirtualException(const char* msg)
|
||||
: DirectorException(E_ERROR, "SWIG director pure virtual method called", msg)
|
||||
{
|
||||
}
|
||||
|
||||
static void raise(const char *msg)
|
||||
{
|
||||
throw DirectorPureVirtualException(msg);
|
||||
}
|
||||
};
|
||||
/* any php exception that occurs during a director method call */
|
||||
class DirectorMethodException : public Swig::DirectorException
|
||||
{
|
||||
public:
|
||||
DirectorMethodException(const char* msg = "")
|
||||
: DirectorException(E_ERROR, "SWIG director method error", msg)
|
||||
{
|
||||
}
|
||||
|
||||
static void raise(const char *msg)
|
||||
{
|
||||
throw DirectorMethodException(msg);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
109
Lib/php/factory.i
Normal file
109
Lib/php/factory.i
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
Implement a more natural wrap for factory methods, for example, if
|
||||
you have:
|
||||
|
||||
---- geometry.h --------
|
||||
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; }
|
||||
};
|
||||
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
---- geometry.h --------
|
||||
|
||||
|
||||
You can use the %factory with the Geometry::create method as follows:
|
||||
|
||||
%newobject Geometry::create;
|
||||
%factory(Geometry *Geometry::create, Point, Circle);
|
||||
%include "geometry.h"
|
||||
|
||||
and Geometry::create will return a 'Point' or 'Circle' instance
|
||||
instead of the plain 'Geometry' type. For example, in python:
|
||||
|
||||
circle = Geometry.create(Geometry.CIRCLE)
|
||||
r = circle.radius()
|
||||
|
||||
where circle is a Circle proxy instance.
|
||||
|
||||
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);
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* for loop for macro with one argument */
|
||||
%define %_formacro_1(macro, arg1,...)macro(arg1)
|
||||
#if #__VA_ARGS__ != "__fordone__"
|
||||
%_formacro_1(macro, __VA_ARGS__)
|
||||
#endif
|
||||
%enddef
|
||||
|
||||
/* for loop for macro with one argument */
|
||||
%define %formacro_1(macro,...)%_formacro_1(macro,__VA_ARGS__,__fordone__)%enddef
|
||||
%define %formacro(macro,...)%_formacro_1(macro,__VA_ARGS__,__fordone__)%enddef
|
||||
|
||||
/* for loop for macro with two arguments */
|
||||
%define %_formacro_2(macro, arg1, arg2, ...)macro(arg1, arg2)
|
||||
#if #__VA_ARGS__ != "__fordone__"
|
||||
%_formacro_2(macro, __VA_ARGS__)
|
||||
#endif
|
||||
%enddef
|
||||
|
||||
/* for loop for macro with two arguments */
|
||||
%define %formacro_2(macro,...)%_formacro_2(macro, __VA_ARGS__, __fordone__)%enddef
|
||||
|
||||
%define %_factory_dispatch(Type)
|
||||
if (!dcast) {
|
||||
Type *dobj = dynamic_cast<Type *>($1);
|
||||
if (dobj) {
|
||||
dcast = 1;
|
||||
SWIG_SetPointerZval(return_value, SWIG_as_voidptr(dobj),$descriptor(Type *), $owner);
|
||||
}
|
||||
}%enddef
|
||||
|
||||
%define %factory(Method,Types...)
|
||||
%typemap(out) Method {
|
||||
int dcast = 0;
|
||||
%formacro(%_factory_dispatch, Types)
|
||||
if (!dcast) {
|
||||
SWIG_SetPointerZval(return_value, SWIG_as_voidptr($1),$descriptor, $owner);
|
||||
}
|
||||
}%enddef
|
||||
|
|
@ -102,6 +102,16 @@
|
|||
zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&z_var, sizeof(zval *), NULL);
|
||||
}
|
||||
|
||||
%typemap(varinit) SWIGTYPE (CLASS::*)
|
||||
{
|
||||
void * p = emalloc(sizeof($1));
|
||||
memcpy(p, &$1, sizeof($1));
|
||||
zval * resource;
|
||||
MAKE_STD_ZVAL(resource);
|
||||
ZEND_REGISTER_RESOURCE(resource, p, le_member_ptr);
|
||||
zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&resource, sizeof(zval *), NULL);
|
||||
}
|
||||
|
||||
%typemap(varin) int, unsigned int, short, unsigned short, long, unsigned long, signed char, unsigned char, enum SWIGTYPE
|
||||
{
|
||||
zval **z_var;
|
||||
|
|
@ -213,6 +223,15 @@
|
|||
$1 = ($1_ltype)_temp;
|
||||
}
|
||||
|
||||
%typemap(varin) SWIGTYPE (CLASS::*)
|
||||
{
|
||||
zval **z_var;
|
||||
|
||||
zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
|
||||
void * p = (void*)zend_fetch_resource(*z_var TSRMLS_CC, -1, SWIG_MEMBER_PTR, NULL, 1, le_member_ptr);
|
||||
memcpy(&$1, p, sizeof($1));
|
||||
}
|
||||
|
||||
%typemap(varout) int,
|
||||
unsigned int,
|
||||
unsigned short,
|
||||
|
|
@ -325,4 +344,12 @@ deliberate error cos this code looks bogus to me
|
|||
SWIG_SetPointerZval(*z_var, (void*)$1, $1_descriptor, 0);
|
||||
}
|
||||
|
||||
|
||||
%typemap(varout) SWIGTYPE (CLASS::*)
|
||||
{
|
||||
void * p = emalloc(sizeof($1));
|
||||
memcpy(p, &$1, sizeof($1));
|
||||
zval * resource;
|
||||
MAKE_STD_ZVAL(resource);
|
||||
ZEND_REGISTER_RESOURCE(resource, p, le_member_ptr);
|
||||
zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&resource, sizeof(zval *), NULL);
|
||||
}
|
||||
|
|
|
|||
187
Lib/php/php.swg
187
Lib/php/php.swg
|
|
@ -52,6 +52,10 @@
|
|||
%pass_by_val(long, CONVERT_INT_IN);
|
||||
%pass_by_val(unsigned long, CONVERT_INT_IN);
|
||||
|
||||
%pass_by_val(signed long long, CONVERT_LONG_LONG_IN);
|
||||
%pass_by_val(long long, CONVERT_LONG_LONG_IN);
|
||||
%pass_by_val(unsigned long long, CONVERT_UNSIGNED_LONG_LONG_IN);
|
||||
|
||||
%pass_by_val(signed char, CONVERT_INT_IN);
|
||||
%pass_by_val(char, CONVERT_CHAR_IN);
|
||||
%pass_by_val(unsigned char, CONVERT_INT_IN);
|
||||
|
|
@ -61,6 +65,8 @@
|
|||
%pass_by_val(double, CONVERT_FLOAT_IN);
|
||||
|
||||
%pass_by_val(char *, CONVERT_STRING_IN);
|
||||
%typemap(in) char *& = const char *&;
|
||||
%typemap(directorout) char *& = const char *&;
|
||||
|
||||
// char array can be in/out, though the passed string may not be big enough...
|
||||
// so we have to size it
|
||||
|
|
@ -86,6 +92,14 @@
|
|||
$1 = *tmp;
|
||||
}
|
||||
|
||||
%typemap(directorout) SWIGTYPE ($&1_ltype tmp)
|
||||
{
|
||||
if(SWIG_ConvertPtr(*$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) {
|
||||
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor");
|
||||
}
|
||||
$result = *tmp;
|
||||
}
|
||||
|
||||
%typemap(in) SWIGTYPE *,
|
||||
SWIGTYPE []
|
||||
{
|
||||
|
|
@ -101,6 +115,14 @@
|
|||
}
|
||||
}
|
||||
|
||||
%typemap(in) SWIGTYPE *& ($*ltype temp)
|
||||
{
|
||||
if(SWIG_ConvertPtr(*$input, (void **) &temp, $*1_descriptor, 0) < 0) {
|
||||
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor");
|
||||
}
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(in) SWIGTYPE *DISOWN
|
||||
{
|
||||
if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) {
|
||||
|
|
@ -173,22 +195,124 @@
|
|||
ZVAL_LONG(return_value,$1);
|
||||
}
|
||||
|
||||
%typemap(out) long long
|
||||
%{
|
||||
if ((long long)LONG_MIN <= $1 && $1 <= (long long)LONG_MAX) {
|
||||
return_value->value.lval = (long)($1);
|
||||
return_value->type = IS_LONG;
|
||||
} else {
|
||||
char temp[256];
|
||||
sprintf(temp, "%lld", $1);
|
||||
ZVAL_STRING(return_value, temp, 1);
|
||||
}
|
||||
%}
|
||||
%typemap(out) unsigned long long
|
||||
%{
|
||||
if ($1 <= (unsigned long long)LONG_MAX) {
|
||||
return_value->value.lval = (long)($1);
|
||||
return_value->type = IS_LONG;
|
||||
} else {
|
||||
char temp[256];
|
||||
sprintf(temp, "%llu", $1);
|
||||
ZVAL_STRING(return_value, temp, 1);
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap(out) const int &,
|
||||
const unsigned int &,
|
||||
const short &,
|
||||
const unsigned short &,
|
||||
const long &,
|
||||
const unsigned long &,
|
||||
const signed char &,
|
||||
const unsigned char &,
|
||||
const bool &,
|
||||
const size_t &,
|
||||
const enum SWIGTYPE &
|
||||
{
|
||||
ZVAL_LONG(return_value,*$1);
|
||||
}
|
||||
|
||||
%typemap(out) const long long &
|
||||
%{
|
||||
if ((long long)LONG_MIN <= *$1 && *$1 <= (long long)LONG_MAX) {
|
||||
return_value->value.lval = (long)(*$1);
|
||||
return_value->type = IS_LONG;
|
||||
} else {
|
||||
char temp[256];
|
||||
sprintf(temp, "%lld", *$1);
|
||||
ZVAL_STRING(return_value, temp, 1);
|
||||
}
|
||||
%}
|
||||
%typemap(out) const unsigned long long &
|
||||
%{
|
||||
if (*$1 <= (unsigned long long)LONG_MAX) {
|
||||
return_value->value.lval = (long)(*$1);
|
||||
return_value->type = IS_LONG;
|
||||
} else {
|
||||
char temp[256];
|
||||
sprintf(temp, "%llu", *$1);
|
||||
ZVAL_STRING(return_value, temp, 1);
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap(directorin) int,
|
||||
unsigned int,
|
||||
short,
|
||||
unsigned short,
|
||||
long,
|
||||
unsigned long,
|
||||
signed char,
|
||||
unsigned char,
|
||||
size_t,
|
||||
enum SWIGTYPE
|
||||
{
|
||||
ZVAL_LONG($input,$1_name);
|
||||
}
|
||||
|
||||
%typemap(out) bool
|
||||
{
|
||||
ZVAL_BOOL(return_value,($1)?1:0);
|
||||
}
|
||||
|
||||
%typemap(out) const bool &
|
||||
{
|
||||
ZVAL_BOOL(return_value,(*$1)?1:0);
|
||||
}
|
||||
|
||||
%typemap(directorin) bool
|
||||
{
|
||||
ZVAL_BOOL($input,($1_name)?1:0);
|
||||
}
|
||||
|
||||
%typemap(out) float,
|
||||
double
|
||||
{
|
||||
ZVAL_DOUBLE(return_value,$1);
|
||||
}
|
||||
|
||||
%typemap(out) const float &,
|
||||
const double &
|
||||
{
|
||||
ZVAL_DOUBLE(return_value,*$1);
|
||||
}
|
||||
|
||||
%typemap(directorin) float,
|
||||
double
|
||||
{
|
||||
ZVAL_DOUBLE($input,$1_name);
|
||||
}
|
||||
|
||||
%typemap(out) char
|
||||
{
|
||||
ZVAL_STRINGL(return_value,&$1, 1, 1);
|
||||
}
|
||||
|
||||
%typemap(out) const char &
|
||||
{
|
||||
ZVAL_STRINGL(return_value,&*$1, 1, 1);
|
||||
}
|
||||
|
||||
%typemap(out) char *,
|
||||
char []
|
||||
{
|
||||
|
|
@ -199,6 +323,15 @@
|
|||
}
|
||||
}
|
||||
|
||||
%typemap(out) char *&
|
||||
{
|
||||
if(!*$1) {
|
||||
ZVAL_NULL(return_value);
|
||||
} else {
|
||||
ZVAL_STRING(return_value, (char *)*$1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(out) SWIGTYPE *,
|
||||
SWIGTYPE [],
|
||||
SWIGTYPE &
|
||||
|
|
@ -206,6 +339,35 @@
|
|||
SWIG_SetPointerZval(return_value, (void *)$1, $1_descriptor, $owner);
|
||||
%}
|
||||
|
||||
%typemap(out) SWIGTYPE *&
|
||||
%{
|
||||
SWIG_SetPointerZval(return_value, (void *)*$1, $*1_descriptor, $owner);
|
||||
%}
|
||||
|
||||
%typemap(directorin) SWIGTYPE *,
|
||||
SWIGTYPE [],
|
||||
SWIGTYPE &
|
||||
%{
|
||||
SWIG_SetPointerZval($input, (void *)&$1_name, $1_descriptor, $owner);
|
||||
%}
|
||||
|
||||
%typemap(out) SWIGTYPE (CLASS::*)
|
||||
{
|
||||
void * p = emalloc(sizeof($1));
|
||||
memcpy(p, &$1, sizeof($1));
|
||||
zval * resource;
|
||||
MAKE_STD_ZVAL(resource);
|
||||
ZEND_REGISTER_RESOURCE(resource, p, le_member_ptr);
|
||||
|
||||
SWIG_SetPointerZval(return_value, (void *)&$1, $1_descriptor, $owner);
|
||||
}
|
||||
|
||||
%typemap(in) SWIGTYPE (CLASS::*)
|
||||
{
|
||||
void * p = (void*)zend_fetch_resource($input TSRMLS_CC, -1, SWIG_MEMBER_PTR, NULL, 1, le_member_ptr);
|
||||
memcpy(&$1, p, sizeof($1));
|
||||
}
|
||||
|
||||
%typemap(out) SWIGTYPE *DYNAMIC,
|
||||
SWIGTYPE &DYNAMIC
|
||||
{
|
||||
|
|
@ -227,6 +389,15 @@
|
|||
}
|
||||
#endif
|
||||
|
||||
%typemap(directorin) SWIGTYPE
|
||||
{
|
||||
SWIG_SetPointerZval($input, SWIG_as_voidptr(&$1_name), $&1_descriptor, 2);
|
||||
}
|
||||
|
||||
/* Array reference typemaps */
|
||||
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
|
||||
|
||||
|
||||
%typemap(out) void "";
|
||||
|
||||
%typemap(out) char [ANY]
|
||||
|
|
@ -240,7 +411,7 @@
|
|||
// 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
|
||||
%typemap(typecheck,precedence=_prec) _type, const _type &
|
||||
" $1 = (Z_TYPE_PP($input) == is); "
|
||||
%enddef
|
||||
|
||||
|
|
@ -250,18 +421,19 @@
|
|||
%php_typecheck(unsigned short,SWIG_TYPECHECK_UINT16,IS_LONG)
|
||||
%php_typecheck(long,SWIG_TYPECHECK_INT64,IS_LONG)
|
||||
%php_typecheck(unsigned long,SWIG_TYPECHECK_UINT64,IS_LONG)
|
||||
%php_typecheck(long long,SWIG_TYPECHECK_INT64,IS_LONG)
|
||||
%php_typecheck(unsigned long long,SWIG_TYPECHECK_UINT64,IS_LONG)
|
||||
%php_typecheck(signed char,SWIG_TYPECHECK_INT8,IS_LONG)
|
||||
%php_typecheck(unsigned char,SWIG_TYPECHECK_UINT8,IS_LONG)
|
||||
%php_typecheck(size_t,SWIG_TYPECHECK_INT16,IS_LONG)
|
||||
%php_typecheck(enum SWIGTYPE,SWIG_TYPECHECK_INT8,IS_LONG)
|
||||
%php_typecheck(bool,SWIG_TYPECHECK_BOOL,IS_BOOL)
|
||||
|
||||
%php_typecheck(char,SWIG_TYPECHECK_CHAR,IS_STRING)
|
||||
%php_typecheck(char *,SWIG_TYPECHECK_STRING,IS_STRING)
|
||||
%php_typecheck(char [],SWIG_TYPECHECK_STRING,IS_STRING)
|
||||
|
||||
%php_typecheck(float,SWIG_TYPECHECK_FLOAT,IS_DOUBLE)
|
||||
%php_typecheck(double,SWIG_TYPECHECK_BOOL,IS_DOUBLE)
|
||||
%php_typecheck(char,SWIG_TYPECHECK_CHAR,IS_STRING)
|
||||
|
||||
%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) char *, char *&, char []
|
||||
" $1 = (Z_TYPE_PP($input) == IS_STRING); "
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE
|
||||
{
|
||||
|
|
@ -271,7 +443,8 @@
|
|||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *,
|
||||
SWIGTYPE [],
|
||||
SWIGTYPE &
|
||||
SWIGTYPE &,
|
||||
SWIGTYPE *&
|
||||
{
|
||||
void *tmp;
|
||||
_v = (SWIG_ConvertPtr(*$input, (void**)&tmp, $1_descriptor, 0) >= 0);
|
||||
|
|
|
|||
|
|
@ -8,5 +8,6 @@
|
|||
%init %{
|
||||
SWIG_php_minit {
|
||||
SWIG_InitializeModule(0);
|
||||
le_member_ptr = zend_register_list_destructors_ex(member_ptr_dtor, NULL, SWIG_MEMBER_PTR, module_number);
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,25 +1,20 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* phpkw.swg
|
||||
*
|
||||
* The 'keywords' in PHP are global, ie, the following names are fine
|
||||
* when used as class methods.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#define PHPKW(x) %keywordwarn("'" `x` "' is a php keyword, renamed as 'c_" `x` "'",sourcefmt="%(lower)s", rename="c_%s",fullname=1) `x`
|
||||
#define PHPKW(x) %keywordwarn("'" `x` "' is a PHP keyword, renamed as 'c_" `x` "'",sourcefmt="%(lower)s",rename="c_%s") `x`
|
||||
|
||||
%define PHPCN(x)
|
||||
%keywordwarn("'" `x` "' is a php reserved class name, class renamed as 'c_" `x` "'",%$isclass,rename="c_%s") `x`;
|
||||
%keywordwarn("'" `x` "' is a php reserved class name, constructor renamed as 'c_" `x` "'",%$isconstructor,rename="c_%s") `x`;
|
||||
%enddef
|
||||
|
||||
#define PHPBN1(x) %builtinwarn("'" `x` "' conflicts with a built-in name in php",sourcefmt="%(lower)s",fullname=1) `x`
|
||||
#define PHPBN2(x) %builtinwarn("'" `x` "' conflicts with a built-in name in php") "::" `x`
|
||||
#define PHPCN(x) %keywordwarn("'" `x` "' is a PHP reserved class name, class renamed as 'c_" `x` "'",%$isclass,sourcefmt="%(lower)s",rename="c_%s") `x`
|
||||
|
||||
#define PHPBN1(x) %builtinwarn("'" `x` "' conflicts with a built-in name in PHP",sourcefmt="%(lower)s") `x`
|
||||
#define PHPBN2(x) %builtinwarn("'" `x` "' conflicts with a built-in name in PHP") "::" `x`
|
||||
#define PHPFN(x) %keywordwarn("'" `x` "' is a PHP built-in function, renamed as 'c_" `x` "'",sourcefmt="%(lower)s",%$isfunction,%$not %$ismember,rename="c_%s") `x`
|
||||
|
||||
/*
|
||||
From
|
||||
|
||||
http://aspn.activestate.com/ASPN/docs/PHP/reserved.html
|
||||
http://php.net/manual/en/reserved.keywords.php
|
||||
|
||||
and reviewed by Olly Betts.
|
||||
|
||||
|
|
@ -27,76 +22,81 @@
|
|||
*/
|
||||
|
||||
/* We classify these as kw since PHP will not run if used globally. */
|
||||
/* "You cannot use any of the following words as constants, class names,
|
||||
* function or method names. Using them as variable names is generally OK, but
|
||||
* could lead to confusion."
|
||||
*/
|
||||
/* case insensitive */
|
||||
PHPKW(__halt_compiler);
|
||||
PHPKW(abstract);
|
||||
PHPKW(and);
|
||||
PHPKW(array);
|
||||
PHPKW(as);
|
||||
PHPKW(break);
|
||||
PHPKW(case);
|
||||
PHPKW(cfunction); /* No longer reserved in PHP5 */
|
||||
PHPKW(catch);
|
||||
PHPKW(class);
|
||||
PHPKW(clone);
|
||||
PHPKW(const);
|
||||
PHPKW(continue);
|
||||
PHPKW(declare);
|
||||
PHPKW(default);
|
||||
PHPKW(die);
|
||||
PHPKW(die); // "Language construct"
|
||||
PHPKW(do);
|
||||
PHPKW(echo);
|
||||
PHPKW(echo); // "Language construct"
|
||||
PHPKW(else);
|
||||
PHPKW(elseif);
|
||||
PHPKW(empty);
|
||||
PHPKW(empty); // "Language construct"
|
||||
PHPKW(enddeclare);
|
||||
PHPKW(endfor);
|
||||
PHPKW(endforeach);
|
||||
PHPKW(endif);
|
||||
PHPKW(endswitch);
|
||||
PHPKW(endwhile);
|
||||
PHPKW(eval);
|
||||
PHPKW(exit);
|
||||
PHPKW(eval); // "Language construct"
|
||||
PHPKW(exit); // "Language construct"
|
||||
PHPKW(extends);
|
||||
PHPKW(final);
|
||||
PHPKW(for);
|
||||
PHPKW(foreach);
|
||||
PHPKW(function);
|
||||
PHPKW(global);
|
||||
PHPKW(goto); // As of PHP5.3
|
||||
PHPKW(if);
|
||||
PHPKW(include);
|
||||
PHPKW(include_once);
|
||||
PHPKW(isset);
|
||||
PHPKW(list);
|
||||
PHPKW(implements);
|
||||
PHPKW(include); // "Language construct"
|
||||
PHPKW(include_once); // "Language construct"
|
||||
PHPKW(instanceof);
|
||||
PHPKW(interface);
|
||||
PHPKW(isset); // "Language construct"
|
||||
PHPKW(list); // "Language construct"
|
||||
PHPKW(namespace); // As of PHP5.3
|
||||
PHPKW(new);
|
||||
// PHPKW(old_function); /* No longer reserved in PHP5 */
|
||||
PHPKW(or);
|
||||
PHPKW(print);
|
||||
PHPKW(require);
|
||||
PHPKW(require_once);
|
||||
PHPKW(return);
|
||||
PHPKW(print); // "Language construct"
|
||||
PHPKW(private);
|
||||
PHPKW(protected);
|
||||
PHPKW(public);
|
||||
PHPKW(require); // "Language construct"
|
||||
PHPKW(require_once); // "Language construct"
|
||||
PHPKW(return); // "Language construct"
|
||||
PHPKW(static);
|
||||
PHPKW(switch);
|
||||
PHPKW(unset);
|
||||
PHPKW(throw);
|
||||
PHPKW(try);
|
||||
PHPKW(unset); // "Language construct"
|
||||
PHPKW(use);
|
||||
PHPKW(var);
|
||||
PHPKW(while);
|
||||
PHPKW(xor);
|
||||
PHPKW(__FILE__);
|
||||
PHPKW(__LINE__);
|
||||
PHPKW(__FUNCTION__);
|
||||
// Compile-time constants
|
||||
PHPKW(__CLASS__);
|
||||
|
||||
/* Added in PHP5 */
|
||||
PHPKW(__halt_compiler);
|
||||
PHPKW(abstract);
|
||||
PHPKW(catch);
|
||||
PHPKW(clone);
|
||||
PHPKW(final);
|
||||
PHPKW(implements);
|
||||
PHPKW(instanceof);
|
||||
PHPKW(interface);
|
||||
PHPKW(private);
|
||||
PHPKW(protected);
|
||||
PHPKW(public);
|
||||
PHPKW(throw);
|
||||
PHPKW(try);
|
||||
PHPKW(__DIR__); // As of PHP5.3
|
||||
PHPKW(__FILE__);
|
||||
PHPKW(__FUNCTION__);
|
||||
PHPKW(__METHOD__);
|
||||
PHPKW(__NAMESPACE__); // As of PHP5.3
|
||||
PHPKW(__LINE__);
|
||||
|
||||
/* We classify these as built-in names since they conflict, but PHP still runs */
|
||||
|
||||
|
|
@ -352,107 +352,131 @@ PHPBN2(E_STRICT);
|
|||
PHPBN2(__COMPILER_HALT_OFFSET__);
|
||||
|
||||
/* Class names reserved by PHP */
|
||||
PHPCN(stdClass);
|
||||
PHPCN(__PHP_Incomplete_Class);
|
||||
PHPCN(Directory);
|
||||
|
||||
/* case insensitive */
|
||||
PHPCN(stdclass);
|
||||
PHPCN(__php_incomplete_class);
|
||||
PHPCN(directory);
|
||||
/* Added in PHP5 (this list apparently depends which extensions you load by default). */
|
||||
PHPCN(parent);
|
||||
PHPCN(self);
|
||||
PHPCN(Exception);
|
||||
PHPCN(exception);
|
||||
PHPCN(php_user_filter);
|
||||
PHPCN(ErrorException);
|
||||
PHPCN(XMLWriter);
|
||||
PHPCN(LibXMLError);
|
||||
PHPCN(SimpleXMLElement);
|
||||
PHPCN(SoapClient);
|
||||
PHPCN(SoapVar);
|
||||
PHPCN(SoapServer);
|
||||
PHPCN(SoapFault);
|
||||
PHPCN(SoapParam);
|
||||
PHPCN(SoapHeader);
|
||||
PHPCN(RecursiveIteratorIterator);
|
||||
PHPCN(FilterIterator);
|
||||
PHPCN(RecursiveFilterIterator);
|
||||
PHPCN(ParentIterator);
|
||||
PHPCN(LimitIterator);
|
||||
PHPCN(CachingIterator);
|
||||
PHPCN(RecursiveCachingIterator);
|
||||
PHPCN(IteratorIterator);
|
||||
PHPCN(NoRewindIterator);
|
||||
PHPCN(AppendIterator);
|
||||
PHPCN(InfiniteIterator);
|
||||
PHPCN(EmptyIterator);
|
||||
PHPCN(ArrayObject);
|
||||
PHPCN(ArrayIterator);
|
||||
PHPCN(RecursiveArrayIterator);
|
||||
PHPCN(SplFileInfo);
|
||||
PHPCN(DirectoryIterator);
|
||||
PHPCN(RecursiveDirectoryIterator);
|
||||
PHPCN(SplFileObject);
|
||||
PHPCN(SplTempFileObject);
|
||||
PHPCN(SimpleXMLIterator);
|
||||
PHPCN(LogicException);
|
||||
PHPCN(BadFunctionCallException);
|
||||
PHPCN(BadMethodCallException);
|
||||
PHPCN(DomainException);
|
||||
PHPCN(InvalidArgumentException);
|
||||
PHPCN(LengthException);
|
||||
PHPCN(OutOfRangeException);
|
||||
PHPCN(RuntimeException);
|
||||
PHPCN(OutOfBoundsException);
|
||||
PHPCN(OverflowException);
|
||||
PHPCN(RangeException);
|
||||
PHPCN(UnderflowException);
|
||||
PHPCN(UnexpectedValueException);
|
||||
PHPCN(SplObjectStorage);
|
||||
PHPCN(ReflectionException);
|
||||
PHPCN(Reflection);
|
||||
PHPCN(ReflectionFunction);
|
||||
PHPCN(ReflectionParameter);
|
||||
PHPCN(ReflectionMethod);
|
||||
PHPCN(ReflectionClass);
|
||||
PHPCN(ReflectionObject);
|
||||
PHPCN(ReflectionProperty);
|
||||
PHPCN(ReflectionExtension);
|
||||
PHPCN(DOMException);
|
||||
PHPCN(DOMStringList);
|
||||
PHPCN(DOMNameList);
|
||||
PHPCN(DOMImplementationList);
|
||||
PHPCN(DOMImplementationSource);
|
||||
PHPCN(DOMImplementation);
|
||||
PHPCN(DOMNode);
|
||||
PHPCN(DOMNameSpaceNode);
|
||||
PHPCN(DOMDocumentFragment);
|
||||
PHPCN(DOMDocument);
|
||||
PHPCN(DOMNodeList);
|
||||
PHPCN(DOMNamedNodeMap);
|
||||
PHPCN(DOMCharacterData);
|
||||
PHPCN(DOMAttr);
|
||||
PHPCN(DOMElement);
|
||||
PHPCN(DOMText);
|
||||
PHPCN(DOMComment);
|
||||
PHPCN(DOMTypeinfo);
|
||||
PHPCN(DOMUserDataHandler);
|
||||
PHPCN(DOMDomError);
|
||||
PHPCN(DOMErrorHandler);
|
||||
PHPCN(DOMLocator);
|
||||
PHPCN(DOMConfiguration);
|
||||
PHPCN(DOMCdataSection);
|
||||
PHPCN(DOMDocumentType);
|
||||
PHPCN(DOMNotation);
|
||||
PHPCN(DOMEntity);
|
||||
PHPCN(DOMEntityReference);
|
||||
PHPCN(DOMProcessingInstruction);
|
||||
PHPCN(DOMStringExtend);
|
||||
PHPCN(DOMXPath);
|
||||
PHPCN(XMLReader);
|
||||
PHPCN(SQLiteDatabase);
|
||||
PHPCN(SQLiteResult);
|
||||
PHPCN(SQLiteUnbuffered);
|
||||
PHPCN(SQLiteException);
|
||||
PHPCN(errorexception);
|
||||
PHPCN(xmlwriter);
|
||||
PHPCN(libxmlerror);
|
||||
PHPCN(simplexmlelement);
|
||||
PHPCN(soapclient);
|
||||
PHPCN(soapvar);
|
||||
PHPCN(soapserver);
|
||||
PHPCN(soapfault);
|
||||
PHPCN(soapparam);
|
||||
PHPCN(soapheader);
|
||||
PHPCN(recursiveiteratoriterator);
|
||||
PHPCN(filteriterator);
|
||||
PHPCN(recursivefilteriterator);
|
||||
PHPCN(parentiterator);
|
||||
PHPCN(limititerator);
|
||||
PHPCN(cachingiterator);
|
||||
PHPCN(recursivecachingiterator);
|
||||
PHPCN(iteratoriterator);
|
||||
PHPCN(norewinditerator);
|
||||
PHPCN(appenditerator);
|
||||
PHPCN(infiniteiterator);
|
||||
PHPCN(emptyiterator);
|
||||
PHPCN(arrayobject);
|
||||
PHPCN(arrayiterator);
|
||||
PHPCN(recursivearrayiterator);
|
||||
PHPCN(splfileinfo);
|
||||
PHPCN(directoryiterator);
|
||||
PHPCN(recursivedirectoryiterator);
|
||||
PHPCN(splfileobject);
|
||||
PHPCN(spltempfileobject);
|
||||
PHPCN(simplexmliterator);
|
||||
PHPCN(logicexception);
|
||||
PHPCN(badfunctioncallexception);
|
||||
PHPCN(badmethodcallexception);
|
||||
PHPCN(domainexception);
|
||||
PHPCN(invalidargumentexception);
|
||||
PHPCN(lengthexception);
|
||||
PHPCN(outofrangeexception);
|
||||
PHPCN(runtimeexception);
|
||||
PHPCN(outofboundsexception);
|
||||
PHPCN(overflowexception);
|
||||
PHPCN(rangeexception);
|
||||
PHPCN(underflowexception);
|
||||
PHPCN(unexpectedvalueexception);
|
||||
PHPCN(splobjectstorage);
|
||||
PHPCN(reflectionexception);
|
||||
PHPCN(reflection);
|
||||
PHPCN(reflectionfunction);
|
||||
PHPCN(reflectionparameter);
|
||||
PHPCN(reflectionmethod);
|
||||
PHPCN(reflectionclass);
|
||||
PHPCN(reflectionobject);
|
||||
PHPCN(reflectionproperty);
|
||||
PHPCN(reflectionextension);
|
||||
PHPCN(domexception);
|
||||
PHPCN(domstringlist);
|
||||
PHPCN(domnamelist);
|
||||
PHPCN(domimplementationlist);
|
||||
PHPCN(domimplementationsource);
|
||||
PHPCN(domimplementation);
|
||||
PHPCN(domnode);
|
||||
PHPCN(domnamespacenode);
|
||||
PHPCN(domdocumentfragment);
|
||||
PHPCN(domdocument);
|
||||
PHPCN(domnodelist);
|
||||
PHPCN(domnamednodemap);
|
||||
PHPCN(domcharacterdata);
|
||||
PHPCN(domattr);
|
||||
PHPCN(domelement);
|
||||
PHPCN(domtext);
|
||||
PHPCN(domcomment);
|
||||
PHPCN(domtypeinfo);
|
||||
PHPCN(domuserdatahandler);
|
||||
PHPCN(domdomerror);
|
||||
PHPCN(domerrorhandler);
|
||||
PHPCN(domlocator);
|
||||
PHPCN(domconfiguration);
|
||||
PHPCN(domcdatasection);
|
||||
PHPCN(domdocumenttype);
|
||||
PHPCN(domnotation);
|
||||
PHPCN(domentity);
|
||||
PHPCN(domentityreference);
|
||||
PHPCN(domprocessinginstruction);
|
||||
PHPCN(domstringextend);
|
||||
PHPCN(domxpath);
|
||||
PHPCN(xmlreader);
|
||||
PHPCN(sqlitedatabase);
|
||||
PHPCN(sqliteresult);
|
||||
PHPCN(sqliteunbuffered);
|
||||
PHPCN(sqliteexception);
|
||||
PHPCN(datetime);
|
||||
|
||||
/* Built-in PHP functions (incomplete). */
|
||||
PHPFN(cos);
|
||||
PHPFN(sin);
|
||||
PHPFN(tan);
|
||||
PHPFN(acos);
|
||||
PHPFN(asin);
|
||||
PHPFN(atan);
|
||||
PHPFN(atan2);
|
||||
PHPFN(cosh);
|
||||
PHPFN(sinh);
|
||||
PHPFN(tanh);
|
||||
PHPFN(exp);
|
||||
PHPFN(log);
|
||||
PHPFN(log10);
|
||||
PHPFN(pow);
|
||||
PHPFN(sqrt);
|
||||
PHPFN(ceil);
|
||||
PHPFN(floor);
|
||||
PHPFN(fmod);
|
||||
PHPFN(min);
|
||||
PHPFN(max);
|
||||
|
||||
#undef PHPKW
|
||||
#undef PHPBN1
|
||||
#undef PHPBN2
|
||||
#undef PHPCN
|
||||
#undef PHPFN
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ extern "C" {
|
|||
#include "zend.h"
|
||||
#include "zend_API.h"
|
||||
#include "php.h"
|
||||
#include "ext/standard/php_string.h"
|
||||
|
||||
#ifdef ZEND_RAW_FENTRY
|
||||
/* ZEND_RAW_FENTRY was added somewhere between 5.2.0 and 5.2.3 */
|
||||
|
|
@ -21,9 +22,18 @@ extern "C" {
|
|||
# define SWIG_ZEND_NAMED_FE(ZN, N, A) ZEND_NAMED_FE(ZN, N, A)
|
||||
#endif
|
||||
|
||||
#ifndef Z_SET_ISREF_P
|
||||
// For PHP < 5.3
|
||||
# define Z_SET_ISREF_P(z) (z)->is_ref = 1
|
||||
#endif
|
||||
#ifndef Z_SET_REFCOUNT_P
|
||||
// For PHP < 5.3
|
||||
# define Z_SET_REFCOUNT_P(z, rc) (z)->refcount = (rc)
|
||||
#endif
|
||||
|
||||
#define SWIG_LONG_CONSTANT(N, V) zend_register_long_constant((char*)#N, sizeof(#N), V, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC)
|
||||
#define SWIG_DOUBLE_CONSTANT(N, V) zend_register_double_constant((char*)#N, sizeof(#N), V, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC)
|
||||
#define SWIG_STRING_CONSTANT(N, V) zend_register_stringl_constant((char*)#N, sizeof(#N), V, strlen(V), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC)
|
||||
#define SWIG_STRING_CONSTANT(N, V) zend_register_stringl_constant((char*)#N, sizeof(#N), (char*)(V), strlen(V), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC)
|
||||
#define SWIG_CHAR_CONSTANT(N, V) do {\
|
||||
static char swig_char = (V);\
|
||||
zend_register_stringl_constant((char*)#N, sizeof(#N), &swig_char, 1, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC);\
|
||||
|
|
@ -72,7 +82,7 @@ static int default_error_code = E_ERROR;
|
|||
|
||||
/* used to wrap returned objects in so we know whether they are newobject
|
||||
and need freeing, or not */
|
||||
typedef struct _swig_object_wrapper {
|
||||
typedef struct {
|
||||
void * ptr;
|
||||
int newobject;
|
||||
} swig_object_wrapper;
|
||||
|
|
@ -81,6 +91,7 @@ typedef struct _swig_object_wrapper {
|
|||
static ZEND_RSRC_DTOR_FUNC(SWIG_landfill) { (void)rsrc; }
|
||||
|
||||
#define SWIG_SetPointerZval(a,b,c,d) SWIG_ZTS_SetPointerZval(a,b,c,d TSRMLS_CC)
|
||||
#define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a))
|
||||
|
||||
static void
|
||||
SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject TSRMLS_DC) {
|
||||
|
|
@ -98,7 +109,37 @@ SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject
|
|||
value=(swig_object_wrapper *)emalloc(sizeof(swig_object_wrapper));
|
||||
value->ptr=ptr;
|
||||
value->newobject=newobject;
|
||||
ZEND_REGISTER_RESOURCE(z, value, *(int *)(type->clientdata));
|
||||
if (newobject <= 1) {
|
||||
/* Just register the pointer as a resource. */
|
||||
ZEND_REGISTER_RESOURCE(z, value, *(int *)(type->clientdata));
|
||||
} else {
|
||||
/*
|
||||
* Wrap the resource in an object, the resource will be accessible
|
||||
* via the "_cPtr" member. This is currently only used by
|
||||
* directorin typemaps.
|
||||
*/
|
||||
value->newobject = 0;
|
||||
zval *resource;
|
||||
MAKE_STD_ZVAL(resource);
|
||||
ZEND_REGISTER_RESOURCE(resource, value, *(int *)(type->clientdata));
|
||||
zend_class_entry **ce = NULL;
|
||||
zval *classname;
|
||||
MAKE_STD_ZVAL(classname);
|
||||
/* _p_Foo -> Foo */
|
||||
ZVAL_STRING(classname, (char*)type->name+3, 1);
|
||||
/* class names are stored in lowercase */
|
||||
php_strtolower(Z_STRVAL_PP(&classname), Z_STRLEN_PP(&classname));
|
||||
if (zend_lookup_class(Z_STRVAL_P(classname), Z_STRLEN_P(classname), &ce TSRMLS_CC) != SUCCESS) {
|
||||
/* class does not exist */
|
||||
object_init(z);
|
||||
} else {
|
||||
object_init_ex(z, *ce);
|
||||
}
|
||||
Z_SET_REFCOUNT_P(z, 1);
|
||||
Z_SET_ISREF_P(z);
|
||||
zend_hash_update(HASH_OF(z), (char*)"_cPtr", sizeof("_cPtr"), (void*)&resource, sizeof(zval), NULL);
|
||||
FREE_ZVAL(classname);
|
||||
}
|
||||
return;
|
||||
}
|
||||
zend_error(E_ERROR, "Type: %s not registered with zend",type->name);
|
||||
|
|
@ -153,7 +194,7 @@ SWIG_ZTS_ConvertResourcePtr(zval *z, swig_type_info *ty, int flags TSRMLS_DC) {
|
|||
char *type_name;
|
||||
|
||||
value = (swig_object_wrapper *) zend_list_find(z->value.lval, &type);
|
||||
if ( flags && SWIG_POINTER_DISOWN ) {
|
||||
if ( flags & SWIG_POINTER_DISOWN ) {
|
||||
value->newobject = 0;
|
||||
}
|
||||
p = value->ptr;
|
||||
|
|
@ -217,3 +258,12 @@ static void SWIG_Php_SetModule(swig_module_info *pointer) {
|
|||
TSRMLS_FETCH();
|
||||
REGISTER_MAIN_LONG_CONSTANT(const_name, (long) pointer, 0);
|
||||
}
|
||||
|
||||
#define SWIG_MEMBER_PTR ((char*)"CLASS::*")
|
||||
|
||||
static void member_ptr_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
|
||||
efree(rsrc->ptr);
|
||||
}
|
||||
|
||||
static int le_member_ptr;
|
||||
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@ namespace std {
|
|||
map(const map<K,T> &);
|
||||
|
||||
unsigned int size() const;
|
||||
%rename(is_empty) empty;
|
||||
bool empty() const;
|
||||
void clear();
|
||||
%extend {
|
||||
T& get(const K& key) throw (std::out_of_range) {
|
||||
|
|
@ -52,6 +50,9 @@ namespace std {
|
|||
std::map<K,T >::iterator i = self->find(key);
|
||||
return i != self->end();
|
||||
}
|
||||
bool is_empty() const {
|
||||
return self->empty();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -67,8 +68,6 @@ namespace std {
|
|||
map(const map<K,T> &);
|
||||
|
||||
unsigned int size() const;
|
||||
%rename(is_empty) empty;
|
||||
bool empty() const;
|
||||
void clear();
|
||||
%extend {
|
||||
T& get(K key) throw (std::out_of_range) {
|
||||
|
|
@ -92,6 +91,9 @@ namespace std {
|
|||
std::map<K,T >::iterator i = self->find(key);
|
||||
return i != self->end();
|
||||
}
|
||||
bool is_empty() const {
|
||||
return self->empty();
|
||||
}
|
||||
}
|
||||
};
|
||||
%enddef
|
||||
|
|
@ -104,8 +106,6 @@ namespace std {
|
|||
map(const map<K,T> &);
|
||||
|
||||
unsigned int size() const;
|
||||
%rename(is_empty) empty;
|
||||
bool empty() const;
|
||||
void clear();
|
||||
%extend {
|
||||
T get(const K& key) throw (std::out_of_range) {
|
||||
|
|
@ -129,6 +129,9 @@ namespace std {
|
|||
std::map<K,T >::iterator i = self->find(key);
|
||||
return i != self->end();
|
||||
}
|
||||
bool is_empty() const {
|
||||
return self->empty();
|
||||
}
|
||||
}
|
||||
};
|
||||
%enddef
|
||||
|
|
@ -142,8 +145,6 @@ namespace std {
|
|||
map(const map<K,T> &);
|
||||
|
||||
unsigned int size() const;
|
||||
%rename(is_empty) empty;
|
||||
bool empty() const;
|
||||
void clear();
|
||||
%extend {
|
||||
T get(K key) throw (std::out_of_range) {
|
||||
|
|
@ -167,6 +168,9 @@ namespace std {
|
|||
std::map<K,T >::iterator i = self->find(key);
|
||||
return i != self->end();
|
||||
}
|
||||
bool is_empty() const {
|
||||
return self->empty();
|
||||
}
|
||||
}
|
||||
};
|
||||
%enddef
|
||||
|
|
|
|||
|
|
@ -32,6 +32,11 @@ namespace std {
|
|||
$1.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
|
||||
%}
|
||||
|
||||
%typemap(directorout) string %{
|
||||
convert_to_string_ex($input);
|
||||
$result.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
|
||||
%}
|
||||
|
||||
%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) const string& %{
|
||||
$1 = ( Z_TYPE_PP($input) == IS_STRING ) ? 1 : 0;
|
||||
%}
|
||||
|
|
@ -40,6 +45,10 @@ namespace std {
|
|||
ZVAL_STRINGL($result, const_cast<char*>($1.data()), $1.size(), 1);
|
||||
%}
|
||||
|
||||
%typemap(directorin) string %{
|
||||
ZVAL_STRINGL($input, const_cast<char*>($1_name.data()), $1_name.size(), 1);
|
||||
%}
|
||||
|
||||
%typemap(out) const string & %{
|
||||
ZVAL_STRINGL($result, const_cast<char*>($1->data()), $1->size(), 1);
|
||||
%}
|
||||
|
|
@ -60,6 +69,14 @@ namespace std {
|
|||
$1 = &temp;
|
||||
%}
|
||||
|
||||
%typemap(directorout) string & (std::string *temp) %{
|
||||
convert_to_string_ex($input);
|
||||
temp = new std::string;
|
||||
temp->assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
|
||||
swig_acquire_ownership(temp);
|
||||
$result = temp;
|
||||
%}
|
||||
|
||||
%typemap(argout) string & %{
|
||||
ZVAL_STRINGL(*($input), const_cast<char*>($1->data()), $1->size(), 1);
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -1,131 +1,102 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* std_vector.i
|
||||
*
|
||||
* SWIG typemaps for std::vector types
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <std_common.i>
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// std::vector
|
||||
//
|
||||
// The aim of all that follows would be to integrate std::vector with
|
||||
// PHP as much as possible, namely, to allow the user to pass and
|
||||
// be returned PHP lists.
|
||||
// const declarations are used to guess the intent of the function being
|
||||
// exported; therefore, the following rationale is applied:
|
||||
//
|
||||
// -- f(std::vector<T>), f(const std::vector<T>&), f(const std::vector<T>*):
|
||||
// the parameter being read-only, either a PHP sequence or a
|
||||
// previously wrapped std::vector<T> can be passed.
|
||||
// -- f(std::vector<T>&), f(std::vector<T>*):
|
||||
// the parameter must be modified; therefore, only a wrapped std::vector
|
||||
// can be passed.
|
||||
// -- std::vector<T> f():
|
||||
// the vector is returned by copy; therefore, a PHP sequence of T:s
|
||||
// is returned which is most easily used in other PHP functions
|
||||
// -- std::vector<T>& f(), std::vector<T>* f(), const std::vector<T>& f(),
|
||||
// const std::vector<T>* f():
|
||||
// the vector is returned by reference; therefore, a wrapped std::vector
|
||||
// is returned
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
%{
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
%}
|
||||
|
||||
// exported class
|
||||
|
||||
namespace std {
|
||||
|
||||
template<class T> class vector {
|
||||
// add generic typemaps here
|
||||
public:
|
||||
vector(unsigned int size = 0);
|
||||
unsigned int size() const;
|
||||
%rename(is_empty) empty;
|
||||
bool empty() const;
|
||||
void clear();
|
||||
%rename(push) push_back;
|
||||
void push_back(const T& x);
|
||||
%extend {
|
||||
T pop() throw (std::out_of_range) {
|
||||
if (self->size() == 0)
|
||||
throw std::out_of_range("pop from empty vector");
|
||||
T x = self->back();
|
||||
self->pop_back();
|
||||
return x;
|
||||
}
|
||||
T& get(int i) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
return (*self)[i];
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
void set(int i, const T& x) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
(*self)[i] = x;
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class T> class vector {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef T value_type;
|
||||
typedef const value_type& const_reference;
|
||||
vector();
|
||||
vector(size_type n);
|
||||
size_type size() const;
|
||||
size_type capacity() const;
|
||||
void reserve(size_type n);
|
||||
void clear();
|
||||
%rename(push) push_back;
|
||||
void push_back(const value_type& x);
|
||||
%extend {
|
||||
bool is_empty() const {
|
||||
return $self->empty();
|
||||
}
|
||||
T pop() throw (std::out_of_range) {
|
||||
if (self->size() == 0)
|
||||
throw std::out_of_range("pop from empty vector");
|
||||
T x = self->back();
|
||||
self->pop_back();
|
||||
return x;
|
||||
}
|
||||
const_reference get(int i) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
return (*self)[i];
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
void set(int i, const value_type& val) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
(*self)[i] = val;
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// specializations for built-ins
|
||||
|
||||
%define specialize_std_vector(T)
|
||||
template<> class vector<T> {
|
||||
// add specialized typemaps here
|
||||
public:
|
||||
vector(unsigned int size = 0);
|
||||
unsigned int size() const;
|
||||
%rename(is_empty) empty;
|
||||
bool empty() const;
|
||||
void clear();
|
||||
%rename(push) push_back;
|
||||
void push_back(T x);
|
||||
%extend {
|
||||
T pop() throw (std::out_of_range) {
|
||||
if (self->size() == 0)
|
||||
throw std::out_of_range("pop from empty vector");
|
||||
T x = self->back();
|
||||
self->pop_back();
|
||||
return x;
|
||||
}
|
||||
T get(int i) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
return (*self)[i];
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
void set(int i, T x) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
(*self)[i] = x;
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
}
|
||||
};
|
||||
%enddef
|
||||
|
||||
specialize_std_vector(bool);
|
||||
specialize_std_vector(char);
|
||||
specialize_std_vector(int);
|
||||
specialize_std_vector(short);
|
||||
specialize_std_vector(long);
|
||||
specialize_std_vector(unsigned char);
|
||||
specialize_std_vector(unsigned int);
|
||||
specialize_std_vector(unsigned short);
|
||||
specialize_std_vector(unsigned long);
|
||||
specialize_std_vector(float);
|
||||
specialize_std_vector(double);
|
||||
|
||||
// bool specialization
|
||||
template<> class vector<bool> {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef bool value_type;
|
||||
typedef bool const_reference;
|
||||
vector();
|
||||
vector(size_type n);
|
||||
size_type size() const;
|
||||
size_type capacity() const;
|
||||
void reserve(size_type n);
|
||||
void clear();
|
||||
%rename(push) push_back;
|
||||
void push_back(const value_type& x);
|
||||
%extend {
|
||||
bool is_empty() const {
|
||||
return $self->empty();
|
||||
}
|
||||
bool pop() throw (std::out_of_range) {
|
||||
if (self->size() == 0)
|
||||
throw std::out_of_range("pop from empty vector");
|
||||
bool x = self->back();
|
||||
self->pop_back();
|
||||
return x;
|
||||
}
|
||||
const_reference get(int i) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
return (*self)[i];
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
void set(int i, const value_type& val) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
(*self)[i] = val;
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
%define specialize_std_vector(T)
|
||||
#warning "specialize_std_vector - specialization for type T no longer needed"
|
||||
%enddef
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -109,9 +109,7 @@ int_typemap(long long);
|
|||
}
|
||||
%typemap(in) TYPE *REFERENCE (long long lvalue)
|
||||
%{
|
||||
// FIXME won't work for values which don't fit in a long...
|
||||
convert_to_long_ex($input);
|
||||
lvalue = (long long) (*$input)->value.lval;
|
||||
CONVERT_LONG_LONG_IN(lvalue, long long, $input)
|
||||
$1 = &lvalue;
|
||||
%}
|
||||
%typemap(argout) long long *REFERENCE
|
||||
|
|
@ -125,6 +123,17 @@ int_typemap(long long);
|
|||
ZVAL_STRING((*$arg), temp, 1);
|
||||
}
|
||||
%}
|
||||
%typemap(argout) long long &OUTPUT
|
||||
%{
|
||||
if ((long long)LONG_MIN <= *arg$argnum && *arg$argnum <= (long long)LONG_MAX) {
|
||||
($result)->value.lval = (long)(*arg$argnum);
|
||||
($result)->type = IS_LONG;
|
||||
} else {
|
||||
char temp[256];
|
||||
sprintf(temp, "%lld", *arg$argnum);
|
||||
ZVAL_STRING($result, temp, 1);
|
||||
}
|
||||
%}
|
||||
int_typemap(unsigned long long);
|
||||
%typemap(argout,fragment="t_output_helper") unsigned long long *OUTPUT
|
||||
{
|
||||
|
|
@ -141,9 +150,7 @@ int_typemap(unsigned long long);
|
|||
}
|
||||
%typemap(in) TYPE *REFERENCE (unsigned long long lvalue)
|
||||
%{
|
||||
// FIXME won't work for values which don't fit in a long...
|
||||
convert_to_long_ex($input);
|
||||
lvalue = (unsigned long long) (*$input)->value.lval;
|
||||
CONVERT_UNSIGNED_LONG_LONG_IN(lvalue, unsigned long long, $input)
|
||||
$1 = &lvalue;
|
||||
%}
|
||||
%typemap(argout) unsigned long long *REFERENCE
|
||||
|
|
@ -157,6 +164,17 @@ int_typemap(unsigned long long);
|
|||
ZVAL_STRING((*$arg), temp, 1);
|
||||
}
|
||||
%}
|
||||
%typemap(argout) unsigned long long &OUTPUT
|
||||
%{
|
||||
if (*arg$argnum <= (unsigned long long)LONG_MAX) {
|
||||
($result)->value.lval = (long)(*arg$argnum);
|
||||
($result)->type = IS_LONG;
|
||||
} else {
|
||||
char temp[256];
|
||||
sprintf(temp, "%llu", *arg$argnum);
|
||||
ZVAL_STRING($result, temp, 1);
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap(in) float *INOUT = float *INPUT;
|
||||
%typemap(in) double *INOUT = double *INPUT;
|
||||
|
|
@ -178,11 +196,13 @@ int_typemap(unsigned long long);
|
|||
%typemap(in) short &INOUT = short *INPUT;
|
||||
%typemap(in) long &INOUT = long *INPUT;
|
||||
%typemap(in) long long &INOUT = long long *INPUT;
|
||||
%typemap(in) long long &INPUT = long long *INPUT;
|
||||
%typemap(in) unsigned &INOUT = unsigned *INPUT;
|
||||
%typemap(in) unsigned short &INOUT = unsigned short *INPUT;
|
||||
%typemap(in) unsigned long &INOUT = unsigned long *INPUT;
|
||||
%typemap(in) unsigned char &INOUT = unsigned char *INPUT;
|
||||
%typemap(in) unsigned long long &INOUT = unsigned long long *INPUT;
|
||||
%typemap(in) unsigned long long &INPUT = unsigned long long *INPUT;
|
||||
|
||||
%typemap(argout) float *INOUT = float *OUTPUT;
|
||||
%typemap(argout) double *INOUT= double *OUTPUT;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,42 @@
|
|||
lvar = (t) Z_LVAL_PP(invar);
|
||||
%enddef
|
||||
|
||||
%define CONVERT_LONG_LONG_IN(lvar,t,invar)
|
||||
switch ((*(invar))->type) {
|
||||
case IS_DOUBLE:
|
||||
lvar = (t) (*(invar))->value.dval;
|
||||
break;
|
||||
case IS_STRING: {
|
||||
char * endptr;
|
||||
errno = 0;
|
||||
lvar = (t) strtoll((*(invar))->value.str.val, &endptr, 10);
|
||||
if (*endptr && !errno) break;
|
||||
/* FALL THRU */
|
||||
}
|
||||
default:
|
||||
convert_to_long_ex(invar);
|
||||
lvar = (t) (*(invar))->value.lval;
|
||||
}
|
||||
%enddef
|
||||
|
||||
%define CONVERT_UNSIGNED_LONG_LONG_IN(lvar,t,invar)
|
||||
switch ((*(invar))->type) {
|
||||
case IS_DOUBLE:
|
||||
lvar = (t) (*(invar))->value.dval;
|
||||
break;
|
||||
case IS_STRING: {
|
||||
char * endptr;
|
||||
errno = 0;
|
||||
lvar = (t) strtoull((*(invar))->value.str.val, &endptr, 10);
|
||||
if (*endptr && !errno) break;
|
||||
/* FALL THRU */
|
||||
}
|
||||
default:
|
||||
convert_to_long_ex(invar);
|
||||
lvar = (t) (*(invar))->value.lval;
|
||||
}
|
||||
%enddef
|
||||
|
||||
%define CONVERT_INT_OUT(lvar,invar)
|
||||
lvar = (t) Z_LVAL_PP(invar);
|
||||
%enddef
|
||||
|
|
@ -33,10 +69,24 @@
|
|||
%enddef
|
||||
|
||||
%define %pass_by_val( TYPE, CONVERT_IN )
|
||||
%typemap(in) TYPE, const TYPE &
|
||||
%typemap(in) TYPE
|
||||
%{
|
||||
CONVERT_IN($1,$1_ltype,$input);
|
||||
%}
|
||||
%typemap(in) const TYPE & ($*1_ltype temp)
|
||||
%{
|
||||
CONVERT_IN(temp,$*1_ltype,$input);
|
||||
$1 = &temp;
|
||||
%}
|
||||
%typemap(directorout) TYPE
|
||||
%{
|
||||
CONVERT_IN($result,$1_ltype,$input);
|
||||
%}
|
||||
%typemap(directorout) const TYPE & ($*1_ltype temp)
|
||||
%{
|
||||
CONVERT_IN(temp,$*1_ltype,$input);
|
||||
$result = &temp;
|
||||
%}
|
||||
%enddef
|
||||
|
||||
%fragment("t_output_helper","header") %{
|
||||
|
|
@ -49,6 +99,7 @@ t_output_helper( zval **target, zval *o) {
|
|||
}
|
||||
if ( (*target)->type == IS_NULL ) {
|
||||
REPLACE_ZVAL_VALUE(target,o,1);
|
||||
FREE_ZVAL(o);
|
||||
return;
|
||||
}
|
||||
zval *tmp;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue