merge from trunk

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@11627 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Baozeng Ding 2009-08-17 16:29:31 +00:00
commit b6b2fce6ae
103 changed files with 893 additions and 786 deletions

View file

@ -262,9 +262,15 @@ SWIGINTERN void SWIG_CSharpException(int code, const char *msg) {
/* rethrow the unknown exception */
#ifdef SWIGCSHARP
%typemap(throws,noblock=1, canthrow=1) (...) {
SWIG_exception(SWIG_RuntimeError,"unknown exception");
}
#else
%typemap(throws,noblock=1) (...) {
SWIG_exception(SWIG_RuntimeError,"unknown exception");
}
#endif
#endif /* __cplusplus */

View file

@ -1,4 +1,26 @@
#if OCTAVE_API_VERSION_OPTION>0
#define USE_OCTAVE_API_VERSION OCTAVE_API_VERSION_OPTION
#else
#include <octave/version.h>
#ifdef OCTAVE_API_VERSION_N
#define USE_OCTAVE_API_VERSION OCTAVE_API_VERSION_N
#else // Interim hack to distinguish between Octave 3.2 and earlier versions.
#define ComplexLU __ignore
#include <octave/CmplxLU.h>
#undef ComplexLU
#ifdef octave_Complex_LU_h
#define USE_OCTAVE_API_VERSION 36
#else
#define USE_OCTAVE_API_VERSION 37
#endif
#endif
#endif
SWIGRUNTIME bool SWIG_check_num_args(const char *func_name, int num_args, int max_args, int min_args, int varargs) {
if (num_args > max_args && !varargs)

View file

@ -32,7 +32,7 @@
#define SWIG_SetConstant(name, obj) SWIG_Octave_SetConstant(module_ns,name,obj)
// raise
#define SWIG_Octave_Raise(obj, type, desc) error("c++-side threw an exception")
#define SWIG_Octave_Raise(OBJ, TYPE, DESC) error("C++ side threw an exception of type " TYPE)
#define SWIG_Raise(obj, type, desc) SWIG_Octave_Raise(obj, type, desc)
// Include the unified typemap library

View file

@ -7,6 +7,9 @@
#ifdef do_close
#undef do_close
#endif
#ifdef do_exec
#undef do_exec
#endif
#ifdef scalar
#undef scalar
#endif

View file

@ -18,6 +18,7 @@
/* for raw pointers */
#define SWIG_ConvertPtr(obj, pp, type, flags) SWIG_Perl_ConvertPtr(SWIG_PERL_OBJECT_CALL obj, pp, type, flags)
#define SWIG_ConvertPtrAndOwn(obj, pp, type, flags,own) SWIG_Perl_ConvertPtrAndOwn(SWIG_PERL_OBJECT_CALL obj, pp, type, flags, own)
#define SWIG_NewPointerObj(p, type, flags) SWIG_Perl_NewPointerObj(SWIG_PERL_OBJECT_CALL p, type, flags)
/* for raw packed data */
@ -234,10 +235,14 @@ SWIG_TypeProxyCheck(const char *c, swig_type_info *ty) {
/* Function for getting a pointer value */
SWIGRUNTIME int
SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *_t, int flags) {
SWIG_Perl_ConvertPtrAndOwn(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *_t, int flags, int *own) {
swig_cast_info *tc;
void *voidptr = (void *)0;
SV *tsv = 0;
if (own)
*own = 0;
/* If magical, apply more magic */
if (SvGMAGICAL(sv))
mg_get(sv);
@ -287,7 +292,11 @@ SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *
{
int newmemory = 0;
*ptr = SWIG_TypeCast(tc,voidptr,&newmemory);
assert(!newmemory); /* newmemory handling not yet implemented */
if (newmemory == SWIG_CAST_NEW_MEMORY) {
assert(own);
if (own)
*own = *own | SWIG_CAST_NEW_MEMORY;
}
}
} else {
*ptr = voidptr;
@ -317,9 +326,14 @@ SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *
return SWIG_OK;
}
SWIGRUNTIME int
SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *_t, int flags) {
return SWIG_Perl_ConvertPtrAndOwn(sv, ptr, _t, flags, 0);
}
SWIGRUNTIME void
SWIG_Perl_MakePtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, swig_type_info *t, int flags) {
if (ptr && (flags & SWIG_SHADOW)) {
if (ptr && (flags & (SWIG_SHADOW | SWIG_POINTER_OWN))) {
SV *self;
SV *obj=newSV(0);
HV *hash=newHV();

View file

@ -64,6 +64,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
@ -112,6 +114,14 @@
}
}
%typemap(in) SWIGTYPE *& ($*ltype temp)
{
if(SWIG_ConvertPtr(*$input, (void **) &temp, $*1_descriptor, 0) < 0) {
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor");
}
$1 = &temp;
}
%typemap(in) SWIGTYPE *DISOWN
{
if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) {
@ -184,6 +194,21 @@
ZVAL_LONG(return_value,$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(directorin) int,
unsigned int,
short,
@ -203,6 +228,11 @@
ZVAL_BOOL(return_value,($1)?1:0);
}
%typemap(out) const bool &
{
ZVAL_BOOL(return_value,(*$1)?1:0);
}
%typemap(directorin) bool
{
ZVAL_BOOL($input,($1_name)?1:0);
@ -214,8 +244,14 @@
ZVAL_DOUBLE(return_value,$1);
}
%typemap(out) const float &,
const double &
{
ZVAL_DOUBLE(return_value,*$1);
}
%typemap(directorin) float,
double
double
{
ZVAL_DOUBLE($input,$1_name);
}
@ -225,6 +261,11 @@
ZVAL_STRINGL(return_value,&$1, 1, 1);
}
%typemap(out) const char &
{
ZVAL_STRINGL(return_value,&*$1, 1, 1);
}
%typemap(out) char *,
char []
{
@ -235,6 +276,15 @@
}
}
%typemap(out) char *&
{
if(!*$1) {
ZVAL_NULL(return_value);
} else {
ZVAL_STRING(return_value, (char *)*$1, 1);
}
}
%typemap(out) SWIGTYPE *,
SWIGTYPE [],
SWIGTYPE &
@ -242,9 +292,14 @@
SWIG_SetPointerZval(return_value, (void *)$1, $1_descriptor, $owner);
%}
%typemap(out) SWIGTYPE *&
%{
SWIG_SetPointerZval(return_value, (void *)*$1, $*1_descriptor, $owner);
%}
%typemap(directorin) SWIGTYPE *,
SWIGTYPE [],
SWIGTYPE &
SWIGTYPE [],
SWIGTYPE &
%{
SWIG_SetPointerZval($input, (void *)&$1_name, $1_descriptor, $owner);
%}
@ -271,17 +326,13 @@
#endif
%typemap(directorin) SWIGTYPE
#ifdef __cplusplus
{
SWIG_SetPointerZval($input, SWIG_as_voidptr(&$1_name), $&1_descriptor, 2);
}
#else
{
$&1_ltype resultobj = ($&1_ltype) emalloc(sizeof($1_type));
memcpy(resultobj, &$1, sizeof($1_type));
SWIG_SetPointerZval($input, (void *)resultobj, $&1_descriptor, 2);
}
#endif
/* Array reference typemaps */
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
%typemap(out) void "";
@ -296,7 +347,7 @@
// an argument to be converted from a different PHP type, you must convert
// it yourself before passing it (e.g. (string)4.7 or (int)"6").
%define %php_typecheck(_type,_prec,is)
%typemap(typecheck,precedence=_prec) _type
%typemap(typecheck,precedence=_prec) _type, const _type &
" $1 = (Z_TYPE_PP($input) == is); "
%enddef
@ -311,13 +362,12 @@
%php_typecheck(size_t,SWIG_TYPECHECK_INT16,IS_LONG)
%php_typecheck(enum SWIGTYPE,SWIG_TYPECHECK_INT8,IS_LONG)
%php_typecheck(bool,SWIG_TYPECHECK_BOOL,IS_BOOL)
%php_typecheck(char,SWIG_TYPECHECK_CHAR,IS_STRING)
%php_typecheck(char *,SWIG_TYPECHECK_STRING,IS_STRING)
%php_typecheck(char [],SWIG_TYPECHECK_STRING,IS_STRING)
%php_typecheck(float,SWIG_TYPECHECK_FLOAT,IS_DOUBLE)
%php_typecheck(double,SWIG_TYPECHECK_BOOL,IS_DOUBLE)
%php_typecheck(char,SWIG_TYPECHECK_CHAR,IS_STRING)
%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) char *, char *&, char []
" $1 = (Z_TYPE_PP($input) == IS_STRING); "
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE
{
@ -327,7 +377,8 @@
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *,
SWIGTYPE [],
SWIGTYPE &
SWIGTYPE &,
SWIGTYPE *&
{
void *tmp;
_v = (SWIG_ConvertPtr(*$input, (void**)&tmp, $1_descriptor, 0) >= 0);

View file

@ -13,7 +13,6 @@
#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
@ -475,6 +474,8 @@ PHPFN(sqrt);
PHPFN(ceil);
PHPFN(floor);
PHPFN(fmod);
PHPFN(min);
PHPFN(max);
#undef PHPKW
#undef PHPBN1

View file

@ -113,8 +113,14 @@ SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject
value->ptr=ptr;
value->newobject=newobject;
if (newobject <= 1) {
/* Just register the pointer as a resource. */
ZEND_REGISTER_RESOURCE(z, value, *(int *)(type->clientdata));
} else {
/*
* Wrap the resource in an object, the resource will be accessible
* via the "_cPtr" member. This is currently only used by
* directorin typemaps.
*/
value->newobject = 0;
zval *resource;
MAKE_STD_ZVAL(resource);

View file

@ -3,132 +3,103 @@
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* 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

@ -33,14 +33,24 @@
%enddef
%define %pass_by_val( TYPE, CONVERT_IN )
%typemap(in) TYPE, const TYPE &
%typemap(in) TYPE
%{
CONVERT_IN($1,$1_ltype,$input);
%}
%typemap(directorout) TYPE, const TYPE &
%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") %{

View file

@ -1163,10 +1163,10 @@ SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) {
/* here we get the method pointer for callbacks */
const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc);
const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0;
if (desc) {
if (desc)
desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0;
if (!desc) return SWIG_ERROR;
}
if (!desc)
return SWIG_ERROR;
if (ty) {
swig_cast_info *tc = SWIG_TypeCheck(desc,ty);
if (tc) {

View file

@ -875,31 +875,8 @@ namespace swig
}
%enddef
// ..I don't think %swig_sequence_methods_val are really used at all anymore...
%define %swig_sequence_methods_val(Sequence...)
%swig_sequence_methods_common(%arg(Sequence))
%extend {
VALUE __getitem__(difference_type i) {
VALUE r = Qnil;
try {
r = swig::from< Sequence::value_type >( *(swig::cgetpos(self, i)) );
}
catch( std::out_of_range )
{
}
return r;
}
VALUE __setitem__(difference_type i, value_type x) {
std::size_t len = $self->size();
if ( i < 0 ) i = len - i;
else if ( static_cast<std::size_t>(i) >= len )
$self->resize( i+1, x );
else *(swig::getpos(self,i)) = x;
return swig::from< Sequence::value_type >( x );
}
}
%swig_sequence_methods(%arg(Sequence))
%enddef