__DIRECTOR__ renamed Swig::Director

SWIG_DIRECTOR_EXCEPTION renamed Swig::DirectorException (similarly for derived classes)


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5138 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2003-09-22 20:13:42 +00:00
commit f569dd135d
20 changed files with 507 additions and 496 deletions

View file

@ -6,64 +6,63 @@
*
* Author : Scott Michel (scottm@aero.org)
*
* N.B.: This file was
adapted from the python director.swg, written by
* This file was adapted from the python director.swg, written by
* Mark Rose (mrose@stm.lbl.gov)
************************************************************************/
#ifdef __cplusplus
/* director base class */
class __DIRECTOR__ {
private:
/* pointer to java virtual machine */
JavaVM *__jvm;
namespace Swig {
/* director base class */
class Director {
private:
/* pointer to java virtual machine */
JavaVM *__jvm;
protected:
/* pointer to the wrapped java object */
jobject __self;
/* Acquire Java VM environment from Java VM */
JNIEnv *__acquire_jenv() const {
JNIEnv *env;
__jvm->AttachCurrentThread((void **) &env, NULL);
return env;
}
protected:
/* pointer to the wrapped java object */
jobject __self;
/* Acquire Java VM environment from Java VM */
JNIEnv *__acquire_jenv() const {
JNIEnv *env;
__jvm->AttachCurrentThread((void **) &env, NULL);
return env;
}
public:
__DIRECTOR__(JNIEnv *jenv):
__jvm((JavaVM *) NULL),
__self(NULL)
{
/* Acquire the Java VM pointer */
jenv->GetJavaVM(&__jvm);
}
public:
Director(JNIEnv *jenv):
__jvm((JavaVM *) NULL),
__self(NULL) {
/* Acquire the Java VM pointer */
jenv->GetJavaVM(&__jvm);
}
/* Remove the Java object global lock at destruction */
virtual ~__DIRECTOR__()
{
if (__self) {
JNIEnv *jenv;
jmethodID disconn_meth;
jenv = __acquire_jenv();
disconn_meth = jenv->GetMethodID(jenv->GetObjectClass(__self), "__director_disconnect", "()V");
if (disconn_meth)
jenv->CallVoidMethod(__self, disconn_meth);
jenv->DeleteGlobalRef(__self);
__self = (jobject) NULL;
}
}
/* Set __self and get Java global reference on object */
inline void __set_self(JNIEnv *jenv, jobject jself)
{
__self = jenv->NewGlobalRef(jself);
}
/* Remove the Java object global lock at destruction */
virtual ~Director() {
if (__self) {
JNIEnv *jenv;
jmethodID disconn_meth;
/* return a pointer to the wrapped java object */
inline jobject __get_self() const
{ return __self; }
};
jenv = __acquire_jenv();
disconn_meth = jenv->GetMethodID(jenv->GetObjectClass(__self), "__director_disconnect", "()V");
if (disconn_meth)
jenv->CallVoidMethod(__self, disconn_meth);
jenv->DeleteGlobalRef(__self);
__self = (jobject) NULL;
}
}
/* Set __self and get Java global reference on object */
inline void __set_self(JNIEnv *jenv, jobject jself) {
__self = jenv->NewGlobalRef(jself);
}
/* return a pointer to the wrapped java object */
inline jobject __get_self() const {
return __self;
}
};
}
#endif /* __cplusplus */

View file

