The great merge

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2002-11-30 22:01:28 +00:00
commit 516036631c
1508 changed files with 125983 additions and 44037 deletions

498
SWIG/Lib/php4/php4.swg Normal file
View file

@ -0,0 +1,498 @@
/*
* php4.swg
*
* PHP 4 configuration file
*
*/
%runtime "common.swg" // common type checking code
%runtime "php4run.swg" // Php4 runtime functions
%include "utils.i" // building blocks
/* Typemaps for input parameters by value */
%typemap(in) int, unsigned int, unsigned short, short, unsigned short, long, unsigned long, signed char, unsigned char, enum SWIGTYPE %{
convert_to_long_ex($input);
$1 = ($1_ltype) Z_LVAL_PP($input);
%}
%typemap(in) bool %{
convert_to_boolean_ex($input);
$1 = ($1_ltype) Z_LVAL_PP($input);
%}
%typemap(in) char %{
convert_to_string_ex($input);
$1 = ($1_ltype) *Z_STRVAL_PP($input);
%}
%typemap(in) float,double %{
convert_to_double_ex($input);
$1 = ($1_ltype) Z_DVAL_PP($input);
%}
// char * is input only normally
%typemap(in) char * %{
convert_to_string_ex($input);
$1 = ($1_ltype) Z_STRVAL_PP($input);
%}
// char array can be in/out, though the passed string may not be big enough...
// so we have to size it
strarray_inout(char [ANY])
%typemap(in) SWIGTYPE *, SWIGTYPE [], SWIGTYPE & %{
if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor) < 0) {
zend_error(E_ERROR, "Type error in argument %d of $symname. Expected %s", $argnum-argbase, $1_descriptor->name);
}
%}
%typemap(in) void * %{
if(SWIG_ConvertPtr(*$input, (void **) &$1, 0) < 0) {
/* Allow NULL from php for void* */
if ((*$input)->type==IS_NULL) $1=0;
else zend_error(E_ERROR, "Type error in argument %d of $symname. Expected %s", $argnum-argbase, $1_descriptor->name);
}
%}
/* Special case when void* is passed by reference so it can be made to point
to opaque api structs */
%typemap(in) void ** ($*1_ltype ptr, int force), void *& ($*1_ltype ptr, int force) %{
/* If they pass NULL by reference, make it into a void*
This bit should go in arginit if arginit support init-ing scripting args */
if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor) < 0) {
/* So... we didn't get a ref or ptr, but we'll accept NULL by reference */
if ((*$input)->type==IS_NULL && PZVAL_IS_REF(*$input)) {
#if __cplusplus
ptr=new $*1_ltype;
#else
ptr=($*1_ltype) calloc(1,sizeof($*1_ltype));
#endif
$1=&ptr;
/* have to passback arg$arg too */
force=1;
} else { /* wasn't a pre/ref/thing, OR anything like an int thing */
force=0;
zend_error(E_ERROR, "Type error in argument %d of $symname. Expected %s or %s or at least NULL passed by reference", $argnum-argbase, $1_descriptor->name,$*1_descriptor->name);
}
} else force=0;
%}
%typemap(argout) void **, void *& %{
if (force$argnum) { /* pass back arg$argnum through params ($arg) if we can */
if(! PZVAL_IS_REF(*$arg)) {
zend_error(E_WARNING, "Parameter %d of $symname wasn't passed by reference: [argout void**, void*&]",$argnum-argbase);
} else {
SWIG_SetPointerZval(*$arg, (void *) ptr$argnum, $*1_descriptor, 1);
}
}
%}
/* Object passed by value. Convert to a pointer */
%typemap(in) SWIGTYPE {
$&1_ltype argp;
if(SWIG_ConvertPtr(*$input, (void **) &argp, $&1_descriptor) < 0) {
zend_error(E_ERROR, "Type error in argument %d of $symname. Expected %s", $argnum-argbase, $&1_descriptor->name);
}
$1 = *argp;
}
/* Typemap for output values */
%typemap(out) int, unsigned int, short, unsigned short, long, unsigned long, signed char, unsigned char, bool, enum SWIGTYPE %{
ZVAL_LONG(return_value,$1);
%}
%typemap(out) bool %{
ZVAL_BOOL(return_value,($1)?1:0);
%}
%typemap(out) float, double %{
ZVAL_DOUBLE(return_value,$1);
%}
%typemap(out) char %{
// out char
ZVAL_STRINGL(return_value,$1, 1, 1);
%}
%typemap(out) char * %{
ZVAL_STRING(return_value,$1, 1);
%}
%typemap(out) SWIGTYPE *, SWIGTYPE [], SWIGTYPE & %{
SWIG_SetPointerZval(return_value, (void *)$1, $1_descriptor, $owner);
%}
%typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC {
swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor, (void **) &$1);
SWIG_SetPointerZval(return_value, (void *)$1, ty, $owner);
}
%typemap(out) SWIGTYPE
#ifdef __cplusplus
{
$&1_ltype resultobj = new $1_ltype(($1_ltype &) $1);
SWIG_SetPointerZval(return_value, (void *)resultobj, $&1_descriptor, $owner);
}
#else
{
$&1_ltype resultobj = ($&1_ltype) emalloc(sizeof($1_type));
memmove(resultobj, &$1, sizeof($1_type));
SWIG_SetPointerZval(return_value, (void *)resultobj, $&1_descriptor, $owner);
}
#endif
%typemap(out) void "";
/* Typemap for character array returns */
%typemap(out) char [ANY] {
// out char any
ZVAL_STRINGL(return_value,$1, $1_dim0, 1);
}
/* Typemap for in/argout references
NOTE: we don't choose to use these for arrays yet, maybe later */
%typemap_inout_ord(bool,convert_to_bool_ex,ZVAL_BOOL)
%typemap_inout_ord(int,convert_to_long_ex,ZVAL_LONG)
%typemap_inout_ord(unsigned int,convert_to_long_ex,ZVAL_LONG)
%typemap_inout_ord(short,convert_to_long_ex,ZVAL_LONG)
%typemap_inout_ord(unsigned short,convert_to_long_ex,ZVAL_LONG)
%typemap_inout_ord(long,convert_to_long_ex,ZVAL_LONG)
%typemap_inout_ord(unsigned long,convert_to_long_ex,ZVAL_LONG)
%typemap_inout_ord(signed char,convert_to_long_ex,ZVAL_LONG)
%typemap_inout_ord(unsigned char,convert_to_long_ex,ZVAL_LONG)
%typemap_inout_ord(enum SWIGTYPE,convert_to_long_ex,ZVAL_LONG)
/* Global variables - add the variable to PHP */
%typemap(varinit) char *
{
zval *z_var;
MAKE_STD_ZVAL(z_var);
z_var->type = IS_STRING;
if($1) {
z_var->value.str.val = estrdup($1);
z_var->value.str.len = strlen($1);
} else {
z_var->value.str.val = 0;
z_var->value.str.len = 0;
}
zend_hash_add(&EG(symbol_table), "$1", strlen("$1")+1, (void *)&z_var, sizeof(zval *), NULL);
}
%typemap(varinit) int, unsigned int, unsigned short, short, unsigned short, long, unsigned long, signed char, unsigned char, bool, enum SWIGTYPE
{
zval *z_var;
MAKE_STD_ZVAL(z_var);
z_var->type = IS_LONG;
z_var->value.lval = $1;
zend_hash_add(&EG(symbol_table), "$1", strlen("$1")+1, (void *)&z_var, sizeof(zval *), NULL);
}
%typemap(varinit) bool
{
zval *z_var;
MAKE_STD_ZVAL(z_var);
z_var->type = IS_BOOL;
z_var->value.lval = ($1)?1:0;
zend_hash_add(&EG(symbol_table), "$1", strlen("$1")+1, (void *)&z_var, sizeof(zval *), NULL);
}
%typemap(varinit) float, double
{
zval *z_var;
MAKE_STD_ZVAL(z_var);
z_var->type = IS_DOUBLE;
z_var->value.dval = $1;
zend_hash_add(&EG(symbol_table), "$1", strlen("$1")+1, (void *)&z_var,
sizeof(zval *), NULL);
}
%typemap(varinit) char
{
zval *z_var;
char c[2];
MAKE_STD_ZVAL(z_var);
c[0] = $1;
c[1] = 0;
z_var->type = IS_STRING;
z_var->value.str.val = estrdup(c);
z_var->value.str.len = 2;
zend_hash_add(&EG(symbol_table), "$1", strlen("$1")+1, (void *)&z_var,
sizeof(zval *), NULL);
}
%typemap(varinit) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
{
zval *z_var;
MAKE_STD_ZVAL(z_var);
SWIG_SetPointerZval(z_var, (void*)$1, $1_descriptor, $owner);
zend_hash_add(&EG(symbol_table), "$1", strlen("$1")+1, (void *)&z_var,
sizeof(zval *), NULL);
}
%typemap(varinit) SWIGTYPE
{
$&1_ltype argp;
zval *z_var;
MAKE_STD_ZVAL(z_var);
SWIG_SetPointerZval(z_var, (void*)&$1, $&1_descriptor, $owner);
zend_hash_add(&EG(symbol_table), "$1", strlen("$1")+1, (void*)&z_var,
sizeof(zval *), NULL);
}
%typemap(varinit) char [ANY]
{
zval *z_var;
MAKE_STD_ZVAL(z_var);
z_var->type = IS_STRING;
if($1) {
// varinit char [ANY]
ZVAL_STRINGL(z_var,$1, $1_dim0, 1);
}
zend_hash_add(&EG(symbol_table), "$1", strlen("$1")+1, (void*)&z_var,
sizeof(zval *), NULL);
}
%typemap(varin) int, unsigned int, unsigned short, short, unsigned short, long, unsigned long, signed char, unsigned char, enum SWIGTYPE
{
zval **z_var;
zend_hash_find(&EG(symbol_table), "$1",strlen("$1")+1, (void**)&z_var);
convert_to_long_ex(z_var);
if($1 != ($1_ltype)((*z_var)->value.lval)) {
$1 = Z_LVAL_PP(z_var);
}
}
%typemap(varin) bool
{
zval **z_var;
zend_hash_find(&EG(symbol_table), "$1",strlen("$1")+1, (void**)&z_var);
convert_to_boolean_ex(z_var);
if($1 != ($1_ltype)((*z_var)->value.lval)) {
$1 = Z_LVAL_PP(z_var);
}
}
%typemap(varin) double,float
{
zval **z_var;
zend_hash_find(&EG(symbol_table), "$1", strlen("$1")+1, (void**)&z_var);
convert_to_double_ex(z_var);
if($1 != ($1_ltype)((*z_var)->value.dval)) {
$1 = Z_DVAL_PP(z_var);
}
}
%typemap(varin) char
{
zval **z_var;
zend_hash_find(&EG(symbol_table), "$1",strlen("$1")+1, (void**)&z_var);
convert_to_string_ex(z_var);
if($1 != *((*z_var)->value.str.val)) {
$1 = *((*z_var)->value.str.val);
}
}
%typemap(varin) char *
{
zval **z_var;
char *s1;
zend_hash_find(&EG(symbol_table), "$1", strlen("$1")+1, (void**)&z_var);
convert_to_string_ex(z_var);
s1 = Z_STRVAL_PP(z_var);
if((s1 == NULL) || ($1 == NULL) || zend_binary_strcmp(s1, strlen(s1), $1, strlen($1))) {
if(s1)
$1 = estrdup(s1);
else
$1 = NULL;
}
}
%typemap(varin) SWIGTYPE []
{
zval **z_var;
zend_hash_find(&EG(symbol_table), "$1", strlen("$1")+1, (void**)&z_var);
if($1) {
SWIG_SetPointerZval(*z_var, (void*)$1, $1_descriptor, $owner);
}
}
%typemap(varin) char [ANY]
{
zval **z_var;
char *s1;
zend_hash_find(&EG(symbol_table), "$1", strlen("$1")+1, (void**)&z_var);
s1 = Z_STRVAL_PP(z_var);
if((s1 == NULL) || ($1 == NULL) || zend_binary_strcmp(s1, strlen(s1), $1, strlen($1))) {
if(s1)
strncpy($1, s1, $1_dim0);
}
}
%typemap(varin) SWIGTYPE
{
zval **z_var;
$&1_ltype _temp;
zend_hash_find(&EG(symbol_table), "$1", strlen("$1")+1, (void**)&z_var);
if (SWIG_ConvertPtr(*z_var, (void**)&_temp, $&1_descriptor) < 0) {
zend_error(E_ERROR, "Type error in value of $symname. Expected %s", $&1_descriptor->name);
}
$1 = *($&1_ltype)_temp;
}
%typemap(varin) SWIGTYPE *, SWIGTYPE &
{
zval **z_var;
$1_ltype _temp;
zend_hash_find(&EG(symbol_table), "$1", strlen("$1")+1, (void**)&z_var);
if (SWIG_ConvertPtr(*z_var, (void **)&_temp, $1_descriptor) < 0) {
zend_error(E_ERROR, "Type error in value of $symname. Expected %s", $1_descriptor->name);
}
$1 = ($1_ltype)_temp;
}
%typemap(varout) int, unsigned int, unsigned short, short, unsigned short, long, unsigned long, signed char, unsigned char, enum SWIGTYPE
{
zval **z_var;
zend_hash_find(&EG(symbol_table), "$1", strlen("$1")+1, (void**)&z_var);
if($1 != ($1_ltype)((*z_var)->value.lval)) {
(*z_var)->value.lval = (long)$1;
}
}
//SAMFIX need to cast zval->type, what if zend-hash_find fails? etc?
%typemap(varout) bool
{
zval **z_var;
zend_hash_find(&EG(symbol_table), "$1", strlen("$1")+1, (void**)&z_var);
if($1 != ($1_ltype)((*z_var)->value.lval)) {
(*z_var)->value.lval = (long)$1;
}
}
%typemap(varout) double, float
{
zval **z_var;
zend_hash_find(&EG(symbol_table), "$1", strlen("$1")+1, (void**)&z_var);
if($1 != ($1_ltype)((*z_var)->value.dval)) {
(*z_var)->value.dval = (double)$1;
}
}
%typemap(varout) char
{
zval **z_var;
zend_hash_find(&EG(symbol_table), "$1", strlen("$1")+1, (void**)&z_var);
if($1 != *((*z_var)->value.str.val)) {
char c[2];
efree((*z_var)->value.str.val);
c[0] = $1;
c[1] = 0;
(*z_var)->value.str.val = estrdup(c);
}
}
%typemap(varout) char *
{
zval **z_var;
char *s1;
zend_hash_find(&EG(symbol_table), "$1", strlen("$1")+1, (void**)&z_var);
s1 = Z_STRVAL_PP(z_var);
if((s1 == NULL) || ($1 == NULL) || zend_binary_strcmp(s1, strlen(s1), $1, strlen($1) )) {
if(s1)
efree(s1);
if($1) {
(*z_var)->value.str.val = estrdup($1);
(*z_var)->value.str.len = strlen($1) +1;
} else {
(*z_var)->value.str.val = 0;
(*z_var)->value.str.len = 0;
}
}
}
%typemap(varout) SWIGTYPE
{
zval **z_var;
zend_hash_find(&EG(symbol_table), "$1", strlen("$1")+1, (void**)&z_var);
SWIG_SetPointerZval(*z_var, (void*)&$1, $&1_descriptor, $owner);
}
%typemap(varout) SWIGTYPE []
{
zval **z_var;
zend_hash_find(&EG(symbol_table), "$1", strlen("$1")+1, (void**)&z_var);
if($1)
SWIG_SetPointerZval(*z_var, (void*)$1, $1_descriptor, $owner);
}
%typemap(varout) char [ANY]
{
zval **z_var;
char *s1;
deliberate error cos this code looks bogus to me
zend_hash_find(&EG(symbol_table), "$1" ,strlen("$1")+1, (void**)&z_var);
s1 = Z_STRVAL_PP(z_var);
if((s1 == NULL) || zend_binary_strcmp(s1, strlen(s1), $1, strlen($1))) {
if($1) {
(*z_var)->value.str.val = estrdup($1);
(*z_var)->value.str.len = strlen($1)+1;
} else {
(*z_var)->value.str.val = 0;
(*z_var)->value.str.len = 0;
}
}
}
%typemap(varout) SWIGTYPE *, SWIGTYPE &
{
zval **z_var;
zend_hash_find(&EG(symbol_table), "$1", strlen("$1")+1, (void**)&z_var);
SWIG_SetPointerZval(*z_var, (void*)$1, $1_descriptor, $owner);
}
/* Typemaps for constants */
%typemap(consttab) int, unsigned int, short, unsigned short, long, unsigned long, unsigned char, signed char, bool, enum SWIGTYPE
"REGISTER_LONG_CONSTANT( \"$symname\", $value, CONST_CS | CONST_PERSISTENT);";
%typemap(consttab) float, double
"REGISTER_DOUBLE_CONSTANT(\"$symname\", $value, CONST_CS | CONST_PERSISTENT);";
%typemap(consttab) char, char *
"REGISTER_STRING_CONSTANT(\"$symname\", \"$value\", CONST_CS | CONST_PERSISTENT);";
%typemap(consttab) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
char *cp;
SWIG_SetPointerChar(&cp, (void*)$value, $1_descriptor);
REGISTER_STRING_CONSTANT("$symname", cp, CONST_CS | CONST_PERSISTENT);
}
/* Some ANSI C typemaps */
%apply long { size_t };

