Merge trunk (up to just after swig 2.0.5 release - rev 13009) to gsoc2008-cherylfoil

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-cherylfoil@13017 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2012-04-27 18:55:37 +00:00
commit af1c6ac3c3
1811 changed files with 94580 additions and 35569 deletions

View file

@ -48,3 +48,6 @@
c.module_number = module_number;
zend_register_constant( &c TSRMLS_CC );
}
/* Handled as a global variable. */
%typemap(consttab) SWIGTYPE (CLASS::*) "";

200
Lib/php/director.swg Normal file
View file

@ -0,0 +1,200 @@
/* -----------------------------------------------------------------------------
* 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> swig_ownership_map;
mutable swig_ownership_map swig_owner;
#ifdef ZTS
// Store the ZTS context so it's available when C++ calls back to PHP.
void *** swig_zts_ctx;
#endif
public:
Director(zval* self TSRMLS_DC) : swig_self(self) {
TSRMLS_SET_CTX(swig_zts_ctx);
}
bool swig_is_overridden_method(char *cname, char *lc_fname) {
TSRMLS_FETCH_FROM_CTX(swig_zts_ctx);
zend_class_entry **ce;
zend_function *mptr;
int name_len = strlen(lc_fname);
if (zend_lookup_class(cname, strlen(cname), &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) {
swig_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 TSRMLS_DC)
: 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 TSRMLS_DC)
{
throw DirectorException(code, hdr, msg TSRMLS_CC);
}
};
/* attempt to call a pure virtual method via a director method */
class DirectorPureVirtualException : public Swig::DirectorException
{
public:
DirectorPureVirtualException(const char* msg TSRMLS_DC)
: DirectorException(E_ERROR, "SWIG director pure virtual method called", msg TSRMLS_CC)
{
}
static void raise(const char *msg TSRMLS_DC)
{
throw DirectorPureVirtualException(msg TSRMLS_CC);
}
};
/* any php exception that occurs during a director method call */
class DirectorMethodException : public Swig::DirectorException
{
public:
DirectorMethodException(const char* msg TSRMLS_DC)
: DirectorException(E_ERROR, "SWIG director method error", msg TSRMLS_CC)
{
}
static void raise(const char *msg TSRMLS_DC)
{
throw DirectorMethodException(msg TSRMLS_CC);
}
};
}
// DirectorMethodException() is documented to be callable with no parameters
// so use a macro to insert TSRMLS_CC so any ZTS context gets passed.
#define DirectorMethodException() DirectorMethodException("" TSRMLS_CC)
#endif /* __cplusplus */
#endif

109
Lib/php/factory.i Normal file
View 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

View file

@ -96,12 +96,22 @@
MAKE_STD_ZVAL(z_var);
z_var->type = IS_STRING;
if ($1) {
// varinit char [ANY]
/* varinit char [ANY] */
ZVAL_STRINGL(z_var,(char*)$1, $1_dim0, 1);
}
zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&z_var, sizeof(zval *), NULL);
}
%typemap(varinit, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*)
{
void * p = emalloc(sizeof($1));
memcpy(p, &$1, sizeof($1));
zval * resource;
MAKE_STD_ZVAL(resource);
ZEND_REGISTER_RESOURCE(resource, p, swig_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, fragment="swig_php_init_member_ptr") 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, swig_member_ptr);
memcpy(&$1, p, sizeof($1));
}
%typemap(varout) int,
unsigned int,
unsigned short,
@ -296,7 +315,7 @@
zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
if($1)
SWIG_SetPointerZval(*z_var, (void*)$1, $1_descriptor, 0);
SWIG_SetPointerZval(*z_var, (void*)$1, $1_descriptor, 0);
}
%typemap(varout) char [ANY]
@ -325,4 +344,12 @@ deliberate error cos this code looks bogus to me
SWIG_SetPointerZval(*z_var, (void*)$1, $1_descriptor, 0);
}
%typemap(varout, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*)
{
void * p = emalloc(sizeof($1));
memcpy(p, &$1, sizeof($1));
zval * resource;
MAKE_STD_ZVAL(resource);
ZEND_REGISTER_RESOURCE(resource, p, swig_member_ptr);
zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&resource, sizeof(zval *), NULL);
}

View file

