- 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;
/* flag indicating whether the object is owned by ocaml or c++ */
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:
/* 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);
}
@ -103,45 +81,6 @@ namespace Swig {
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"
* is from ocaml) */
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 */

View file

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

View file

@ -317,7 +317,7 @@ namespace Swig {
{
public:
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;
/* flag indicating whether the object is owned by python or c++ */
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 */
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:
/* wrap a python object, optionally taking ownership */
Director(PyObject* self);
@ -420,44 +398,6 @@ namespace Swig {
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"
* is from python) */
void swig_disown() const {
@ -482,7 +422,7 @@ namespace Swig {
virtual void swig_set_inner(const char* /* name */, bool /* val */) const {
}
/* ownership managing */
/* ownership management */
private:
typedef std::map<void*, GCItem_var> ownership_map;
mutable ownership_map owner;
@ -531,7 +471,6 @@ namespace Swig {
return own;
}
};
}
#endif /* __cplusplus */

View file

@ -121,7 +121,6 @@ namespace Swig {
/* body args */
struct body_args {
VALUE recv;
ID id;
@ -253,7 +252,7 @@ namespace Swig {
{
public:
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,102 +298,41 @@ namespace Swig {
/* director base class */
class Director {
private:
/* pointer to the wrapped Ruby object */
VALUE swig_self;
/* flag indicating whether the object is owned by Ruby or c++ */
mutable bool swig_disown_flag;
/* shared flag for breaking recursive director calls */
static bool swig_up;
private:
/* pointer to the wrapped Ruby object */
VALUE swig_self;
/* flag indicating whether the object is owned by Ruby or c++ */
mutable bool swig_disown_flag;
#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
public:
/* wrap a Ruby object, optionally taking ownership */
Director(VALUE self) : swig_self(self), swig_disown_flag(false) {
}
/* 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
/* discard our reference at destruction */
virtual ~Director() {
}
public:
/* wrap a Ruby object, optionally taking ownership */
Director(VALUE self) : swig_self(self), swig_disown_flag(false) {
}
/* return a pointer to the wrapped Ruby object */
VALUE swig_get_self() const {
return swig_self;
}
/* discard our reference at destruction */
virtual ~Director() {
}
/* 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;
}
}
/* return a pointer to the wrapped Ruby object */
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 */
/* ownership management */
private:
typedef std::map<void*, GCItem_var> ownership_map;
mutable ownership_map owner;
#ifdef __PTHREAD__
static pthread_mutex_t swig_mutex_own;
#endif
public:
template <typename Type>
@ -436,16 +374,7 @@ namespace Swig {
}
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 */

View file

@ -163,11 +163,6 @@
#define %nocontract %feature("contract","0")
#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 */
%define DYNAMIC_CAST(mangle,func)
%init %{