240
SWIG/Lib/php4/php4run.swg Normal file
View file

@ -0,0 +1,240 @@
/*
* php4.swg
*
* PHP4 runtime library
*
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "zend.h"
#include "zend_API.h"
#include "php.h"
/* These TSRMLS_ stuff should already be defined now, but with older php under
redhat are not... */
#ifndef TSRMLS_D
#define TSRMLS_D
#endif
#ifndef TSRMLS_DC
#define TSRMLS_DC
#endif
#ifndef TSRMLS_C
#define TSRMLS_C
#endif
#ifndef TSRMLS_CC
#define TSRMLS_CC
#endif
#ifdef __cplusplus
}
#endif
/* used to wrap returned objects in so we know whether they are newobject
and need freeing, or not */
typedef struct _swig_object_wrapper {
void * ptr;
int newobject;
} swig_object_wrapper;
/* local scope self_constructors are set to 1 inside function wrappers
which are also class constructors, so that the php4.swg output typemaps
know whether or not to wrap returned objects in this_ptr or a new object */
int self_constructor=0;
/* empty zend destructor for types without one */
static ZEND_RSRC_DTOR_FUNC(SWIG_landfill) {};
/* This one makes old swig style string pointers but the php module doesn't
use these any more. This is just left here for old times sake and may go */
SWIGRUNTIME(void)
SWIG_MakePtr(char *c, void *ptr, swig_type_info *ty) {
static char hex[17] = "0123456789abcdef";
unsigned long p, s;
char data[32], *r;
r = data;
p = (unsigned long) ptr;
if (p > 0) {
while (p > 0) {
s = p & 0xf;
*(r++) = hex[s];
p = p >> 4;
}
*r = '_';
while (r >= data) {
*(c++) = *(r--);
}
strcpy (c, ty->name);
} else {
strcpy (c, "NULL");
}
}
SWIGRUNTIME(void)
SWIG_SetPointerChar(char **c, void *ptr, swig_type_info *type) {
char data[512];
SWIG_MakePtr(data, ptr, type);
*c = estrdup(data);
}
#define SWIG_SetPointerZval(a,b,c,d) SWIG_ZTS_SetPointerZval(a,b,c,d, SWIG_module_entry TSRMLS_CC)
SWIGRUNTIME(void)
SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject, zend_module_entry* module_entry TSRMLS_DC) {
swig_object_wrapper *value=NULL;
/* No need to call SWIG_MakePtr here! */
if (type->clientdata) {
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));
return;
} else { /* have to deal with old fashioned string pointer?
but this should not get this far */
zend_error(E_ERROR, "Type: %s not registered with zend",type->name);
}
}
/* This old-style routine converts an old string-pointer c into a real pointer
ptr calling making appropriate casting functions according to ty
We don't use this any more */
SWIGRUNTIME(int)
_SWIG_ConvertPtr(char *c, void **ptr, swig_type_info *ty) {
register int d;
unsigned long p;
swig_type_info *tc;
if(c == NULL) {
*ptr = 0;
return 0;
}
p = 0;
if (*c != '_') {
*ptr = (void *) 0;
if (strcmp(c,"NULL") == 0) {
return 0;
} else {
goto type_error;
}
}
c++;
/* Extract hex value from pointer */
while ((d = *c)) {
if ((d >= '0') && (d <= '9'))
p = (p << 4) + (d - '0');
else if ((d >= 'a') && (d <= 'f'))
p = (p << 4) + (d - ('a'-10));
else
break;
c++;
}
*ptr = (void *) p;
if(ty) {
tc = SWIG_TypeCheck(c,ty);
if(!tc) goto type_error;
*ptr = SWIG_TypeCast(tc, (void*)p);
}
return 0;
type_error:
return -1;
}
/* This is a new pointer conversion routine
Taking the native pointer p (which would have been converted from the old
string pointer) and it's php type id, and it's type name (which also would
have come from the old string pointer) it converts it to ptr calling
appropriate casting functions according to ty
Sadly PHP has no API to find a type name from a type id, only from an instance
of a resource of the type id, so we have to pass type_name as well.
The two functions which might call this are:
SWIG_ZTS_ConvertResourcePtr which gets the type name from the resource
and the registered zend destructors for which we have one per type each
with the type name hard wired in. */
SWIGRUNTIME(int)
SWIG_ZTS_ConvertResourceData(void * p, int type, const char *type_name, void **ptr, swig_type_info *ty TSRMLS_DC) {
swig_type_info *tc;
if (ty) {
if (! type_name) {
/* can't convert p to ptr type ty if we don't know what type p is */
return -1;
} else {
/* convert and cast p from type_name to ptr as ty
Need to sort out const-ness, can SWIG_TypeCast really not take a const? */
tc = SWIG_TypeCheck((char *)type_name,ty);
if (!tc) return -1;
*ptr = SWIG_TypeCast(tc, (void*)p);
}
} else {
/* They don't care about the target type, so just pass on the pointer! */
*ptr = (void *) p;
}
return 0;
}
/* This function fills ptr with a pointer of type ty by extracting the pointer
and type info from the resource in z. z must be a resource
It uses SWIG_ZTS_ConvertResourceData to do the real work. */
SWIGRUNTIME(int)
SWIG_ZTS_ConvertResourcePtr(zval *z, void **ptr, swig_type_info *ty TSRMLS_DC) {
swig_object_wrapper *value;
void *p;
int type;
char *type_name;
value = (swig_object_wrapper *) zend_list_find(z->value.lval,&type);
p = value->ptr;
if (type==-1) return -1;
type_name=zend_rsrc_list_get_rsrc_type(z->value.lval);
return SWIG_ZTS_ConvertResourceData(p,type,type_name,ptr,ty TSRMLS_CC);
}
/* But in fact SWIG_ConvertPtr is the native interface for getting typed
pointer values out of zvals. We need the TSRMLS_ macros for when we
make PHP type calls later as we handle php resources */
#define SWIG_ConvertPtr(a,b,c) SWIG_ZTS_ConvertPtr(a,b,c TSRMLS_CC)
/* We allow passing of a STRING or RESOURCE pointing to the object
or an OBJECT whose _cPtr is a string or resource pointing to the object
STRING pointers are very depracated */
SWIGRUNTIME(int)
SWIG_ZTS_ConvertPtr(zval *z, void **ptr, swig_type_info *ty TSRMLS_DC) {
char *c;
zval *val;
if(z == NULL) {
*ptr = 0;
return 0;
}
if (z->type==IS_OBJECT) {
zval ** _cPtr;
if (zend_hash_find(HASH_OF(z),"_cPtr",sizeof("_cPtr"),(void**)&_cPtr)==SUCCESS) {
/* Don't co-erce to string if it isn't */
if ((*_cPtr)->type==IS_STRING) c = Z_STRVAL_PP(_cPtr);
else if ((*_cPtr)->type==IS_RESOURCE) {
return SWIG_ZTS_ConvertResourcePtr(*_cPtr,ptr,ty TSRMLS_CC);
} else goto type_error; /* _cPtr was not string or resource property */
} else goto type_error; /* can't find property _cPtr */
} else if (z->type==IS_RESOURCE) {
return SWIG_ZTS_ConvertResourcePtr(z,ptr,ty TSRMLS_CC);
} else if (z->type==IS_STRING) {
c = Z_STRVAL_P(z);
return _SWIG_ConvertPtr(c,ptr,ty);
} else goto type_error;
type_error:
return -1;
}