@ -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
@ -70,8 +76,7 @@
$1 = ($1_ltype) Z_STRVAL_PP($input);
}
%typemap(in) (char *STRING, int LENGTH)
{
%typemap(in) (char *STRING, int LENGTH), (char *STRING, size_t LENGTH) {
convert_to_string_ex($input);
$1 = ($1_ltype) Z_STRVAL_PP($input);
$2 = ($2_ltype) Z_STRLEN_PP($input);
@ -86,6 +91,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,12 +114,21 @@
}
}
%typemap(in) SWIGTYPE *const& ($*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 = ($1_ltype)&temp;
}
%typemap(in) SWIGTYPE *DISOWN
{
if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) {
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor");
}
}
%typemap(argout) SWIGTYPE *,
SWIGTYPE [],
SWIGTYPE&;
@ -172,22 +194,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", (long long)$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", (unsigned long long)$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", (long long)(*$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", (unsigned long long)(*$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);
}
%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)?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);
}
%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 []
{
@ -198,18 +322,56 @@
}
}
%typemap(out) char *&
{
if(!*$1) {
ZVAL_NULL(return_value);
} else {
ZVAL_STRING(return_value, (char *)*$1, 1);
}
}
%typemap(out) SWIGTYPE *,
SWIGTYPE [],
SWIGTYPE &
%{
SWIG_SetPointerZval(return_value, (void *)$1, $1_descriptor, $owner);
%}
%typemap(out) SWIGTYPE *const&
%{
SWIG_SetPointerZval(return_value, (void *)*$1, $*1_descriptor, $owner);
%}
%typemap(directorin) SWIGTYPE *,
SWIGTYPE [],
SWIGTYPE &
%{
SWIG_SetPointerZval($input, (void *)&$1, $1_descriptor, ($owner)|2);
%}
%typemap(out, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*)
{
SWIG_SetPointerZval(return_value, (void *)$1, $1_descriptor, $owner);
void * p = emalloc(sizeof($1));
memcpy(p, &$1, sizeof($1));
zval * resource;
MAKE_STD_ZVAL(resource);
ZEND_REGISTER_RESOURCE(resource, p, swig_member_ptr);
SWIG_SetPointerZval(return_value, (void *)&$1, $1_descriptor, $owner);
}
%typemap(in, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*)
{
void * p = (void*)zend_fetch_resource($input TSRMLS_CC, -1, SWIG_MEMBER_PTR, NULL, 1, swig_member_ptr);
memcpy(&$1, p, sizeof($1));
}
%typemap(out) SWIGTYPE *DYNAMIC,
SWIGTYPE &DYNAMIC
{
swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor, (void **) &$1);
SWIG_SetPointerZval(return_value, (void *)$1, ty, $owner);
swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor, (void **) &$1);
SWIG_SetPointerZval(return_value, (void *)$1, ty, $owner);
}
%typemap(out) SWIGTYPE
@ -221,23 +383,30 @@
#else
{
$&1_ltype resultobj = ($&1_ltype) emalloc(sizeof($1_type));
memmove(resultobj, &$1, sizeof($1_type));
memcpy(resultobj, &$1, sizeof($1_type));
SWIG_SetPointerZval(return_value, (void *)resultobj, $&1_descriptor, 1);
}
#endif
%typemap(directorin) SWIGTYPE
{
SWIG_SetPointerZval($input, SWIG_as_voidptr(&$1), $&1_descriptor, 2);
}
%typemap(out) void "";
%typemap(out) char [ANY]
{
RETVAL_STRINGL($1,$1_dim0,1);
int len = 0;
while (len < $1_dim0 && $1[len]) ++len;
RETVAL_STRINGL($1, len, 1);
}
// 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
%typemap(typecheck,precedence=_prec) _type, const _type &
" $1 = (Z_TYPE_PP($input) == is); "
%enddef
@ -245,35 +414,49 @@
%php_typecheck(unsigned int,SWIG_TYPECHECK_UINT32,IS_LONG)
%php_typecheck(short,SWIG_TYPECHECK_INT16,IS_LONG)
%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,SWIG_TYPECHECK_INT32,IS_LONG)
%php_typecheck(unsigned long,SWIG_TYPECHECK_UINT32,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(size_t,SWIG_TYPECHECK_SIZE,IS_LONG)
%php_typecheck(enum SWIGTYPE,SWIG_TYPECHECK_INTEGER,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(double,SWIG_TYPECHECK_DOUBLE,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
" /* typecheck SWIGTYPE */ "
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *,
SWIGTYPE [],
SWIGTYPE &
{
void *tmp;
_v = (SWIG_ConvertPtr( *$input, (void**)&tmp, $1_descriptor, 0) >= 0);
_v = (SWIG_ConvertPtr(*$input, (void **)&tmp, $&1_descriptor, 0) >= 0);
}
%typecheck(SWIG_TYPECHECK_POINTER)
SWIGTYPE *,
SWIGTYPE [],
SWIGTYPE &,
SWIGTYPE *const&
{
void *tmp;
_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);
}
%typecheck(SWIG_TYPECHECK_VOIDPTR) void *
" /* typecheck void * */ "
{
void *tmp;
_v = (SWIG_ConvertPtr(*$input, (void**)&tmp, 0, 0) >= 0);
}
/* Exception handling */
@ -283,20 +466,27 @@
unsigned int,
unsigned long,
unsigned short {
char error_msg[256];
sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1);
SWIG_PHP_Error(E_ERROR, error_msg);
zend_throw_exception(NULL, const_cast<char*>("C++ $1_type exception thrown"), $1 TSRMLS_CC);
return;
}
%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY] %{
(void)$1;
SWIG_PHP_Error(E_ERROR, "C++ $1_type exception thrown");
zend_throw_exception(NULL, const_cast<char*>("C++ $1_type exception thrown"), 0 TSRMLS_CC);
return;
%}
%typemap(throws) char * %{
SWIG_PHP_Error(E_ERROR, (char *)$1);
zend_throw_exception(NULL, const_cast<char*>($1), 0 TSRMLS_CC);
return;
%}
/* Array reference typemaps */
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
/* php keywords */
%include <phpkw.swg>

