From 9afcec25bcdf835c55cb655abeef8d09c1e0d5b6 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Thu, 26 Mar 2020 22:44:53 +0100 Subject: [PATCH] Fixed #526 - Make scripe debugging more reliable Problem: the debugger was printing an object's value as string. The effect is that for big objects "to_s" will deliver huge strings (e.g. polygons, netlists ...). "inspect" is better (already used for Python), but it's aliased to "to_s" in Python and Ruby. Huge strings will stall the debugger. The solution is to stop this aliasing (Ruby 2.x doesn't do it itself anymore) and use "inspect" consistently for Python and Ruby. Details can still be printed in the console. --- src/pya/pya/pyaModule.cc | 7 ++++++- src/rba/rba/rba.cc | 2 +- src/rba/rba/rbaInspector.cc | 4 ++-- src/rba/rba/rbaUtils.cc | 9 +++++++++ src/rba/rba/rbaUtils.h | 1 + 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/pya/pya/pyaModule.cc b/src/pya/pya/pyaModule.cc index 78cf493c9..1b1d7b6d4 100644 --- a/src/pya/pya/pyaModule.cc +++ b/src/pya/pya/pyaModule.cc @@ -2665,7 +2665,12 @@ PythonModule::make_classes (const char *mod_name) // The str method is also routed via the tp_str implementation alt_names.push_back ("__str__"); - if (! has_inspect) { +#if GSI_ALIAS_INSPECT + bool alias_inspect = ! has_inspect; +#else + bool alias_inspect = false; +#endif + if (alias_inspect) { add_python_doc (**c, mt, int (mid), tl::to_string (tr ("This method is also available as 'str(object)' and 'repr(object)'"))); alt_names.push_back ("__repr__"); } else { diff --git a/src/rba/rba/rba.cc b/src/rba/rba/rba.cc index 94c2e6f48..acbb5e353 100644 --- a/src/rba/rba/rba.cc +++ b/src/rba/rba/rba.cc @@ -1632,7 +1632,7 @@ rba_init (RubyInterpreterPrivateData *d) } if (mt->name (mid) == "to_s") { -#if HAVE_RUBY_VERSION_CODE>=20000 +#if HAVE_RUBY_VERSION_CODE>=20000 && defined(GSI_ALIAS_INSPECT) // Ruby 2.x does no longer alias "inspect" to "to_s" automatically, so we have to do this: rb_define_alias (klass, "inspect", "to_s"); #endif diff --git a/src/rba/rba/rbaInspector.cc b/src/rba/rba/rbaInspector.cc index 7ec99d676..e534cf7cf 100644 --- a/src/rba/rba/rbaInspector.cc +++ b/src/rba/rba/rbaInspector.cc @@ -228,7 +228,7 @@ public: std::string description () const { - return ruby2c (rba_safe_obj_as_string (m_obj)); + return ruby2c (rba_safe_inspect (m_obj)); } VALUE rb_key (size_t index) const @@ -357,7 +357,7 @@ public: std::string description () const { - return ruby2c (rba_safe_obj_as_string (m_obj)); + return ruby2c (rba_safe_inspect (m_obj)); } virtual std::string key (size_t index) const diff --git a/src/rba/rba/rbaUtils.cc b/src/rba/rba/rbaUtils.cc index 1df2b09fa..5bdc35432 100644 --- a/src/rba/rba/rbaUtils.cc +++ b/src/rba/rba/rbaUtils.cc @@ -212,6 +212,15 @@ rba_safe_obj_as_string (VALUE obj) } } +/** + * @brief object to string with check + */ +VALUE +rba_safe_inspect (VALUE obj) +{ + return rba_safe_func (rb_inspect, obj); +} + /** * @brief needed because NUM2INT may be a macro: */ diff --git a/src/rba/rba/rbaUtils.h b/src/rba/rba/rbaUtils.h index ee394549e..b383fc1df 100644 --- a/src/rba/rba/rbaUtils.h +++ b/src/rba/rba/rbaUtils.h @@ -201,6 +201,7 @@ void rba_check_error (); VALUE rba_string_value_f (VALUE obj); VALUE rba_safe_string_value (VALUE obj); VALUE rba_safe_obj_as_string (VALUE obj); +VALUE rba_safe_inspect (VALUE obj); int rba_num2int_f (VALUE obj); int rba_safe_num2int (VALUE obj); unsigned int rba_num2uint_f (VALUE obj);