View file

@ -0,0 +1,45 @@
//
// SWIG typemaps for std::string types
// Luigi Ballabio
// May 7, 2002
//
// PHP implementation
// ------------------------------------------------------------------------
// std::string is typemapped by value
// This can prevent exporting methods which return a string
// in order for the user to modify it.
// However, I think I'll wait until someone asks for it...
// ------------------------------------------------------------------------
%include exception.i
%{
#include <string>
%}
namespace std {
class string;
%typemap(in) string {
convert_to_string_ex($input);
$1 = std::string(Z_STRVAL_PP($input));
}
%typemap(in) const string & (std::string temp) {
convert_to_string_ex($input);
temp = std::string(Z_STRVAL_PP($input));
$1 = &temp;
}
%typemap(out) string {
ZVAL_STRINGL($result,const_cast<char*>($1.c_str()),$1.length(),1);
}
%typemap(out) const string & {
ZVAL_STRINGL($result,const_cast<char*>($1->c_str()),$1->length(),1);
}
}

156
SWIG/Lib/php4/std_vector.i Normal file
View file

@ -0,0 +1,156 @@
//
// SWIG typemaps for std::vector types
// Luigi Ballabio
// May 7, 2002
//
// PHP implementation
%include exception.i
// containers
// methods which can raise are caused to throw an IndexError
%exception std::vector::get {
try {
$action
} catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}
%exception std::vector::set {
try {
$action
} catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}
%exception std::vector::pop {
try {
$action
} catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}
// ------------------------------------------------------------------------
// 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;
bool empty() const;
void clear();
%rename(push) push_back;
void push_back(const T& x);
%extend {
T pop() {
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) {
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) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = x;
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;
bool empty() const;
void clear();
%rename(push) push_back;
void push_back(T x);
%extend {
T pop() {
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) {
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) {
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(int);
specialize_std_vector(short);
specialize_std_vector(long);
specialize_std_vector(unsigned int);
specialize_std_vector(unsigned short);
specialize_std_vector(unsigned long);
specialize_std_vector(float);
specialize_std_vector(double);
}

9
SWIG/Lib/php4/stl.i Normal file
View file

@ -0,0 +1,9 @@
//
// SWIG typemaps for STL types
// Luigi Ballabio and Manu ???
// Apr 26, 2002
//
%include std_string.i
%include std_vector.i

234
SWIG/Lib/php4/typemaps.i Normal file
View file

@ -0,0 +1,234 @@
//
// SWIG Typemap library
// Richard Palmer
// Oct 3, 2001
//
// PHP4 implementation
//
//
// This library provides standard typemaps for modifying SWIG's behavior.
// With enough entries in this file, I hope that very few people actually
// ever need to write a typemap.
//
%typemap(in) double *INPUT(double temp)
{
temp = (double) Z_DVAL_PP($input);
$1 = &temp;
}
%typemap(in) float *INPUT(float temp)
{
temp = (float) Z_DVAL_PP($input);
$1 = &temp;
}
%typemap(in) int *INPUT(int temp)
{
temp = (int) Z_LVAL_PP($input);
$1 = &temp;
}
%typemap(in) short *INPUT(short temp)
{
temp = (short) Z_LVAL_PP($input);
$1 = &temp;
}
%typemap(in) long *INPUT(long temp)
{
temp = (long) Z_LVAL_PP($input);
$1 = &temp;
}
%typemap(in) unsigned int *INPUT(unsigned int temp)
{
temp = (unsigned int) Z_LVAL_PP($input);
$1 = &temp;
}
%typemap(in) unsigned short *INPUT(unsigned short temp)
{
temp = (unsigned short) Z_LVAL_PP($input);
$1 = &temp;
}
%typemap(in) unsigned long *INPUT(unsigned long temp)
{
temp = (unsigned long) Z_LVAL_PP($input);
$1 = &temp;
}
%typemap(in) unsigned char *INPUT(unsigned char temp)
{
temp = (unsigned char) Z_LVAL_PP($input);
$1 = &temp;
}
%typemap(in,numinputs=0) int *OUTPUT(int temp),
short *OUTPUT(short temp),
long *OUTPUT(long temp),
unsigned int *OUTPUT(unsigned int temp),
unsigned short *OUTPUT(unsigned short temp),
unsigned long *OUTPUT(unsigned long temp),
unsigned char *OUTPUT(unsigned char temp),
float *OUTPUT(float temp),
double *OUTPUT(double temp)
{
$1 = &temp;
}
%typemap(argout) int *OUTPUT,
short *OUTPUT,
long *OUTPUT,
unsigned int *OUTPUT,
unsigned short *OUTPUT,
unsigned long *OUTPUT,
unsigned char *OUTPUT
{
ZVAL_LONG($result,*($input));
}
%typemap(argout) float *OUTPUT,
double *OUTPUT
{
ZVAL_DOUBLE($result,*($input));
}
%typemap(in) int *INOUT = int *INPUT;
%typemap(in) short *INOUT = short *INPUT;
%typemap(in) long *INOUT = 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) float *INOUT = float *INPUT;
%typemap(in) double *INOUT = double *INPUT;
%typemap(argout) int *INOUT = int *OUTPUT;
%typemap(argout) short *INOUT = short *OUTPUT;
%typemap(argout) long *INOUT= 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) float *INOUT = float *OUTPUT;
%typemap(argout) double *INOUT= double *OUTPUT;
// REFERENCE
// Accept Php references as pointers
%typemap(in) double *REFERENCE (double dvalue)
{
if(!ParameterPassedByReference(ht, argvi))
{
zend_error(E_WARNING, "Parameter wasn't passed by reference");
RETURN_NULL();
}
dvalue = (double) (*$input)->value.dval;
$1 = &dvalue;
}
%typemap(in) float *REFERENCE (float dvalue)
{
if(!ParameterPassedByReference(ht, argvi))
{
zend_error(E_WARNING, "Parameter wasn't passed by reference");
RETURN_NULL();
}
dvalue = (float) (*$input)->value.dval;
$1 = &dvalue;
}
%typemap(in) int *REFERENCE (int dvalue)
{
if(!ParameterPassedByReference(ht, argvi))
{
zend_error(E_WARNING, "Parameter wasn't passed by reference");
RETURN_NULL();
}
dvalue = (int) (*$input)->value.lval;
$1 = &dvalue;
}
%typemap(in) short *REFERENCE (short dvalue)
{
if(!ParameterPassedByReference(ht, argvi))
{
zend_error(E_WARNING, "Parameter wasn't passed by reference");
RETURN_NULL();
}
dvalue = (short) (*$input)->value.lval;
$1 = &dvalue;
}
%typemap(in) long *REFERENCE (long dvalue)
{
if(!ParameterPassedByReference(ht, argvi))
{
zend_error(E_WARNING, "Parameter wasn't passed by reference");
RETURN_NULL();
}
dvalue = (long) (*$input)->value.lval;
$1 = &dvalue;
}
%typemap(in) unsigned int *REFERENCE (unsigned int dvalue)
{
if(!ParameterPassedByReference(ht, argvi))
{
zend_error(E_WARNING, "Parameter wasn't passed by reference");
RETURN_NULL();
}
dvalue = (unsigned int) (*$input)->value.lval;
$1 = &dvalue;
}
%typemap(in) unsigned short *REFERENCE (unsigned short dvalue)
{
if(!ParameterPassedByReference(ht, argvi))
{
zend_error(E_WARNING, "Parameter wasn't passed by reference");
RETURN_NULL();
}
dvalue = (unsigned short) $input->value.lval;
$1 = &dvalue;
}
%typemap(in) unsigned long *REFERENCE (unsigned long dvalue)
{
if(!ParameterPassedByReference(ht, argvi))
{
zend_error(E_WARNING, "Parameter wasn't passed by reference");
RETURN_NULL();
}
dvalue = (unsigned long) $input->value.lval;
$1 = &dvalue;
}
%typemap(argout) double *REFERENCE,
float *REFERENCE
{
$1->value.dval = (double)(*$arg);
$1->type = IS_DOUBLE;
}
%typemap(argout) int *REFERENCE,
short *REFERENCE,
long *REFERENCE,
unsigned int *REFERENCE,
unsigned short *REFERENCE,
unsigned long *REFERENCE
{
(*$arg)->value.lval = (long)(*$input);
(*$arg)->type = IS_LONG;
}

