merge revisions 11877-12162 from trunk to gsoc2009-matevz
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@12164 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
commit
25ff4e4927
563 changed files with 22912 additions and 17189 deletions
|
|
@ -103,19 +103,19 @@ namespace Swig {
|
|||
class Director {
|
||||
protected:
|
||||
zval *swig_self;
|
||||
typedef std::map<void*, GCItem_var> ownership_map;
|
||||
mutable ownership_map owner;
|
||||
typedef std::map<void*, GCItem_var> swig_ownership_map;
|
||||
mutable swig_ownership_map swig_owner;
|
||||
public:
|
||||
Director(zval* self) : swig_self(self) {
|
||||
}
|
||||
|
||||
~Director() {
|
||||
for (ownership_map::iterator i = owner.begin(); i != owner.end(); i++) {
|
||||
owner.erase(i);
|
||||
for (swig_ownership_map::iterator i = swig_owner.begin(); i != swig_owner.end(); i++) {
|
||||
swig_owner.erase(i);
|
||||
}
|
||||
}
|
||||
|
||||
bool is_overriden_method(char *cname, char *lc_fname) {
|
||||
bool swig_is_overridden_method(char *cname, char *lc_fname) {
|
||||
zval classname;
|
||||
zend_class_entry **ce;
|
||||
zend_function *mptr;
|
||||
|
|
@ -136,7 +136,7 @@ namespace Swig {
|
|||
void swig_acquire_ownership(Type *vptr) const
|
||||
{
|
||||
if (vptr) {
|
||||
owner[vptr] = new GCItem_T<Type>(vptr);
|
||||
swig_owner[vptr] = new GCItem_T<Type>(vptr);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -96,19 +96,19 @@
|
|||
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) SWIGTYPE (CLASS::*)
|
||||
%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, le_member_ptr);
|
||||
ZEND_REGISTER_RESOURCE(resource, p, swig_member_ptr);
|
||||
zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&resource, sizeof(zval *), NULL);
|
||||
}
|
||||
|
||||
|
|
@ -223,12 +223,12 @@
|
|||
$1 = ($1_ltype)_temp;
|
||||
}
|
||||
|
||||
%typemap(varin) SWIGTYPE (CLASS::*)
|
||||
%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, le_member_ptr);
|
||||
void * p = (void*)zend_fetch_resource(*z_var TSRMLS_CC, -1, SWIG_MEMBER_PTR, NULL, 1, swig_member_ptr);
|
||||
memcpy(&$1, p, sizeof($1));
|
||||
}
|
||||
|
||||
|
|
@ -344,12 +344,12 @@ deliberate error cos this code looks bogus to me
|
|||
SWIG_SetPointerZval(*z_var, (void*)$1, $1_descriptor, 0);
|
||||
}
|
||||
|
||||
%typemap(varout) SWIGTYPE (CLASS::*)
|
||||
%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, le_member_ptr);
|
||||
ZEND_REGISTER_RESOURCE(resource, p, swig_member_ptr);
|
||||
zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&resource, sizeof(zval *), NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,12 +115,12 @@
|
|||
}
|
||||
}
|
||||
|
||||
%typemap(in) SWIGTYPE *& ($*ltype temp)
|
||||
%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 = &temp;
|
||||
$1 = ($1_ltype)&temp;
|
||||
}
|
||||
|
||||
%typemap(in) SWIGTYPE *DISOWN
|
||||
|
|
@ -339,7 +339,7 @@
|
|||
SWIG_SetPointerZval(return_value, (void *)$1, $1_descriptor, $owner);
|
||||
%}
|
||||
|
||||
%typemap(out) SWIGTYPE *&
|
||||
%typemap(out) SWIGTYPE *const&
|
||||
%{
|
||||
SWIG_SetPointerZval(return_value, (void *)*$1, $*1_descriptor, $owner);
|
||||
%}
|
||||
|
|
@ -351,20 +351,20 @@
|
|||
SWIG_SetPointerZval($input, (void *)&$1_name, $1_descriptor, $owner);
|
||||
%}
|
||||
|
||||
%typemap(out) SWIGTYPE (CLASS::*)
|
||||
%typemap(out, 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, le_member_ptr);
|
||||
ZEND_REGISTER_RESOURCE(resource, p, swig_member_ptr);
|
||||
|
||||
SWIG_SetPointerZval(return_value, (void *)&$1, $1_descriptor, $owner);
|
||||
}
|
||||
|
||||
%typemap(in) SWIGTYPE (CLASS::*)
|
||||
%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, le_member_ptr);
|
||||
void * p = (void*)zend_fetch_resource($input TSRMLS_CC, -1, SWIG_MEMBER_PTR, NULL, 1, swig_member_ptr);
|
||||
memcpy(&$1, p, sizeof($1));
|
||||
}
|
||||
|
||||
|
|
@ -394,10 +394,6 @@
|
|||
SWIG_SetPointerZval($input, SWIG_as_voidptr(&$1_name), $&1_descriptor, 2);
|
||||
}
|
||||
|
||||
/* Array reference typemaps */
|
||||
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
|
||||
|
||||
|
||||
%typemap(out) void "";
|
||||
|
||||
%typemap(out) char [ANY]
|
||||
|
|
@ -441,10 +437,11 @@
|
|||
_v = (SWIG_ConvertPtr(*$input, (void **)&tmp, $&1_descriptor, 0) >= 0);
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *,
|
||||
%typecheck(SWIG_TYPECHECK_POINTER)
|
||||
SWIGTYPE *,
|
||||
SWIGTYPE [],
|
||||
SWIGTYPE &,
|
||||
SWIGTYPE *&
|
||||
SWIGTYPE *const&
|
||||
{
|
||||
void *tmp;
|
||||
_v = (SWIG_ConvertPtr(*$input, (void**)&tmp, $1_descriptor, 0) >= 0);
|
||||
|
|
@ -464,20 +461,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>
|
||||
|
|
|
|||
|
|
@ -8,6 +8,18 @@
|
|||
%init %{
|
||||
SWIG_php_minit {
|
||||
SWIG_InitializeModule(0);
|
||||
le_member_ptr = zend_register_list_destructors_ex(member_ptr_dtor, NULL, SWIG_MEMBER_PTR, module_number);
|
||||
%}
|
||||
|
||||
%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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ extern "C" {
|
|||
#endif
|
||||
#include "zend.h"
|
||||
#include "zend_API.h"
|
||||
#include "zend_exceptions.h"
|
||||
#include "php.h"
|
||||
#include "ext/standard/php_string.h"
|
||||
|
||||
|
|
@ -23,11 +24,11 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#ifndef Z_SET_ISREF_P
|
||||
// For PHP < 5.3
|
||||
/* For PHP < 5.3 */
|
||||
# define Z_SET_ISREF_P(z) (z)->is_ref = 1
|
||||
#endif
|
||||
#ifndef Z_SET_REFCOUNT_P
|
||||
// For PHP < 5.3
|
||||
/* For PHP < 5.3 */
|
||||
# define Z_SET_REFCOUNT_P(z, rc) (z)->refcount = (rc)
|
||||
#endif
|
||||
|
||||
|
|
@ -258,12 +259,3 @@ static void SWIG_Php_SetModule(swig_module_info *pointer) {
|
|||
TSRMLS_FETCH();
|
||||
REGISTER_MAIN_LONG_CONSTANT(const_name, (long) pointer, 0);
|
||||
}
|
||||
|
||||
#define SWIG_MEMBER_PTR ((char*)"CLASS::*")
|
||||
|
||||
static void member_ptr_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
|
||||
efree(rsrc->ptr);
|
||||
}
|
||||
|
||||
static int le_member_ptr;
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace std {
|
|||
unsigned int size() 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;
|
||||
|
|
@ -56,125 +56,17 @@ namespace std {
|
|||
}
|
||||
};
|
||||
|
||||
// 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
|
||||
|
||||
// specializations for built-ins
|
||||
%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
|
||||
|
||||
%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;
|
||||
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;
|
||||
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();
|
||||
}
|
||||
bool is_empty() const {
|
||||
return self->empty();
|
||||
}
|
||||
}
|
||||
};
|
||||
%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;
|
||||
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();
|
||||
}
|
||||
bool is_empty() const {
|
||||
return self->empty();
|
||||
}
|
||||
}
|
||||
};
|
||||
%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
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 %{
|
||||
|
|
@ -37,15 +37,11 @@ namespace std {
|
|||
$result.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
|
||||
%}
|
||||
|
||||
%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) const string& %{
|
||||
$1 = ( Z_TYPE_PP($input) == IS_STRING ) ? 1 : 0;
|
||||
%}
|
||||
|
||||
%typemap(out) string %{
|
||||
ZVAL_STRINGL($result, const_cast<char*>($1.data()), $1.size(), 1);
|
||||
%}
|
||||
|
||||
%typemap(directorin) string %{
|
||||
%typemap(directorin) string, const string& %{
|
||||
ZVAL_STRINGL($input, const_cast<char*>($1_name.data()), $1_name.size(), 1);
|
||||
%}
|
||||
|
||||
|
|
@ -53,12 +49,9 @@ namespace std {
|
|||
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
|
||||
|
|
@ -71,8 +64,7 @@ namespace std {
|
|||
|
||||
%typemap(directorout) string & (std::string *temp) %{
|
||||
convert_to_string_ex($input);
|
||||
temp = new std::string;
|
||||
temp->assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
|
||||
temp = new std::string(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
|
||||
swig_acquire_ownership(temp);
|
||||
$result = temp;
|
||||
%}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue