Crash on startup in Piraha

Issue #1363 closed
Erik Schnetter created an issue

I built a Cactus configuration with fewer thorns than usual, and with assertions disabled (-DNDEBUG. This configuration does not start; it crashes on startup with a backtrace

#0  std::_Rb_tree<void*, void*, std::_Identity<void*>, std::less<void*>, std::allocator<void*> >::_M_insert_unique<void* const&> (this=0x0, __v=@0x7fff5fbfd228) at locale_facets.h:1078
#1  0x000000010072e6f2 in smart_ptr<piraha::Grammar>::smart_ptr (this=0x104b9d0d0, ptr=0x10570a5a0, array_=<value temporarily unavailable, due to optimizations>) at stl_set.h:415
#2  0x0000000100721542 in piraha::AutoGrammar::reparserGenerator () at AutoGrammar.cc:6
#3  0x0000000100c2ada6 in _GLOBAL__sub_I_Grammar.cc () at smart_ptr.hpp:53
#4  0x00007fff5fc13762 in __dyld__ZN16ImageLoaderMachO16doInitializationERKN11ImageLoader11LinkContextE ()

This indicates that the failure oocurs during initialisation of a global variable during startup. _Rb_tree points to a set or a map. This may be caused by

extern smart_ptr<Grammar> pegGrammar;

I also see that Piraha has some code in smart_ptr.hpp that is only added when DNEBUG is defined, and contains assert calls (!). Given that NDEBUG disables assert, this looks like an error.

It is considered bad style to use C++ constructors to initialise global variables; this is fragile and breaks often. I suggest instead to change these global variables to pointers, to initialise them to NULL, and to allocate to respective objects explicitly at run time. This is safer, as it ensures that things are allocated in the right order.

I also just see that there is a global variables called "ptrs" in Piraha. This is not good; please use a cctki_ prefix for all globally visible variables and functions (or move them into a namespace).

Keyword:

Comments (9)

  1. Erik Schnetter reporter
    • marked as
    • removed milestone
    • removed comment

    I disabled the debugging code in r5010 (trunk) and r5010 (release branch). Reducing severity, since things don't crash any more.

  2. Steven R. Brandt
    • removed comment

    The #ifndef was changed to #ifdef

    The null initializer was used (as suggested)

    The underlying problem was fixed (didn't check for null in one place)

    since ptrs is in a namespace, it should not cause trouble.

  3. Log in to comment