Skip to content

The universe and the big bang

Nat! edited this page Sep 27, 2018 · 2 revisions

The runtime is missing one function __register_mulle_objc_universe. It is actually the task of the executing program to setup the Objective-C runtime. This is done by providing said C function, which returns a struct _mulle_objc_universe pointer.

But what does actually happen in __register_mulle_objc_universe ? First the function will acquire with __mulle_objc_get_universe a universe. Then it will check that said universe is initialized with _mulle_objc_universe_is_initialized. If it isn't then the big bang happens and that's what this entry is all about.

The big bang

The big bang starts with a call to _mulle_objc_universe_bang which takes four arguments

Number Argument Description
#0 universe The universe you got from __mulle_objc_get_universe and that is not initialized yes.
#1 bang A function pointer to a setup function. Can be NULL.
#2 exitus After the universe contracts to nothing, the exitus routine will be called. Can be NULL.
#3 userinfo A void pointer that will be passed to the bang routine

_mulle_objc_universe_bang makes sure that there aren't competing threads trying to start the universe at the same time then it calls bang. But lets assume that bang is NULL, then the standard universe setup routine _mulle_objc_universe_defaultbang will be called. This in turn will call __mulle_objc_universe_setup.

If you provide a custom "bang" routine, than that routine should call __mulle_objc_universe_setup also, preferably ahead of your customization.

__mulle_objc_universe_setup doesn't do all that much. It installs the bare minimum print-and-abort handlers into the exception vector table. It initializes various lookup tables. And it reads the environment variables to possibly set various debug flags.

Generally for a simple Foundation you will probably want to setup the following things:

  • exception handlers
  • a static string class