diff --git a/src/gsi/gsi/gsiCallback.h b/src/gsi/gsi/gsiCallback.h index e3903cd5a..e37621823 100644 --- a/src/gsi/gsi/gsiCallback.h +++ b/src/gsi/gsi/gsiCallback.h @@ -41,6 +41,7 @@ struct GSI_PUBLIC Callee virtual ~Callee () { } virtual void call (int id, SerialArgs &args, SerialArgs &ret) const = 0; + virtual bool can_call () const { return true; } }; /** @@ -72,7 +73,7 @@ struct Callback bool can_issue () const { - return callee.get () != 0; + return callee && callee->can_call (); } // 0 arguments diff --git a/src/pya/pya/pyaObject.cc b/src/pya/pya/pyaObject.cc index 938e40488..2c3120418 100644 --- a/src/pya/pya/pyaObject.cc +++ b/src/pya/pya/pyaObject.cc @@ -111,6 +111,50 @@ bool CallbackFunction::operator== (const CallbackFunction &other) const return callable_ref () == other.callable_ref (); } +/** + * @brief An adaptor class for the callback mechanism + */ +class Callee + : public gsi::Callee +{ +public: + /** + * @brief Constructor for a Callee object pointing the to given Python object + */ + Callee (PYAObjectBase *obj); + + /** + * @brief Destructor + */ + ~Callee (); + + /** + * @brief Adds a callback (given by the CallbackFunction) + * This method returns a callback ID which can be used to register the callback + * at an GSI object. + */ + int add_callback (const CallbackFunction &vf); + + /** + * @brief Clears all callbacks registered + */ + void clear_callbacks (); + + /** + * @brief Implementation of the Callee interface + */ + virtual void call (int id, gsi::SerialArgs &args, gsi::SerialArgs &ret) const; + + /** + * @brief Implementation of the Callee interface + */ + virtual bool can_call () const; + +private: + PYAObjectBase *mp_obj; + std::vector m_cbfuncs; +}; + // -------------------------------------------------------------------------- // Implementation of Callee @@ -138,6 +182,12 @@ Callee::clear_callbacks () m_cbfuncs.clear (); } +bool +Callee::can_call () const +{ + return pya::PythonInterpreter::instance () != 0; +} + void Callee::call (int id, gsi::SerialArgs &args, gsi::SerialArgs &ret) const { diff --git a/src/rba/rba/rba.cc b/src/rba/rba/rba.cc index 75ccdab25..4705f2aed 100644 --- a/src/rba/rba/rba.cc +++ b/src/rba/rba/rba.cc @@ -1732,8 +1732,7 @@ RubyInterpreter::~RubyInterpreter () rb_release_top_self (); - // This prevents reinitialization - sp_rba_interpreter = reinterpret_cast (1); + sp_rba_interpreter = 0; } RubyInterpreter *RubyInterpreter::instance () diff --git a/src/rba/rba/rbaInspector.cc b/src/rba/rba/rbaInspector.cc index 26ffa7aab..70a7c9865 100644 --- a/src/rba/rba/rbaInspector.cc +++ b/src/rba/rba/rbaInspector.cc @@ -132,7 +132,7 @@ public: : m_hash (hash) { rb_gc_register_address (&m_hash); - m_keys = rb_ary_new2 (RHASH_SIZE (m_hash)); + m_keys = rb_ary_new2 (long (RHASH_SIZE (m_hash))); rb_gc_register_address (&m_keys); rb_hash_foreach (m_hash, (int (*)(...)) &push_key_to_ary_i, m_keys); } diff --git a/src/rba/rba/rbaInternal.cc b/src/rba/rba/rbaInternal.cc index e92dde690..80836da77 100644 --- a/src/rba/rba/rbaInternal.cc +++ b/src/rba/rba/rbaInternal.cc @@ -301,6 +301,11 @@ Proxy::signal_handler (const gsi::MethodBase *meth) return sh; } +bool Proxy::can_call () const +{ + return rba::RubyInterpreter::instance () != 0; +} + void Proxy::call (int id, gsi::SerialArgs &args, gsi::SerialArgs &ret) const { diff --git a/src/rba/rba/rbaInternal.h b/src/rba/rba/rbaInternal.h index 4957e5881..cca746f6d 100644 --- a/src/rba/rba/rbaInternal.h +++ b/src/rba/rba/rbaInternal.h @@ -147,6 +147,7 @@ public: VALUE signal_handler (const gsi::MethodBase *meth); virtual void call (int id, gsi::SerialArgs &args, gsi::SerialArgs &ret) const; + virtual bool can_call () const; private: const gsi::ClassBase *m_cls_decl; diff --git a/src/rbastub/rba.cc b/src/rbastub/rba.cc index 71718be2b..cf12dd57a 100644 --- a/src/rbastub/rba.cc +++ b/src/rbastub/rba.cc @@ -40,8 +40,7 @@ RubyInterpreter::RubyInterpreter () RubyInterpreter::~RubyInterpreter () { - // This prevents reinitialization - sp_rba_interpreter = reinterpret_cast (1); + sp_rba_interpreter = 0; } RubyInterpreter *RubyInterpreter::instance ()