@ -15,125 +15,128 @@
#include <string>
/* simple thread abstraction for pthreads or win32 */
namespace Swig {
/* simple thread abstraction for pthreads on win32 */
#ifdef __THREAD__
#define __PTHREAD__
#if defined(_WIN32) || defined(__WIN32__)
#define pthread_mutex_lock EnterCriticalSection
#define pthread_mutex_unlock LeaveCriticalSection
#define pthread_mutex_t CRITICAL_SECTION
#define MUTEX_INIT(var) CRITICAL_SECTION var
#else
#include <pthread.h>
#define MUTEX_INIT(var) pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER
#endif
#endif
/* director base class */
class __DIRECTOR__ {
private:
/* pointer to the wrapped ocaml object */
CAML_VALUE _self;
/* flag indicating whether the object is owned by ocaml or c++ */
mutable int _disown;
/* shared flag for breaking recursive director calls */
static int _up;
#ifdef __PTHREAD__
/* locks for sharing the _up flag in a threaded environment */
static pthread_mutex_t _mutex_up;
static int _mutex_active;
static pthread_t _mutex_thread;
#endif
/* reset the _up flag once the routing direction has been determined */
#ifdef __PTHREAD__
void __clear_up() const {
__DIRECTOR__::_up = 0;
__DIRECTOR__::_mutex_active = 0;
pthread_mutex_unlock(&_mutex_up);
}
#define __PTHREAD__
#if defined(_WIN32) || defined(__WIN32__)
#define pthread_mutex_lock EnterCriticalSection
#define pthread_mutex_unlock LeaveCriticalSection
#define pthread_mutex_t CRITICAL_SECTION
#define MUTEX_INIT(var) CRITICAL_SECTION var
#else
void __clear_up() const {
__DIRECTOR__::_up = 0;
}
#include <pthread.h>
#define MUTEX_INIT(var) pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER
#endif
#endif
public:
/* wrap a ocaml object, optionally taking ownership */
__DIRECTOR__(CAML_VALUE self, int disown): _self(self), _disown(disown) {
/* director base class */
class Director {
private:
/* pointer to the wrapped ocaml object */
CAML_VALUE _self;
/* flag indicating whether the object is owned by ocaml or c++ */
mutable int _disown;
/* shared flag for breaking recursive director calls */
static int _up;
#ifdef __PTHREAD__
/* locks for sharing the _up flag in a threaded environment */
static pthread_mutex_t _mutex_up;
static int _mutex_active;
static pthread_t _mutex_thread;
#endif
/* reset the _up flag once the routing direction has been determined */
#ifdef __PTHREAD__
void __clear_up() const {
Swig::Director::_up = 0;
Swig::Director::_mutex_active = 0;
pthread_mutex_unlock(&_mutex_up);
}
#else
void __clear_up() const {
Swig::Director::_up = 0;
}
#endif
public:
/* wrap a ocaml object, optionally taking ownership */
Director(CAML_VALUE self, int disown): _self(self), _disown(disown) {
register_global_root(&_self);
}
/* discard our reference at destruction */
virtual ~__DIRECTOR__() {
}
/* discard our reference at destruction */
virtual ~Director() {
remove_global_root(&_self);
__disown();
// Disown is safe here because we're just divorcing a reference that
// points to us.
}
/* return a pointer to the wrapped ocaml object */
CAML_VALUE __get_self() const {
return callback(*caml_named_value("caml_director_get_self"),_self);
}
}
/* get the _up flag to determine if the method call should be routed
* to the c++ base class or through the wrapped ocaml object
*/
/* return a pointer to the wrapped ocaml object */
CAML_VALUE __get_self() const {
return callback(*caml_named_value("caml_director_get_self"),_self);
}
/* get the _up flag to determine if the method call should be routed
* to the c++ base class or through the wrapped ocaml object
*/
#ifdef __PTHREAD__
int __get_up() const {
if (__DIRECTOR__::_mutex_active) {
if (pthread_equal(__DIRECTOR__::_mutex_thread, pthread_self())) {
int up = _up;
__clear_up();
return up;
}
int __get_up() const {
if (Swig::Director::_mutex_active) {
if (pthread_equal(Swig::Director::_mutex_thread, pthread_self())) {
int up = _up;
__clear_up();
return up;
}
}
return 0;
}
}
#else
int __get_up() const {
int __get_up() const {
int up = _up;
_up = 0;
return up;
}
}
#endif
/* set the _up flag if the next method call should be directed to
* the c++ base class rather than the wrapped ocaml object
*/
/* set the _up flag if the next method call should be directed to
* the c++ base class rather than the wrapped ocaml object
*/
#ifdef __PTHREAD__
void __set_up() const {
pthread_mutex_lock(&__DIRECTOR__::_mutex_up);
__DIRECTOR__::_mutex_thread = pthread_self();
__DIRECTOR__::_mutex_active = 1;
__DIRECTOR__::_up = 1;
}
void __set_up() const {
pthread_mutex_lock(&Swig::Director::_mutex_up);
Swig::Director::_mutex_thread = pthread_self();
Swig::Director::_mutex_active = 1;
Swig::Director::_up = 1;
}
#else
void __set_up() const {
__DIRECTOR__::_up = 1;
}
void __set_up() const {
Swig::Director::_up = 1;
}
#endif
/* acquire ownership of the wrapped ocaml object (the sense of "disown"
* is from ocaml) */
void __disown() const {
if (!_disown) {
_disown=1;
callback(*caml_named_value("caml_obj_disown"),_self);
}
}
};
int __DIRECTOR__::_up = 0;
/* acquire ownership of the wrapped ocaml object (the sense of "disown"
* is from ocaml) */
void __disown() const {
if (!_disown) {
_disown=1;
callback(*caml_named_value("caml_obj_disown"),_self);
}
}
};
int Swig::Director::_up = 0;
#ifdef __PTHREAD__
MUTEX_INIT(__DIRECTOR__::_mutex_up);
pthread_t __DIRECTOR__::_mutex_thread;
int __DIRECTOR__::_mutex_active = 0;
MUTEX_INIT(Swig::Director::_mutex_up);
pthread_t Swig::Director::_mutex_thread;
int Swig::Director::_mutex_active = 0;
#endif
}
#endif /* __cplusplus */
%}

