Fixed an issue with destruction callbacks in the QApplication destructor - in this case the interpreter may be nulled already and callbacks must not happen into Ruby/Python.

This commit is contained in:
Matthias Köfferlein 2018-09-06 23:37:26 +02:00
parent 5be469af90
commit ce01ce2dae
7 changed files with 22 additions and 6 deletions

View File

@ -41,6 +41,7 @@ struct GSI_PUBLIC Callee
virtual ~Callee () { } virtual ~Callee () { }
virtual void call (int id, SerialArgs &args, SerialArgs &ret) const = 0; 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 bool can_issue () const
{ {
return callee.get () != 0; return callee && callee->can_call ();
} }
// 0 arguments // 0 arguments

View File

@ -76,6 +76,11 @@ public:
*/ */
virtual void call (int id, gsi::SerialArgs &args, gsi::SerialArgs &ret) const; virtual void call (int id, gsi::SerialArgs &args, gsi::SerialArgs &ret) const;
/**
* @brief Implementation of the Callee interface
*/
virtual bool can_call () const;
private: private:
PYAObjectBase *mp_obj; PYAObjectBase *mp_obj;
std::vector<CallbackFunction> m_cbfuncs; std::vector<CallbackFunction> m_cbfuncs;
@ -108,6 +113,12 @@ Callee::clear_callbacks ()
m_cbfuncs.clear (); m_cbfuncs.clear ();
} }
bool
Callee::can_call () const
{
return pya::PythonInterpreter::instance () != 0;
}
void void
Callee::call (int id, gsi::SerialArgs &args, gsi::SerialArgs &ret) const Callee::call (int id, gsi::SerialArgs &args, gsi::SerialArgs &ret) const
{ {

View File

@ -1728,8 +1728,7 @@ RubyInterpreter::~RubyInterpreter ()
rb_release_top_self (); rb_release_top_self ();
// This prevents reinitialization sp_rba_interpreter = 0;
sp_rba_interpreter = reinterpret_cast<RubyInterpreter *> (1);
} }
RubyInterpreter *RubyInterpreter::instance () RubyInterpreter *RubyInterpreter::instance ()

View File

@ -132,7 +132,7 @@ public:
: m_hash (hash) : m_hash (hash)
{ {
rb_gc_register_address (&m_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_gc_register_address (&m_keys);
rb_hash_foreach (m_hash, (int (*)(...)) &push_key_to_ary_i, m_keys); rb_hash_foreach (m_hash, (int (*)(...)) &push_key_to_ary_i, m_keys);
} }

View File

@ -301,6 +301,11 @@ Proxy::signal_handler (const gsi::MethodBase *meth)
return sh; return sh;
} }
bool Proxy::can_call () const
{
return rba::RubyInterpreter::instance () != 0;
}
void void
Proxy::call (int id, gsi::SerialArgs &args, gsi::SerialArgs &ret) const Proxy::call (int id, gsi::SerialArgs &args, gsi::SerialArgs &ret) const
{ {

View File

@ -147,6 +147,7 @@ public:
VALUE signal_handler (const gsi::MethodBase *meth); VALUE signal_handler (const gsi::MethodBase *meth);
virtual void call (int id, gsi::SerialArgs &args, gsi::SerialArgs &ret) const; virtual void call (int id, gsi::SerialArgs &args, gsi::SerialArgs &ret) const;
virtual bool can_call () const;
private: private:
const gsi::ClassBase *m_cls_decl; const gsi::ClassBase *m_cls_decl;

View File

@ -41,8 +41,7 @@ RubyInterpreter::RubyInterpreter ()
RubyInterpreter::~RubyInterpreter () RubyInterpreter::~RubyInterpreter ()
{ {
// This prevents reinitialization sp_rba_interpreter = 0;
sp_rba_interpreter = reinterpret_cast<RubyInterpreter *> (1);
} }
RubyInterpreter *RubyInterpreter::instance () RubyInterpreter *RubyInterpreter::instance ()