145
SWIG/Lib/php4/utils.i Normal file
View file

@ -0,0 +1,145 @@
// Contains operations useful in php typemaps
// typemaps don't support "subroutine" typemaps where one typemap can
// include another, so we define useful bodies here to include inother places
// _strbuf_out is designed to be included as part of an argout typemap
// and _strbuf_in which should be part of the in typemap for the same argument
// They share knowledge of the "force" temporary variable.
// You probably don't want to make direct use of _strbuf_out or _strbuf_in but
// you may want strbufsize_inout which uses these
%define _strbuf_out(BUFFER,SIZE)
if (force$argnum) { /* pass back arg$argnum through params ($arg) if we can */
if(! PZVAL_IS_REF(*$arg)) {
zend_error(E_WARNING, "Parameter %d of $symname wasn't passed by reference [argout TYPES *, TYPES &]",$argnum-argbase);
} else {
#if SIZE
// SIZE
ZVAL_STRINGL(*$arg,BUFFER$argnum, SIZE, 1);
#else
// Measure length
ZVAL_STRING(*$arg,BUFFER$argnum, 1);
#endif
}
}
%enddef
%define
_strbuf_in(BUFFER)
// _strbuf_in
if(! SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor) < 0) {
/* Using a _p_ SWIG pointer, so they will have to manage size themselves */
force=0;
} else if ((*$input)->type==IS_STRING ||
(*$input)->type==IS_LONG ||
/* Null passed by reference means we want a value back */
(*$input)->type==IS_NULL ||
(*$input)->type==IS_BOOL ||
(*$input)->type==IS_DOUBLE) {
// Only pass back if we can...
if (PZVAL_IS_REF(*$input)) force=1;
else force=0;
convert_to_string_ex($input);
// Init temp buffer
strncpy((char *)temp,Z_STRVAL_PP($input),sizeof(BUFFER));
$1=temp;
} else {
force=0;
$1=NULL;
zend_error(E_ERROR, "Type error in argument %d of $symname. Expected %s or at least something looking vaguely like a string hopefully passed by reference", $argnum-argbase, $1_descriptor->name);
}
%enddef
// strbufsize_inout defines a typemap which
// Example: strbufsize_inout(UCHAR FAR * szErrorMsg, SWORD cbErrorMsgMax,1024)
// defines a typeemap for UCHAR FAR * szErrorMsg, SWORD cbErrorMsgMax with a
// max buffer size of 1024
%define strbufsize_inout(BUFFER,SIZE,MAXSIZE)
%typemap(in) (BUFFER, SIZE) ($*1_ltype temp[MAXSIZE], int force) {
_strbuf_in(temp)
$2=sizeof(temp);
}
%typemap(argout) (BUFFER, SIZE) {
_strbuf_out((char *)temp,strlen(temp))
}
%enddef
// char array can be in/out, though the passed string may not be big enough...
// so we have to size it
// e.g. Do: strarray_inout(char [ANY])
%define strarray_inout(TYPE)
%typemap(in) TYPE ($*1_ltype temp[$1_dim0], int force) %{
_strbuf_in(temp)
%}
%typemap(argout) TYPE %{
_strbuf_out((char *)temp,$1_dim0);
%}
%enddef
%define strarraysize_inout(TYPE,SIZE)
%typemap(in) TYPE ($*1_ltype temp[SIZE], int force) %{
_strbuf_in(temp)
%}
%typemap(argout) TYPE %{
_strbuf_out((char *)temp,SIZE);
%}
%enddef
%define strbuf_inout(BUFFER,MAXSIZE)
%typemap(in) (BUFFER) ($*1_ltype temp[MAXSIZE], int force) {
_strbuf_in(temp)
}
%typemap(argout) (BUFFER) {
_strbuf_out(temp,strlen(temp))
}
%enddef
/* Typemap for in/argout references
NOTE: we don't choose to use these for arrays yet, maybe later */
%define outLONG(ZVALARG,CARG)
ZVAL_LONG(*$arg,intr$argnum);
%enddef
// Defines an on/argout typemap for ordinal types
//Usage: %typemap_inout_ord(bool,convert_to_bool_ex,ZVAL_BOOL)
%define %typemap_inout_ord(TYPES,TYPE_IN,TYPE_OUT)
%typemap(in) TYPES * ($*1_ltype intr, int force),
TYPES & ($*1_ltype intr, int force) %{
/* inout typemap for TYPES using TYPE_IN and TYPE_OUT */
if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor) < 0) {
/* So... we didn't get a ref or ptr, but can it be reasonably
co-erced into what we were looking for a ref of or ptr to? */
if (!PZVAL_IS_REF(*$input) && (*$input)->type==IS_NULL) {
// null passed not by reference means pass NULL
$1 = NULL;
force=0;
} else if (PZVAL_IS_REF(*$input) &&
((*$input)->type==IS_STRING ||
(*$input)->type==IS_LONG ||
/* Null passed by reference means we want a value back */
(*$input)->type==IS_NULL ||
(*$input)->type==IS_BOOL ||
(*$input)->type==IS_DOUBLE)) {
TYPE_IN($input);
intr = ($*1_ltype) (*$input)->value.lval;
$1 = &intr;
/* have to passback arg$arg too */
force=1;
} else { /* wasn't a pre/ref/thing, OR anything like an int thing */
force=0;
zend_error(E_ERROR, "Type error in argument %d of $symname. Expected %s or at least something looking vaguely like a number hopefully passed by reference", $argnum-argbase, $1_descriptor->name);
}
} else force=0;
%}
%typemap(argout) TYPES *, TYPES & %{
if (force$argnum) { /* pass back arg$argnum through params ($arg) if we can */
if(! PZVAL_IS_REF(*$arg)) {
zend_error(E_WARNING, "Parameter %d of $symname wasn't passed by reference [argout TYPES *, TYPES &]",$argnum-argbase);
} else {
TYPE_OUT(*$arg,intr$argnum);
}
}
%}
%enddef