View file

@ -43,7 +43,7 @@ namespace std {
if ($input.type == T_STRING)
$result = std::string(STR0($input.u.string));
else
throw SWIG_DIRECTOR_TYPE_MISMATCH("string expected");
throw Swig::DirectorTypeMismatchException("string expected");
}
%typemap(directorout) const string & (std::string temp) {
@ -51,7 +51,7 @@ namespace std {
temp = std::string(STR0($input.u.string));
$result = &temp;
} else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("string expected");
throw Swig::DirectorTypeMismatchException("string expected");
}
}

View file

@ -11,166 +11,168 @@
#include <string>
/* base class for director exceptions */
class SWIG_DIRECTOR_EXCEPTION {
protected:
std::string _msg;
public:
SWIG_DIRECTOR_EXCEPTION(const char* msg="") {
}
const char *getMessage() { return _msg.c_str(); }
virtual ~SWIG_DIRECTOR_EXCEPTION() { }
};
namespace Swig {
/* base class for director exceptions */
class DirectorException {
protected:
std::string _msg;
public:
DirectorException(const char* msg="") {
}
const char *getMessage() {
return _msg.c_str();
}
virtual ~DirectorException() {}
};
/* type mismatch in the return value from a python method call */
class SWIG_DIRECTOR_TYPE_MISMATCH: public SWIG_DIRECTOR_EXCEPTION {
public:
SWIG_DIRECTOR_TYPE_MISMATCH(const char* msg="") {
_msg = "Swig director type mismatch: ";
_msg += msg;
PyErr_SetString(PyExc_TypeError, msg);
}
};
/* type mismatch in the return value from a python method call */
class DirectorTypeMismatchException : public Swig::DirectorException {
public:
DirectorTypeMismatchException(const char* msg="") {
_msg = "Swig director type mismatch: ";
_msg += msg;
PyErr_SetString(PyExc_TypeError, msg);
}
};
/* any python exception that occurs during a director method call */
class SWIG_DIRECTOR_METHOD_EXCEPTION: public SWIG_DIRECTOR_EXCEPTION { };
/* any python exception that occurs during a director method call */
class DirectorMethodException : public Swig::DirectorException {};
/* attempt to call a pure virtual method via a director method */
class SWIG_DIRECTOR_PURE_VIRTUAL_EXCEPTION: public SWIG_DIRECTOR_EXCEPTION { };
/* attempt to call a pure virtual method via a director method */
class DirectorPureVirtualException : public Swig::DirectorException {};
/* simple thread abstraction for pthreads or win32 */
/* simple thread abstraction for pthreads on win32 */
#ifdef __THREAD__
#define __PTHREAD__
#if defined(_WIN32) || defined(__WIN32__)
#define pthread_mutex_lock EnterCriticalSection
#define pthread_mutex_unlock LeaveCriticalSection
#define pthread_mutex_t CRITICAL_SECTION
#define MUTEX_INIT(var) CRITICAL_SECTION var
#else
#include <pthread.h>
#define MUTEX_INIT(var) pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER
#endif
#endif
/* director base class */
class __DIRECTOR__ {
private:
/* pointer to the wrapped python object */
PyObject* _self;
/* flag indicating whether the object is owned by python or c++ */
mutable int _disown;
/* shared flag for breaking recursive director calls */
static int _up;
#ifdef __PTHREAD__
/* locks for sharing the _up flag in a threaded environment */
static pthread_mutex_t _mutex_up;
static int _mutex_active;
static pthread_t _mutex_thread;
#endif
/* decrement the reference count of the wrapped python object */
void __decref() const {
if (_disown) {
Py_DECREF(_self);
}
}
/* reset the _up flag once the routing direction has been determined */
#ifdef __PTHREAD__
void __clear_up() const {
__DIRECTOR__::_up = 0;
__DIRECTOR__::_mutex_active = 0;
pthread_mutex_unlock(&_mutex_up);
}
#define __PTHREAD__
#if defined(_WIN32) || defined(__WIN32__)
#define pthread_mutex_lock EnterCriticalSection
#define pthread_mutex_unlock LeaveCriticalSection
#define pthread_mutex_t CRITICAL_SECTION
#define MUTEX_INIT(var) CRITICAL_SECTION var
#else
void __clear_up() const {
__DIRECTOR__::_up = 0;
}
#include <pthread.h>
#define MUTEX_INIT(var) pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER
#endif
#endif
public:
/* wrap a python object, optionally taking ownership */
__DIRECTOR__(PyObject* self, int disown): _self(self), _disown(disown) {
__incref();
}
/* discard our reference at destruction */
virtual ~__DIRECTOR__() {
__decref();
}
/* return a pointer to the wrapped python object */
PyObject *__get_self() const {
return _self;
}
/* director base class */
class Director {
private:
/* pointer to the wrapped python object */
PyObject* _self;
/* flag indicating whether the object is owned by python or c++ */
mutable int _disown;
/* shared flag for breaking recursive director calls */
static int _up;
/* get the _up flag to determine if the method call should be routed
* to the c++ base class or through the wrapped python object
*/
#ifdef __PTHREAD__
int __get_up() const {
if (__DIRECTOR__::_mutex_active) {
if (pthread_equal(__DIRECTOR__::_mutex_thread, pthread_self())) {
/* locks for sharing the _up flag in a threaded environment */
static pthread_mutex_t _mutex_up;
static int _mutex_active;
static pthread_t _mutex_thread;
#endif
/* decrement the reference count of the wrapped python object */
void __decref() const {
if (_disown) {
Py_DECREF(_self);
}
}
/* reset the _up flag once the routing direction has been determined */
#ifdef __PTHREAD__
void __clear_up() const {
Swig::Director::_up = 0;
Swig::Director::_mutex_active = 0;
pthread_mutex_unlock(&_mutex_up);
}
#else
void __clear_up() const {
Swig::Director::_up = 0;
}
#endif
public:
/* wrap a python object, optionally taking ownership */
Director(PyObject* self, int disown): _self(self), _disown(disown) {
__incref();
}
/* discard our reference at destruction */
virtual ~Director() {
__decref();
}
/* return a pointer to the wrapped python object */
PyObject *__get_self() const {
return _self;
}
/* get the _up flag to determine if the method call should be routed
* to the c++ base class or through the wrapped python object
*/
#ifdef __PTHREAD__
int __get_up() const {
if (Swig::Director::_mutex_active) {
if (pthread_equal(Swig::Director::_mutex_thread, pthread_self())) {
int up = _up;
__clear_up();
return up;
}
}
return 0;
}
#else
int __get_up() const {
int up = _up;
__clear_up();
_up = 0;
return up;
}
}
return 0;
}
#else
int __get_up() const {
int up = _up;
_up = 0;
return up;
}
#endif
/* set the _up flag if the next method call should be directed to
* the c++ base class rather than the wrapped python object
*/
#ifdef __PTHREAD__
void __set_up() const {
pthread_mutex_lock(&__DIRECTOR__::_mutex_up);
__DIRECTOR__::_mutex_thread = pthread_self();
__DIRECTOR__::_mutex_active = 1;
__DIRECTOR__::_up = 1;
}
#else
void __set_up() const {
__DIRECTOR__::_up = 1;
}
#endif
/* acquire ownership of the wrapped python object (the sense of "disown"
* is from python) */
void __disown() const {
if (!_disown) {
_disown=1;
__incref();
}
}
/* set the _up flag if the next method call should be directed to
* the c++ base class rather than the wrapped python object
*/
#ifdef __PTHREAD__
void __set_up() const {
pthread_mutex_lock(&Swig::Director::_mutex_up);
Swig::Director::_mutex_thread = pthread_self();
Swig::Director::_mutex_active = 1;
Swig::Director::_up = 1;
}
#else
void __set_up() const {
Swig::Director::_up = 1;
}
#endif
/* increase the reference count of the wrapped python object */
void __incref() const {
if (_disown) {
Py_INCREF(_self);
}
}
/* acquire ownership of the wrapped python object (the sense of "disown"
* is from python) */
void __disown() const {
if (!_disown) {
_disown=1;
__incref();
}
}
};
/* increase the reference count of the wrapped python object */
void __incref() const {
if (_disown) {
Py_INCREF(_self);
}
}
namespace {
int __DIRECTOR__::_up = 0;
};
int Swig::Director::_up = 0;
#ifdef __PTHREAD__
MUTEX_INIT(__DIRECTOR__::_mutex_up);
pthread_t __DIRECTOR__::_mutex_thread;
int __DIRECTOR__::_mutex_active = 0;
MUTEX_INIT(Swig::Director::_mutex_up);
pthread_t Swig::Director::_mutex_thread;
int Swig::Director::_mutex_active = 0;
#endif
}

View file

@ -467,7 +467,7 @@
/* no can do... see python.cxx
%typemap(directorin) DIRECTORTYPE * {
{
__DIRECTOR__$1_ltype proxy = dynamic_cast<__DIRECTOR__$1_ltype>($1_name);
SwigDirector::$1_ltype proxy = dynamic_cast<SwigDirector::$1_ltype>($1_name);
if (!proxy) {
$input = SWIG_NewPointerObj((void *) $1_name, $1_descriptor, 0);
} else {
@ -493,10 +493,10 @@
%define DIRECTOROUT_TYPEMAP(type, converter)
%typemap(directorargout) type *DIRECTOROUT
"*$result = (type) converter($input);
if (PyErr_Occurred()) throw SWIG_DIRECTOR_TYPE_MISMATCH(\"Error converting Python object using converter\");";
if (PyErr_Occurred()) throw Swig::DirectorTypeMismatchException(\"Error converting Python object using converter\");";
%typemap(directorout) type
"$result = (type) converter($input);
if (PyErr_Occurred()) throw SWIG_DIRECTOR_TYPE_MISMATCH(\"Error converting Python object using converter\");";
if (PyErr_Occurred()) throw Swig::DirectorTypeMismatchException(\"Error converting Python object using converter\");";
%typemap(directorout) type &DIRECTOROUT = type
%enddef
@ -519,14 +519,14 @@ DIRECTOROUT_TYPEMAP(std::size_t, PyInt_AsLong);
/* Object returned by value. Convert from a pointer */
%typemap(directorout) SWIGTYPE ($&ltype argp)
"if ((SWIG_ConvertPtr($input,(void **) &argp, $&descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1) throw SWIG_DIRECTOR_TYPE_MISMATCH(\"Pointer conversion failed.\"); $result = *argp;";
"if ((SWIG_ConvertPtr($input,(void **) &argp, $&descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1) throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\"); $result = *argp;";
%typemap(directorout) SWIGTYPE *,
SWIGTYPE &,
SWIGTYPE []
"if ((SWIG_ConvertPtr($input,(void **) &$result, $descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1) throw SWIG_DIRECTOR_TYPE_MISMATCH(\"Pointer conversion failed.\");";
"if ((SWIG_ConvertPtr($input,(void **) &$result, $descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1) throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\");";
%typemap(directorout) void * "if ((SWIG_ConvertPtr($input,(void **) &$result, 0, SWIG_POINTER_EXCEPTION | $disown )) == -1) throw SWIG_DIRECTOR_TYPE_MISMATCH(\"Pointer conversion failed.\");";
%typemap(directorout) void * "if ((SWIG_ConvertPtr($input,(void **) &$result, 0, SWIG_POINTER_EXCEPTION | $disown )) == -1) throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\");";

View file

@ -78,14 +78,14 @@ SwigComplex_AsComplexDouble(PyObject *o)
%typemap(directorout) Complex {
$result = SwigComplex_As< Complex >($input);
if (PyErr_Occurred()) {
throw SWIG_DIRECTOR_TYPE_MISMATCH("Expecting a complex or compatible type");
throw Swig::DirectorTypeMismatchException("Expecting a complex or compatible type");
}
}
%typemap(directorout) const complex<T>& (Complex temp) {
temp = SwigComplex_As< Complex >($input);
if (PyErr_Occurred()) {
throw SWIG_DIRECTOR_TYPE_MISMATCH("Expecting a complex or compatible type");
throw Swig::DirectorTypeMismatchException("Expecting a complex or compatible type");
}
$result = &temp;
}

View file

@ -62,7 +62,7 @@ namespace std {
$result = std::string(PyString_AsString($input),
PyString_Size($input));
else
throw SWIG_DIRECTOR_TYPE_MISMATCH("string expected");
throw Swig::DirectorTypeMismatchException("string expected");
}
%typemap(directorout) const string & (std::string temp) {
@ -71,7 +71,7 @@ namespace std {
PyString_Size($input));
$result = &temp;
} else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("string expected");
throw Swig::DirectorTypeMismatchException("string expected");
}
}