View file

@ -10,3 +10,16 @@
SWIG_InitializeModule(0);
%}
%fragment("swig_php_init_member_ptr2", "header") {
#define SWIG_MEMBER_PTR ((char*)"CLASS::*")
static void swig_member_ptr_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
efree(rsrc->ptr);
}
static int swig_member_ptr = 0;
}
%fragment("swig_php_init_member_ptr", "init", fragment="swig_php_init_member_ptr2") {
swig_member_ptr = zend_register_list_destructors_ex(swig_member_ptr_dtor, NULL, SWIG_MEMBER_PTR, module_number);
}

View file

@ -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 */
@ -124,6 +124,8 @@ PHPBN2(E_COMPILE_WARNING);
PHPBN2(E_USER_ERROR);
PHPBN2(E_USER_WARNING);
PHPBN2(E_USER_NOTICE);
PHPBN2(E_DEPRECATED); // As of PHP 5.3
PHPBN2(E_USER_DEPRECATED); // As of PHP 5.3
PHPBN2(PHP_OS);
PHPBN2(PHP_VERSION);
PHPBN2(PHP_SAPI);
@ -146,6 +148,20 @@ PHPBN2(PHP_SHLIB_SUFFIX);
PHPBN2(PHP_OUTPUT_HANDLER_START);
PHPBN2(PHP_OUTPUT_HANDLER_CONT);
PHPBN2(PHP_OUTPUT_HANDLER_END);
PHPBN2(PHP_MAXPATHLEN); // As of PHP 5.3
/* These don't actually seem to be set (tested on Linux, I guess they're
* Windows only?) */
PHPBN2(PHP_WINDOWS_NT_DOMAIN_CONTROLLER); // As of PHP 5.3
PHPBN2(PHP_WINDOWS_NT_SERVER); // As of PHP 5.3
PHPBN2(PHP_WINDOWS_NT_WORKSTATION); // As of PHP 5.3
PHPBN2(PHP_WINDOWS_VERSION_BUILD); // As of PHP 5.3
PHPBN2(PHP_WINDOWS_VERSION_MAJOR); // As of PHP 5.3
PHPBN2(PHP_WINDOWS_VERSION_MINOR); // As of PHP 5.3
PHPBN2(PHP_WINDOWS_VERSION_PLATFORM); // As of PHP 5.3
PHPBN2(PHP_WINDOWS_VERSION_PRODUCTTYPE); // As of PHP 5.3
PHPBN2(PHP_WINDOWS_VERSION_SP_MAJOR); // As of PHP 5.3
PHPBN2(PHP_WINDOWS_VERSION_SP_MINOR); // As of PHP 5.3
PHPBN2(PHP_WINDOWS_VERSION_SUITEMASK); // As of PHP 5.3
/* "Standard Predefined Constants" from http://uk2.php.net/manual/en/reserved.constants.php */
PHPBN2(EXTR_OVERWRITE);
PHPBN2(EXTR_SKIP);
@ -175,6 +191,8 @@ PHPBN2(INI_USER);
PHPBN2(INI_PERDIR);
PHPBN2(INI_SYSTEM);
PHPBN2(INI_ALL);
PHPBN2(INI_SCANNER_NORMAL); // As of PHP 5.3
PHPBN2(INI_SCANNER_RAW); // As of PHP 5.3
PHPBN2(M_E);
PHPBN2(M_LOG2E);
PHPBN2(M_LOG10E);
@ -188,6 +206,10 @@ PHPBN2(M_2_PI);
PHPBN2(M_2_SQRTPI);
PHPBN2(M_SQRT2);
PHPBN2(M_SQRT1_2);
PHPBN2(M_EULER); // As of PHP 5.2
PHPBN2(M_LNPI); // As of PHP 5.2
PHPBN2(M_SQRT3); // As of PHP 5.2
PHPBN2(M_SQRTPI); // As of PHP 5.2
PHPBN2(CRYPT_SALT_LENGTH);
PHPBN2(CRYPT_STD_DES);
PHPBN2(CRYPT_EXT_DES);
@ -228,6 +250,7 @@ PHPBN2(STR_PAD_BOTH);
PHPBN2(PATHINFO_DIRNAME);
PHPBN2(PATHINFO_BASENAME);
PHPBN2(PATHINFO_EXTENSION);
PHPBN2(PATHINFO_FILENAME); // As of PHP 5.2
PHPBN2(PATH_SEPARATOR);
PHPBN2(CHAR_MAX);
PHPBN2(LC_CTYPE);
@ -351,108 +374,243 @@ PHPBN2(LOG_PERROR);
PHPBN2(E_STRICT);
PHPBN2(__COMPILER_HALT_OFFSET__);
/* Class names reserved by PHP */
PHPCN(stdClass);
PHPCN(__PHP_Incomplete_Class);
PHPCN(Directory);
/* Added in PHP 5.2 */
PHPBN2(PREG_BACKTRACK_LIMIT_ERROR);
PHPBN2(PREG_BAD_UTF8_ERROR);
PHPBN2(PREG_INTERNAL_ERROR);
PHPBN2(PREG_NO_ERROR);
PHPBN2(PREG_RECURSION_LIMIT_ERROR);
PHPBN2(UPLOAD_ERR_EXTENSION);
PHPBN2(STREAM_SHUT_RD);
PHPBN2(STREAM_SHUT_WR);
PHPBN2(STREAM_SHUT_RDWR);
PHPBN2(CURLE_FILESIZE_EXCEEDED);
PHPBN2(CURLE_FTP_SSL_FAILED);
PHPBN2(CURLE_LDAP_INVALID_URL);
PHPBN2(CURLFTPAUTH_DEFAULT);
PHPBN2(CURLFTPAUTH_SSL);
PHPBN2(CURLFTPAUTH_TLS);
PHPBN2(CURLFTPSSL_ALL);
PHPBN2(CURLFTPSSL_CONTROL);
PHPBN2(CURLFTPSSL_NONE);
PHPBN2(CURLFTPSSL_TRY);
PHPBN2(CURLOPT_FTP_SSL);
PHPBN2(CURLOPT_FTPSSLAUTH);
PHPBN2(CURLOPT_TCP_NODELAY); // Added in PHP 5.2.1
PHPBN2(CURLOPT_TIMEOUT_MS); // Added in PHP 5.2.3
PHPBN2(CURLOPT_CONNECTTIMEOUT_MS); // Added in PHP 5.2.3
PHPBN2(GMP_VERSION); // Added in PHP 5.2.2
PHPBN2(SWFTEXTFIELD_USEFONT);
PHPBN2(SWFTEXTFIELD_AUTOSIZE);
PHPBN2(SWF_SOUND_NOT_COMPRESSED);
PHPBN2(SWF_SOUND_ADPCM_COMPRESSED);
PHPBN2(SWF_SOUND_MP3_COMPRESSED);
PHPBN2(SWF_SOUND_NOT_COMPRESSED_LE);
PHPBN2(SWF_SOUND_NELLY_COMPRESSED);
PHPBN2(SWF_SOUND_5KHZ);
PHPBN2(SWF_SOUND_11KHZ);
PHPBN2(SWF_SOUND_22KHZ);
PHPBN2(SWF_SOUND_44KHZ);
PHPBN2(SWF_SOUND_8BITS);
PHPBN2(SWF_SOUND_16BITS);
PHPBN2(SWF_SOUND_MONO);
PHPBN2(SWF_SOUND_STEREO);
PHPBN2(OPENSSL_VERSION_NUMBER);
PHPBN2(SNMP_OID_OUTPUT_FULL);
PHPBN2(SNMP_OID_OUTPUT_NUMERIC);
PHPBN2(MSG_EAGAIN);
PHPBN2(MSG_ENOMSG);
/* Added in PHP 5.3 */
PHPBN2(CURLOPT_PROGRESSFUNCTION);
PHPBN2(IMG_FILTER_PIXELATE);
PHPBN2(JSON_ERROR_CTRL_CHAR);
PHPBN2(JSON_ERROR_DEPTH);
PHPBN2(JSON_ERROR_NONE);
PHPBN2(JSON_ERROR_STATE_MISMATCH);
PHPBN2(JSON_ERROR_SYNTAX);
PHPBN2(JSON_FORCE_OBJECT);
PHPBN2(JSON_HEX_TAG);
PHPBN2(JSON_HEX_AMP);
PHPBN2(JSON_HEX_APOS);
PHPBN2(JSON_HEX_QUOT);
PHPBN2(LDAP_OPT_NETWORK_TIMEOUT);
PHPBN2(LIBXML_LOADED_VERSION);
PHPBN2(PREG_BAD_UTF8_OFFSET_ERROR);
PHPBN2(BUS_ADRALN);
PHPBN2(BUS_ADRERR);
PHPBN2(BUS_OBJERR);
PHPBN2(CLD_CONTIUNED);
PHPBN2(CLD_DUMPED);
PHPBN2(CLD_EXITED);
PHPBN2(CLD_KILLED);
PHPBN2(CLD_STOPPED);
PHPBN2(CLD_TRAPPED);
PHPBN2(FPE_FLTDIV);
PHPBN2(FPE_FLTINV);
PHPBN2(FPE_FLTOVF);
PHPBN2(FPE_FLTRES);
PHPBN2(FPE_FLTSUB);
PHPBN2(FPE_FLTUND);
PHPBN2(FPE_INTDIV);
PHPBN2(FPE_INTOVF);
PHPBN2(ILL_BADSTK);
PHPBN2(ILL_COPROC);
PHPBN2(ILL_ILLADR);
PHPBN2(ILL_ILLOPC);
PHPBN2(ILL_ILLOPN);
PHPBN2(ILL_ILLTRP);
PHPBN2(ILL_PRVOPC);
PHPBN2(ILL_PRVREG);
PHPBN2(POLL_ERR);
PHPBN2(POLL_HUP);
PHPBN2(POLL_IN);
PHPBN2(POLL_MSG);
PHPBN2(POLL_OUT);
PHPBN2(POLL_PRI);
PHPBN2(SEGV_ACCERR);
PHPBN2(SEGV_MAPERR);
PHPBN2(SI_ASYNCIO);
PHPBN2(SI_KERNEL);
PHPBN2(SI_MESGQ);
PHPBN2(SI_NOINFO);
PHPBN2(SI_QUEUE);
PHPBN2(SI_SIGIO);
PHPBN2(SI_TIMER);
PHPBN2(SI_TKILL);
PHPBN2(SI_USER);
PHPBN2(SIG_BLOCK);
PHPBN2(SIG_SETMASK);
PHPBN2(SIG_UNBLOCK);
PHPBN2(TRAP_BRKPT);
PHPBN2(TRAP_TRACE);
/* Class names reserved by PHP */
/* 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

View file

@ -9,7 +9,9 @@ extern "C" {
#endif
#include "zend.h"
#include "zend_API.h"
#include "zend_exceptions.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 +23,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);\
@ -67,12 +78,12 @@ static int default_error_code = E_ERROR;
if (!(expr) ) { zend_printf("Contract Assert Failed %s\n",msg ); } else
/* Standard SWIG API */
#define SWIG_GetModule(clientdata) SWIG_Php4_GetModule()
#define SWIG_SetModule(clientdata, pointer) SWIG_Php4_SetModule(pointer)
#define SWIG_GetModule(clientdata) SWIG_Php_GetModule()
#define SWIG_SetModule(clientdata, pointer) SWIG_Php_SetModule(pointer)
/* 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,10 +92,10 @@ 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) {
swig_object_wrapper *value=NULL;
/*
* First test for Null pointers. Return those as PHP native NULL
*/
@ -93,12 +104,56 @@ SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject
return;
}
if (type->clientdata) {
swig_object_wrapper *value;
if (! (*(int *)(type->clientdata)))
zend_error(E_ERROR, "Type: %s failed to register with zend",type->name);
value=(swig_object_wrapper *)emalloc(sizeof(swig_object_wrapper));
value->ptr=ptr;
value->newobject=newobject;
ZEND_REGISTER_RESOURCE(z, value, *(int *)(type->clientdata));
value->newobject=(newobject & 1);
if ((newobject & 2) == 0) {
/* 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.
*/
zval *resource;
zend_class_entry **ce = NULL;
const char *type_name = type->name+3; /* +3 so: _p_Foo -> Foo */
size_t type_name_len;
int result;
const char * p;
/* Namespace__Foo -> Foo */
/* FIXME: ugly and goes wrong for classes with __ in their names. */
while ((p = strstr(type_name, "__")) != NULL) {
type_name = p + 2;
}
type_name_len = strlen(type_name);
MAKE_STD_ZVAL(resource);
ZEND_REGISTER_RESOURCE(resource, value, *(int *)(type->clientdata));
if (SWIG_PREFIX_LEN > 0) {
char * classname = (char*)emalloc(SWIG_PREFIX_LEN + type_name_len + 1);
strcpy(classname, SWIG_PREFIX);
strcpy(classname + SWIG_PREFIX_LEN, type_name);
result = zend_lookup_class(classname, SWIG_PREFIX_LEN + type_name_len, &ce TSRMLS_CC);
efree(classname);
} else {
result = zend_lookup_class((char *)type_name, type_name_len, &ce TSRMLS_CC);
}
if (result != 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);
}
return;
}
zend_error(E_ERROR, "Type: %s not registered with zend",type->name);
@ -150,10 +205,10 @@ SWIG_ZTS_ConvertResourcePtr(zval *z, swig_type_info *ty, int flags TSRMLS_DC) {
swig_object_wrapper *value;
void *p;
int type;
char *type_name;
const 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;
@ -196,7 +251,7 @@ SWIG_ZTS_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags TSRMLS_DC
}
static char const_name[] = "swig_runtime_data_type_pointer";
static swig_module_info *SWIG_Php4_GetModule() {
static swig_module_info *SWIG_Php_GetModule() {
zval *pointer;
swig_module_info *ret = 0;
@ -204,7 +259,7 @@ static swig_module_info *SWIG_Php4_GetModule() {
TSRMLS_FETCH();
if (zend_get_constant(const_name, sizeof(const_name), pointer TSRMLS_CC)) {
if (zend_get_constant(const_name, sizeof(const_name) - 1, pointer TSRMLS_CC)) {
if (pointer->type == IS_LONG) {
ret = (swig_module_info *) pointer->value.lval;
}
@ -213,7 +268,7 @@ static swig_module_info *SWIG_Php4_GetModule() {
return ret;
}
static void SWIG_Php4_SetModule(swig_module_info *pointer) {
static void SWIG_Php_SetModule(swig_module_info *pointer) {
TSRMLS_FETCH();
REGISTER_MAIN_LONG_CONSTANT(const_name, (long) pointer, 0);
}

View file

@ -27,11 +27,9 @@ 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) {
const T& get(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
@ -52,125 +50,23 @@ namespace std {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
}
};
// specializations for built-ins
%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
template<class T> class map<K,T> {
// add typemaps here
public:
map();
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) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void set(K key, const T& x) {
(*self)[key] = x;
}
void del(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(K key) {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
bool is_empty() const {
return self->empty();
}
}
};
%enddef
%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
template<class K> class map<K,T> {
// add typemaps here
public:
map();
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) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void set(const K& key, T x) {
(*self)[key] = x;
}
void del(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(const K& key) {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
}
};
%enddef
// Legacy macros (deprecated)
%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
#warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary"
%enddef
%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO,
T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
template<> class map<K,T> {
// add typemaps here
public:
map();
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) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void set(K key, T x) {
(*self)[key] = x;
}
void del(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(K key) {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
}
};
%enddef
%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
#warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary"
%enddef
// add specializations here
%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
#warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary"
%enddef
}

View file

@ -23,8 +23,8 @@ namespace std {
class string;
%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) string %{
$1 = ( Z_TYPE_PP($input) == IS_STRING ) ? 1 : 0;
%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) string, const string& %{
$1 = ( Z_TYPE_PP($input) == IS_STRING ) ? 1 : 0;
%}
%typemap(in) string %{
@ -32,24 +32,26 @@ namespace std {
$1.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;
%typemap(directorout) string %{
convert_to_string_ex($input);
$result.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
%}
%typemap(out) string %{
ZVAL_STRINGL($result, const_cast<char*>($1.data()), $1.size(), 1);
%}
%typemap(directorin) string, const string& %{
ZVAL_STRINGL($input, const_cast<char*>($1.data()), $1.size(), 1);
%}
%typemap(out) const string & %{
ZVAL_STRINGL($result, const_cast<char*>($1->data()), $1->size(), 1);
%}
%typemap(throws) string %{
SWIG_PHP_Error(E_ERROR, (char *)$1.c_str());
%}
%typemap(throws) const string& %{
SWIG_PHP_Error(E_ERROR, (char *)$1.c_str());
%typemap(throws) string, const string& %{
zend_throw_exception(NULL, const_cast<char*>($1.c_str()), 0 TSRMLS_CC);
return;
%}
/* These next two handle a function which takes a non-const reference to
@ -60,6 +62,13 @@ namespace std {
$1 = &temp;
%}
%typemap(directorout) string & (std::string *temp) %{
convert_to_string_ex($input);
temp = new std::string(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);
%}

View file

@ -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

View file

@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
* typemaps.i.
*
* SWIG Typemap library for PHP4.
* SWIG Typemap library for PHP.
*
* This library provides standard typemaps for modifying SWIG's behavior.
* With enough entries in this file, I hope that very few people actually
@ -24,116 +24,249 @@
* its value can be changed by foo().
* ----------------------------------------------------------------------------- */
%define double_typemap(TYPE)
%typemap(in) TYPE *INPUT(TYPE temp)
%define BOOL_TYPEMAP(TYPE)
%typemap(in) TYPE *INPUT(TYPE temp), TYPE &INPUT(TYPE temp)
%{
convert_to_boolean_ex($input);
temp = Z_LVAL_PP($input) ? true : false;
$1 = &temp;
%}
%typemap(argout) TYPE *INPUT, TYPE &INPUT "";
%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp), TYPE &OUTPUT(TYPE temp) "$1 = &temp;";
%typemap(argout,fragment="t_output_helper") TYPE *OUTPUT, TYPE &OUTPUT
{
zval *o;
MAKE_STD_ZVAL(o);
ZVAL_BOOL(o,temp$argnum);
t_output_helper( &$result, o );
}
%typemap(in) TYPE *REFERENCE (TYPE lvalue), TYPE &REFERENCE (TYPE lvalue)
%{
convert_to_boolean_ex($input);
lvalue = (*$input)->value.lval ? true : false;
$1 = &lvalue;
%}
%typemap(argout) TYPE *REFERENCE, TYPE &REFERENCE
%{
(*$arg)->value.lval = lvalue$argnum ? true : false;
(*$arg)->type = IS_BOOL;
%}
%enddef
%define DOUBLE_TYPEMAP(TYPE)
%typemap(in) TYPE *INPUT(TYPE temp), TYPE &INPUT(TYPE temp)
%{
convert_to_double_ex($input);
temp = (TYPE) Z_DVAL_PP($input);
$1 = &temp;
%}
%typemap(argout) TYPE *INPUT "";
%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp) "$1 = &temp;";
%typemap(argout,fragment="t_output_helper") TYPE *OUTPUT
%typemap(argout) TYPE *INPUT, TYPE &INPUT "";
%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp), TYPE &OUTPUT(TYPE temp) "$1 = &temp;";
%typemap(argout,fragment="t_output_helper") TYPE *OUTPUT, TYPE &OUTPUT
{
zval *o;
MAKE_STD_ZVAL(o);
ZVAL_DOUBLE(o,temp$argnum);
t_output_helper( &$result, o );
}
%typemap(in) TYPE *REFERENCE (TYPE dvalue)
%typemap(in) TYPE *REFERENCE (TYPE dvalue), TYPE &REFERENCE (TYPE dvalue)
%{
convert_to_double_ex($input);
dvalue = (TYPE) (*$input)->value.dval;
$1 = &dvalue;
%}
%typemap(argout) TYPE *REFERENCE
%typemap(argout) TYPE *REFERENCE, TYPE &REFERENCE
%{
$1->value.dval = (double)(lvalue$argnum);
$1->type = IS_DOUBLE;
%}
%enddef
%define int_typemap(TYPE)
%typemap(in) TYPE *INPUT(TYPE temp)
%define INT_TYPEMAP(TYPE)
%typemap(in) TYPE *INPUT(TYPE temp), TYPE &INPUT(TYPE temp)
%{
convert_to_long_ex($input);
temp = (TYPE) Z_LVAL_PP($input);
$1 = &temp;
%}
%typemap(argout) TYPE *INPUT "";
%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp) "$1 = &temp;";
%typemap(argout,fragment="t_output_helper") TYPE *OUTPUT
%typemap(argout) TYPE *INPUT, TYPE &INPUT "";
%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp), TYPE &OUTPUT(TYPE temp) "$1 = &temp;";
%typemap(argout,fragment="t_output_helper") TYPE *OUTPUT, TYPE &OUTPUT
{
zval *o;
MAKE_STD_ZVAL(o);
ZVAL_LONG(o,temp$argnum);
t_output_helper( &$result, o );
}
%typemap(in) TYPE *REFERENCE (TYPE lvalue)
%typemap(in) TYPE *REFERENCE (TYPE lvalue), TYPE &REFERENCE (TYPE lvalue)
%{
convert_to_long_ex($input);
lvalue = (TYPE) (*$input)->value.lval;
$1 = &lvalue;
%}
%typemap(argout) TYPE *REFERENCE
%typemap(argout) TYPE *REFERENCE, TYPE &REFERENCE
%{
(*$arg)->value.lval = (long)(lvalue$argnum);
(*$arg)->type = IS_LONG;
%}
%enddef
double_typemap(float);
double_typemap(double);
BOOL_TYPEMAP(bool);
int_typemap(int);
int_typemap(short);
int_typemap(long);
int_typemap(unsigned int);
int_typemap(unsigned short);
int_typemap(unsigned long);
int_typemap(unsigned char);
DOUBLE_TYPEMAP(float);
DOUBLE_TYPEMAP(double);
INT_TYPEMAP(int);
INT_TYPEMAP(short);
INT_TYPEMAP(long);
INT_TYPEMAP(unsigned int);
INT_TYPEMAP(unsigned short);
INT_TYPEMAP(unsigned long);
INT_TYPEMAP(unsigned char);
INT_TYPEMAP(signed char);
INT_TYPEMAP(long long);
%typemap(argout,fragment="t_output_helper") long long *OUTPUT
{
zval *o;
MAKE_STD_ZVAL(o);
if ((long long)LONG_MIN <= temp$argnum && temp$argnum <= (long long)LONG_MAX) {
ZVAL_LONG(o, temp$argnum);
} else {
char temp[256];
sprintf(temp, "%lld", (long long)temp$argnum);
ZVAL_STRING(o, temp, 1);
}
t_output_helper( &$result, o );
}
%typemap(in) TYPE *REFERENCE (long long lvalue)
%{
CONVERT_LONG_LONG_IN(lvalue, long long, $input)
$1 = &lvalue;
%}
%typemap(argout) long long *REFERENCE
%{
if ((long long)LONG_MIN <= lvalue$argnum && lvalue$argnum <= (long long)LONG_MAX) {
(*$arg)->value.lval = (long)(lvalue$argnum);
(*$arg)->type = IS_LONG;
} else {
char temp[256];
sprintf(temp, "%lld", (long long)lvalue$argnum);
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", (long long)(*arg$argnum));
ZVAL_STRING($result, temp, 1);
}
%}
INT_TYPEMAP(unsigned long long);
%typemap(argout,fragment="t_output_helper") unsigned long long *OUTPUT
{
zval *o;
MAKE_STD_ZVAL(o);
if (temp$argnum <= (unsigned long long)LONG_MAX) {
ZVAL_LONG(o, temp$argnum);
} else {
char temp[256];
sprintf(temp, "%llu", (unsigned long long)temp$argnum);
ZVAL_STRING(o, temp, 1);
}
t_output_helper( &$result, o );
}
%typemap(in) TYPE *REFERENCE (unsigned long long lvalue)
%{
CONVERT_UNSIGNED_LONG_LONG_IN(lvalue, unsigned long long, $input)
$1 = &lvalue;
%}
%typemap(argout) unsigned long long *REFERENCE
%{
if (lvalue$argnum <= (unsigned long long)LONG_MAX) {
(*$arg)->value.lval = (long)(lvalue$argnum);
(*$arg)->type = IS_LONG;
} else {
char temp[256];
sprintf(temp, "%llu", (unsigned long long)lvalue$argnum);
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", (unsigned long long)(*arg$argnum));
ZVAL_STRING($result, temp, 1);
}
%}
%typemap(in) bool *INOUT = bool *INPUT;
%typemap(in) float *INOUT = float *INPUT;
%typemap(in) double *INOUT = double *INPUT;
%typemap(in) int *INOUT = int *INPUT;
%typemap(in) short *INOUT = short *INPUT;
%typemap(in) long *INOUT = long *INPUT;
%typemap(in) long long *INOUT = 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) signed char *INOUT = signed char *INPUT;
%typemap(in) bool &INOUT = bool *INPUT;
%typemap(in) float &INOUT = float *INPUT;
%typemap(in) double &INOUT = double *INPUT;
%typemap(in) int &INOUT = int *INPUT;
%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(in) signed char &INOUT = signed char *INPUT;
%typemap(argout) bool *INOUT = bool *OUTPUT;
%typemap(argout) float *INOUT = float *OUTPUT;
%typemap(argout) double *INOUT= double *OUTPUT;
%typemap(argout) int *INOUT = int *OUTPUT;
%typemap(argout) short *INOUT = short *OUTPUT;
%typemap(argout) long *INOUT= long *OUTPUT;
%typemap(argout) long long *INOUT= long long *OUTPUT;
%typemap(argout) unsigned short *INOUT= unsigned short *OUTPUT;
%typemap(argout) unsigned long *INOUT = unsigned long *OUTPUT;
%typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT;
%typemap(argout) unsigned long long *INOUT = unsigned long long *OUTPUT;
%typemap(argout) signed char *INOUT = signed char *OUTPUT;
%typemap(argout) bool &INOUT = bool *OUTPUT;
%typemap(argout) float &INOUT = float *OUTPUT;
%typemap(argout) double &INOUT= double *OUTPUT;
%typemap(argout) int &INOUT = int *OUTPUT;
%typemap(argout) short &INOUT = short *OUTPUT;
%typemap(argout) long &INOUT= long *OUTPUT;
%typemap(argout) long long &INOUT= long long *OUTPUT;
%typemap(argout) unsigned short &INOUT= unsigned short *OUTPUT;
%typemap(argout) unsigned long &INOUT = unsigned long *OUTPUT;
%typemap(argout) unsigned char &INOUT = unsigned char *OUTPUT;
%typemap(argout) unsigned long long &INOUT = unsigned long long *OUTPUT;
%typemap(argout) signed char &INOUT = signed char *OUTPUT;
%typemap(in) char INPUT[ANY] ( char temp[$1_dim0] )
%{

View file

@ -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
@ -24,15 +60,33 @@
%enddef
%define CONVERT_STRING_IN(lvar,t,invar)
convert_to_string_ex(invar);
lvar = (t) Z_STRVAL_PP(invar);
if ((*invar)->type==IS_NULL) {
lvar = (t) 0;
} else {
convert_to_string_ex(invar);
lvar = (t) Z_STRVAL_PP(invar);
}
%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") %{
@ -45,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;