- explicitcall feature removed.

- Instead of using the swig_up flag in each director method (Python, Ruby, Ocaml) to indicate
whether the explicit C++ call to the appropriate base class method or a normal
polymorphic C++ call should be made, the new approach makes one of these calls
directly from the wrapper method.
- Java/C# recursive director method calls fixed (no need for explicitcall feature to solve this now)


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9272 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2006-09-13 20:45:31 +00:00
commit 949e220630
5 changed files with 28 additions and 241 deletions

View file

@ -61,32 +61,10 @@ namespace Swig {
CAML_VALUE swig_self; CAML_VALUE swig_self;
/* flag indicating whether the object is owned by ocaml or c++ */ /* flag indicating whether the object is owned by ocaml or c++ */
mutable bool swig_disown_flag; mutable bool swig_disown_flag;
mutable bool swig_up;
#ifdef __PTHREAD__
/* locks for sharing the swig_up flag in a threaded environment */
static pthread_mutex_t swig_mutex_up;
static bool swig_mutex_active;
static pthread_t swig_mutex_thread;
#endif
/* reset the swig_up flag once the routing direction has been determined */
#ifdef __PTHREAD__
void swig_clear_up() const {
swig_up = false;
Swig::Director::swig_mutex_active = false;
pthread_mutex_unlock(&swig_mutex_up);
}
#else
void swig_clear_up() const {
swig_up = false;
}
#endif
public: public:
/* wrap a ocaml object, optionally taking ownership */ /* wrap a ocaml object, optionally taking ownership */
Director(CAML_VALUE self) : swig_self(self), swig_disown_flag(false), swig_up( false ) { Director(CAML_VALUE self) : swig_self(self), swig_disown_flag(false) {
register_global_root(&swig_self); register_global_root(&swig_self);
} }
@ -103,45 +81,6 @@ namespace Swig {
return swig_self; return swig_self;
} }
/* get the swig_up flag to determine if the method call should be routed
* to the c++ base class or through the wrapped ocaml object
*/
#ifdef __PTHREAD__
bool swig_get_up( bool clear = true ) const {
if (Swig::Director::swig_mutex_active) {
if (pthread_equal(Swig::Director::swig_mutex_thread, pthread_self())) {
bool up = swig_up;
if( clear ) swig_clear_up();
return up;
}
}
return false;
}
#else
bool swig_get_up( bool clear = true ) const {
bool up = swig_up;
if( clear ) swig_up = false;
return up;
}
#endif
/* set the swig_up flag if the next method call should be directed to
* the c++ base class rather than the wrapped ocaml object
*/
#ifdef __PTHREAD__
void swig_set_up() const {
pthread_mutex_lock(&Swig::Director::swig_mutex_up);
Swig::Director::swig_mutex_thread = pthread_self();
Swig::Director::swig_mutex_active = true;
swig_up = true;
}
#else
void swig_set_up() const {
swig_up = true;
}
#endif
/* acquire ownership of the wrapped ocaml object (the sense of "disown" /* acquire ownership of the wrapped ocaml object (the sense of "disown"
* is from ocaml) */ * is from ocaml) */
void swig_disown() const { void swig_disown() const {
@ -151,13 +90,6 @@ namespace Swig {
} }
} }
}; };
#ifdef __PTHREAD__
MUTEX_INIT(Swig::Director::swig_mutex_up);
pthread_t Swig::Director::swig_mutex_thread;
bool Swig::Director::swig_mutex_active = false;
#endif
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View file

@ -26,18 +26,10 @@ namespace Swig {
swig_incref(); swig_incref();
} }
bool Director::swig_up = false;
#ifdef __PTHREAD__ #ifdef __PTHREAD__
pthread_mutex_t SWIG_MUTEX_INIT(Director::swig_mutex_up);
pthread_mutex_t SWIG_MUTEX_INIT(Director::swig_mutex_own); pthread_mutex_t SWIG_MUTEX_INIT(Director::swig_mutex_own);
pthread_t Director::swig_mutex_thread;
bool Director::swig_mutex_active = false;
#endif #endif
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View file