View file

@ -121,15 +121,14 @@ namespace std {
Py_DECREF(o);
} else {
Py_DECREF(o);
throw SWIG_DIRECTOR_TYPE_MISMATCH(
"vector<" #T "> expected");
throw Swig::DirectorTypeMismatchException("vector<" #T "> expected");
}
}
} else if (SWIG_ConvertPtr($input,(void **) &v,
$&descriptor,1) != -1){
$result = *v;
} else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "> expected");
throw Swig::DirectorTypeMismatchException("vector<" #T "> expected");
}
}
%typemap(in) const vector<T>& (std::vector<T> temp,
@ -183,14 +182,14 @@ namespace std {
Py_DECREF(o);
} else {
Py_DECREF(o);
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "> expected");
throw Swig::DirectorTypeMismatchException("vector<" #T "> expected");
}
}
} else if (SWIG_ConvertPtr($input,(void **) &v,
$descriptor,1) != -1){
$result = v;
} else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "> expected");
throw Swig::DirectorTypeMismatchException("vector<" #T "> expected");
}
}
%typemap(out) vector<T> {
@ -403,14 +402,14 @@ namespace std {
Py_DECREF(o);
} else {
Py_DECREF(o);
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "*> expected");
throw Swig::DirectorTypeMismatchException("vector<" #T "*> expected");
}
}
} else if (SWIG_ConvertPtr($input,(void **) &v,
$&descriptor,1) != -1){
$result = *v;
} else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "*> expected");
throw Swig::DirectorTypeMismatchException("vector<" #T "*> expected");
}
}
%typemap(in) const vector<T*>& (std::vector<T*> temp,
@ -464,14 +463,14 @@ namespace std {
Py_DECREF(o);
} else {
Py_DECREF(o);
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "*> expected");
throw Swig::DirectorTypeMismatchException("vector<" #T "*> expected");
}
}
} else if (SWIG_ConvertPtr($input,(void **) &v,
$descriptor,1) != -1){
$result = v;
} else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "*> expected");
throw Swig::DirectorTypeMismatchException("vector<" #T "*> expected");
}
}
%typemap(out) vector<T*> {
@ -678,14 +677,14 @@ namespace std {
Py_DECREF(o);
} else {
Py_DECREF(o);
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "> expected");
throw Swig::DirectorTypeMismatchException("vector<" #T "> expected");
}
}
} else if (SWIG_ConvertPtr($input,(void **) &v,
$&descriptor,1) != -1){
$result = *v;
} else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "> expected");
throw Swig::DirectorTypeMismatchException("vector<" #T "> expected");
}
}
%typemap(in) const vector<T>& (std::vector<T> temp,
@ -735,14 +734,14 @@ namespace std {
Py_DECREF(o);
} else {
Py_DECREF(o);
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "> expected");
throw Swig::DirectorTypeMismatchException("vector<" #T "> expected");
}
}
} else if (SWIG_ConvertPtr($input,(void **) &v,
$descriptor,1) != -1){
$result = v;
} else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "> expected");
throw Swig::DirectorTypeMismatchException("vector<" #T "> expected");
}
}
%typemap(out) vector<T> {

View file

@ -13,160 +13,166 @@
#include <string>
struct swig_body_args
{
VALUE recv;
ID id;
int argc;
VALUE *argv;
};
namespace Swig {
struct body_args {
VALUE recv;
ID id;
int argc;
VALUE *argv;
};
/* Base class for director exceptions */
class SWIG_DIRECTOR_EXCEPTION {
protected:
VALUE _error;
protected:
SWIG_DIRECTOR_EXCEPTION(VALUE error=Qnil) : _error(error) {}
public:
VALUE getType() const { return CLASS_OF(_error); }
VALUE getError() const { return _error; }
virtual ~SWIG_DIRECTOR_EXCEPTION() {}
};
/* Base class for director exceptions */
class DirectorException {
protected:
VALUE _error;
protected:
DirectorException(VALUE error=Qnil) : _error(error) {}
public:
VALUE getType() const {
return CLASS_OF(_error);
}
VALUE getError() const {
return _error;
}
virtual ~DirectorException() {}
};
/* Type mismatch in the return value from a Ruby method call */
class SWIG_DIRECTOR_TYPE_MISMATCH : public SWIG_DIRECTOR_EXCEPTION {
public:
SWIG_DIRECTOR_TYPE_MISMATCH(const char *msg="") {
VALUE str = rb_str_new2("Swig director type mismatch: ");
rb_str_concat(str, rb_str_new2(msg));
_error = rb_exc_new3(rb_eTypeError, str);
}
};
/* Type mismatch in the return value from a Ruby method call */
class DirectorTypeMismatchException : public Swig::DirectorException {
public:
DirectorTypeMismatchException(const char *msg="") {
VALUE str = rb_str_new2("Swig director type mismatch: ");
rb_str_concat(str, rb_str_new2(msg));
_error = rb_exc_new3(rb_eTypeError, str);
}
};
/* Any Ruby exception that occurs during a director method call */
class SWIG_DIRECTOR_METHOD_EXCEPTION : public SWIG_DIRECTOR_EXCEPTION {
public:
SWIG_DIRECTOR_METHOD_EXCEPTION(VALUE error) :SWIG_DIRECTOR_EXCEPTION(error) {}
};
/* Any Ruby exception that occurs during a director method call */
class DirectorMethodException : public Swig::DirectorException {
public:
DirectorMethodException(VALUE error) : Swig::DirectorException(error) {}
};
/* Attempted to call a pure virtual method via a director method */
class SWIG_DIRECTOR_PURE_VIRTUAL_EXCEPTION : public SWIG_DIRECTOR_EXCEPTION {};
/* Attempted to call a pure virtual method via a director method */
class DirectorPureVirtualException : public Swig::DirectorException {};
/* Simple thread abstraction for pthreads or win32 */
/* Simple thread abstraction for pthreads on win32 */
#ifdef __THREAD__
#define __PTHREAD__
#if defined(_WIN32) || defined(__WIN32__)
#define pthread_mutex_lock EnterCriticalSection
#define pthread_mutex_unlock LeaveCriticalSection
#define pthread_mutex_t CRITICAL_SECTION
#define MUTEX_INIT(var) CRITICAL_SECTION var
#else
#include <pthread.h>
#define MUTEX_INIT(var) pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER
#endif
#endif
/* director base class */
class __DIRECTOR__ {
private:
/* pointer to the wrapped Ruby object */
VALUE _self;
/* flag indicating whether the object is owned by Ruby or c++ */
mutable bool _disown;
/* shared flag for breaking recursive director calls */
static bool _up;
#ifdef __PTHREAD__
/* locks for sharing the _up flag in a threaded environment */
static pthread_mutex_t _mutex_up;
static bool _mutex_active;
static pthread_t _mutex_thread;
#endif
/* reset the _up flag once the routing direction has been determined */
#ifdef __PTHREAD__
void __clear_up() const {
__DIRECTOR__::_up = false;
__DIRECTOR__::_mutex_active = false;
pthread_mutex_unlock(&_mutex_up);
}
#define __PTHREAD__
#if defined(_WIN32) || defined(__WIN32__)
#define pthread_mutex_lock EnterCriticalSection
#define pthread_mutex_unlock LeaveCriticalSection
#define pthread_mutex_t CRITICAL_SECTION
#define MUTEX_INIT(var) CRITICAL_SECTION var
#else
void __clear_up() const {
__DIRECTOR__::_up = false;
}
#include <pthread.h>
#define MUTEX_INIT(var) pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER
#endif
#endif
public:
/* wrap a Ruby object, optionally taking ownership */
__DIRECTOR__(VALUE self, bool disown) : _self(self), _disown(disown) {
}
/* director base class */
class Director {
private:
/* pointer to the wrapped Ruby object */
VALUE _self;
/* flag indicating whether the object is owned by Ruby or c++ */
mutable bool _disown;
/* shared flag for breaking recursive director calls */
static bool _up;
/* discard our reference at destruction */
virtual ~__DIRECTOR__() {
}
/* return a pointer to the wrapped Ruby object */
VALUE __get_self() const {
return _self;
}
/* get the _up flag to determine if the method call should be routed
* to the c++ base class or through the wrapped Ruby object
*/
#ifdef __PTHREAD__
bool __get_up() const {
if (__DIRECTOR__::_mutex_active) {
if (pthread_equal(__DIRECTOR__::_mutex_thread, pthread_self())) {
/* locks for sharing the _up flag in a threaded environment */
static pthread_mutex_t _mutex_up;
static bool _mutex_active;
static pthread_t _mutex_thread;
#endif
/* reset the _up flag once the routing direction has been determined */
#ifdef __PTHREAD__
void __clear_up() const {
Swig::Director::_up = false;
Swig::Director::_mutex_active = false;
pthread_mutex_unlock(&_mutex_up);
}
#else
void __clear_up() const {
Swig::Director::_up = false;
}
#endif
public:
/* wrap a Ruby object, optionally taking ownership */
Director(VALUE self, bool disown) : _self(self), _disown(disown) {
}
/* discard our reference at destruction */
virtual ~Director() {
}
/* return a pointer to the wrapped Ruby object */
VALUE __get_self() const {
return _self;
}
/* get the _up flag to determine if the method call should be routed
* to the c++ base class or through the wrapped Ruby object
*/
#ifdef __PTHREAD__
bool __get_up() const {
if (Swig::Director::_mutex_active) {
if (pthread_equal(Swig::Director::_mutex_thread, pthread_self())) {
bool up = _up;
__clear_up();
return up;
}
}
return false;
}
#else
bool __get_up() const {
bool up = _up;
__clear_up();
_up = false;
return up;
}
}
return false;
}
#else
bool __get_up() const {
bool up = _up;
_up = false;
return up;
}
#endif
/* set the _up flag if the next method call should be directed to
* the c++ base class rather than the wrapped Ruby object
*/
/* set the _up flag if the next method call should be directed to
* the c++ base class rather than the wrapped Ruby object
*/
#ifdef __PTHREAD__
void __set_up() const {
pthread_mutex_lock(&__DIRECTOR__::_mutex_up);
__DIRECTOR__::_mutex_thread = pthread_self();
__DIRECTOR__::_mutex_active = true;
__DIRECTOR__::_up = true;
}
void __set_up() const {
pthread_mutex_lock(&Swig::Director::_mutex_up);
Swig::Director::_mutex_thread = pthread_self();
Swig::Director::_mutex_active = true;
Swig::Director::_up = true;
}
#else
void __set_up() const {
__DIRECTOR__::_up = true;
}
void __set_up() const {
Swig::Director::_up = true;
}
#endif
/* acquire ownership of the wrapped Ruby object (the sense of "disown"
* is from Ruby) */
void __disown() const {
if (!_disown) {
_disown = true;
}
}
};
/* acquire ownership of the wrapped Ruby object (the sense of "disown"
* is from Ruby) */
void __disown() const {
if (!_disown) {
_disown = true;
}
}
};
bool __DIRECTOR__::_up = false;
bool Swig::Director::_up = false;
#ifdef __PTHREAD__
MUTEX_INIT(__DIRECTOR__::_mutex_up);
pthread_t __DIRECTOR__::_mutex_thread;
int __DIRECTOR__::_mutex_active = false;
MUTEX_INIT(Swig::Director::_mutex_up);
pthread_t Swig::Director::_mutex_thread;
int Swig::Director::_mutex_active = false;
#endif
}
#endif /* __cplusplus */

View file

@ -425,7 +425,7 @@
/* no can do... see python.cxx
%typemap(directorin) DIRECTORTYPE * {
{
__DIRECTOR__$1_ltype proxy = dynamic_cast<__DIRECTOR__$1_ltype>($1_name);
SwigDirector::$1_ltype proxy = dynamic_cast<SwigDirector::$1_ltype>($1_name);
if (!proxy) {
$input = SWIG_NewPointerObj((void *) $1_name, $1_descriptor, 0);
} else {
@ -474,9 +474,9 @@ DIRECTOROUT_TYPEMAP(bool, RTEST);
%typemap(directorout) SWIGTYPE *,
SWIGTYPE &,
SWIGTYPE []
"if ((SWIG_ConvertPtr($input,(void **) &$result, $descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1) throw SWIG_DIRECTOR_TYPE_MISMATCH(\"Pointer conversion failed.\");";
"if ((SWIG_ConvertPtr($input,(void **) &$result, $descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1) throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\");";
%typemap(directorout) void * "if ((SWIG_ConvertPtr($input,(void **) &$result, 0, SWIG_POINTER_EXCEPTION | $disown )) == -1) throw SWIG_DIRECTOR_TYPE_MISMATCH(\"Pointer conversion failed.\");";
%typemap(directorout) void * "if ((SWIG_ConvertPtr($input,(void **) &$result, 0, SWIG_POINTER_EXCEPTION | $disown )) == -1) throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\");";
/* ---------------------------------------------------------------------
* typedef & typemaps for VALUE (passed through unmodified and unchecked)

View file

@ -62,7 +62,7 @@ namespace std {
if (TYPE($input) == T_STRING)
$result = std::string(StringValuePtr($input));
else
throw SWIG_DIRECTOR_TYPE_MISMATCH("string expected");
throw Swig::DirectorTypeMismatchException("string expected");
}
%typemap(directorout) const string & (std::string temp) {
@ -70,7 +70,7 @@ namespace std {
temp = std::string(StringValuePtr($input));
$result = &temp;
} else {
throw SWIG_DIRECTOR_TYPE_MISMATCH("string expected");
throw Swig::DirectorTypeMismatchException("string expected");
}
}