@ -317,7 +317,7 @@ namespace Swig {
{ {
public: public:
DirectorPureVirtualException(const char* msg = "") DirectorPureVirtualException(const char* msg = "")
: DirectorException(PyExc_RuntimeError, "Swig director pure virtal method called", msg) : DirectorException(PyExc_RuntimeError, "Swig director pure virtual method called", msg)
{ {
} }
@ -376,15 +376,6 @@ namespace Swig {
PyObject* swig_self; PyObject* swig_self;
/* flag indicating whether the object is owned by python or c++ */ /* flag indicating whether the object is owned by python or c++ */
mutable bool swig_disown_flag; mutable bool swig_disown_flag;
/* shared flag for breaking recursive director calls */
static bool swig_up;
#ifdef __PTHREAD__
/* locks for sharing the swig_up flag in a threaded environment */
static pthread_mutex_t swig_mutex_up;
static bool swig_mutex_active;
static pthread_t swig_mutex_thread;
#endif
/* decrement the reference count of the wrapped python object */ /* decrement the reference count of the wrapped python object */
void swig_decref() const { void swig_decref() const {
@ -395,19 +386,6 @@ namespace Swig {
} }
} }
/* reset the swig_up flag once the routing direction has been determined */
#ifdef __PTHREAD__
void swig_clear_up() const {
Swig::Director::swig_up = false;
Swig::Director::swig_mutex_active = false;
pthread_mutex_unlock(&swig_mutex_up);
}
#else
void swig_clear_up() const {
Swig::Director::swig_up = false;
}
#endif
public: public:
/* wrap a python object, optionally taking ownership */ /* wrap a python object, optionally taking ownership */
Director(PyObject* self); Director(PyObject* self);
@ -420,44 +398,6 @@ namespace Swig {
return swig_self; return swig_self;
} }
/* get the swig_up flag to determine if the method call should be routed
* to the c++ base class or through the wrapped python object
*/
#ifdef __PTHREAD__
bool swig_get_up() const {
if (Swig::Director::swig_mutex_active) {
if (pthread_equal(Swig::Director::swig_mutex_thread, pthread_self())) {
bool up = swig_up;
swig_clear_up();
return up;
}
}
return 0;
}
#else
bool swig_get_up() const {
bool up = swig_up;
swig_up = false;
return up;
}
#endif
/* set the swig_up flag if the next method call should be directed to
* the c++ base class rather than the wrapped python object
*/
#ifdef __PTHREAD__
void swig_set_up() const {
pthread_mutex_lock(&Swig::Director::swig_mutex_up);
Swig::Director::swig_mutex_thread = pthread_self();
Swig::Director::swig_mutex_active = true;
Swig::Director::swig_up = true;
}
#else
void swig_set_up() const {
Swig::Director::swig_up = true;
}
#endif
/* acquire ownership of the wrapped python object (the sense of "disown" /* acquire ownership of the wrapped python object (the sense of "disown"
* is from python) */ * is from python) */
void swig_disown() const { void swig_disown() const {
@ -482,7 +422,7 @@ namespace Swig {
virtual void swig_set_inner(const char* /* name */, bool /* val */) const { virtual void swig_set_inner(const char* /* name */, bool /* val */) const {
} }
/* ownership managing */ /* ownership management */
private: private:
typedef std::map<void*, GCItem_var> ownership_map; typedef std::map<void*, GCItem_var> ownership_map;
mutable ownership_map owner; mutable ownership_map owner;
@ -531,7 +471,6 @@ namespace Swig {
return own; return own;
} }
}; };
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View file

@ -121,7 +121,6 @@ namespace Swig {
/* body args */ /* body args */
struct body_args { struct body_args {
VALUE recv; VALUE recv;
ID id; ID id;
@ -253,7 +252,7 @@ namespace Swig {
{ {
public: public:
DirectorPureVirtualException(const char* msg = "") DirectorPureVirtualException(const char* msg = "")
: DirectorException(rb_eRuntimeError, "Swig director pure virtal method called", msg) : DirectorException(rb_eRuntimeError, "Swig director pure virtual method called", msg)
{ {
} }
@ -299,95 +298,35 @@ namespace Swig {
/* director base class */ /* director base class */
class Director { class Director {
private: private:
/* pointer to the wrapped Ruby object */ /* pointer to the wrapped Ruby object */
VALUE swig_self; VALUE swig_self;
/* flag indicating whether the object is owned by Ruby or c++ */ /* flag indicating whether the object is owned by Ruby or c++ */
mutable bool swig_disown_flag; mutable bool swig_disown_flag;
/* shared flag for breaking recursive director calls */
static bool swig_up;
#ifdef __PTHREAD__ public:
/* locks for sharing the swig_up flag in a threaded environment */ /* wrap a Ruby object, optionally taking ownership */
static pthread_mutex_t swig_mutex_up; Director(VALUE self) : swig_self(self), swig_disown_flag(false) {
static bool swig_mutex_active; }
static pthread_t swig_mutex_thread;
#endif
/* reset the swig_up flag once the routing direction has been determined */ /* discard our reference at destruction */
#ifdef __PTHREAD__ virtual ~Director() {
void swig_clear_up() const { }
Swig::Director::swig_up = false;
Swig::Director::swig_mutex_active = false;
pthread_mutex_unlock(&swig_mutex_up);
}
#else
void swig_clear_up() const {
Swig::Director::swig_up = false;
}
#endif
public: /* return a pointer to the wrapped Ruby object */
/* wrap a Ruby object, optionally taking ownership */ VALUE swig_get_self() const {
Director(VALUE self) : swig_self(self), swig_disown_flag(false) { return swig_self;
} }
/* discard our reference at destruction */ /* acquire ownership of the wrapped Ruby object (the sense of "disown"
virtual ~Director() { * is from Ruby) */
void swig_disown() const {
if (!swig_disown_flag) {
swig_disown_flag = true;
} }
}
/* return a pointer to the wrapped Ruby object */ /* ownership management */
VALUE swig_get_self() const {
return swig_self;
}
/* get the swig_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 swig_get_up() const {
if (Swig::Director::swig_mutex_active) {
if (pthread_equal(Swig::Director::swig_mutex_thread, pthread_self())) {
bool up = swig_up;
swig_clear_up();
return up;
}
}
return false;
}
#else
bool swig_get_up() const {
bool up = swig_up;
swig_up = false;
return up;
}
#endif
/* set the swig_up flag if the next method call should be directed to
* the c++ base class rather than the wrapped Ruby object
*/
#ifdef __PTHREAD__
void swig_set_up() const {
pthread_mutex_lock(&Swig::Director::swig_mutex_up);
Swig::Director::swig_mutex_thread = pthread_self();
Swig::Director::swig_mutex_active = true;
Swig::Director::swig_up = true;
}
#else
void swig_set_up() const {
Swig::Director::swig_up = true;
}
#endif
/* acquire ownership of the wrapped Ruby object (the sense of "disown"
* is from Ruby) */
void swig_disown() const {
if (!swig_disown_flag) {
swig_disown_flag = true;
}
}
/* ownership managing */
private: private:
typedef std::map<void*, GCItem_var> ownership_map; typedef std::map<void*, GCItem_var> ownership_map;
mutable ownership_map owner; mutable ownership_map owner;
@ -395,7 +334,6 @@ namespace Swig {
static pthread_mutex_t swig_mutex_own; static pthread_mutex_t swig_mutex_own;
#endif #endif
public: public:
template <typename Type> template <typename Type>
void swig_acquire_ownership_array(Type *vptr) const void swig_acquire_ownership_array(Type *vptr) const
@ -436,16 +374,7 @@ namespace Swig {
} }
return own; return own;
} }
}; };
bool Swig::Director::swig_up = false;
#ifdef __PTHREAD__
MUTEX_INIT(Swig::Director::swig_mutex_up);
pthread_t Swig::Director::swig_mutex_thread;
bool Swig::Director::swig_mutex_active = false;
#endif
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View file

@ -163,11 +163,6 @@
#define %nocontract %feature("contract","0") #define %nocontract %feature("contract","0")
#define %clearcontract %feature("contract","") #define %clearcontract %feature("contract","")
/* explicitcall directives */
#define %explicitcall %feature("explicitcall")
#define %noexplicitcall %feature("explicitcall","0")
#define %clearexplicitcall %feature("explicitcall","")
/* Macro for setting a dynamic cast function */ /* Macro for setting a dynamic cast function */
%define DYNAMIC_CAST(mangle,func) %define DYNAMIC_CAST(mangle,func)
%init %{ %init %{