gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question: Best way to initialize constant objects in -corebase


From: Stefan Bidi
Subject: Question: Best way to initialize constant objects in -corebase
Date: Fri, 27 Jan 2012 08:32:09 -0600

I'd like to throw this up for discussion because I've got a few idea but do not know which one would be best.  As some of you might have noticed, a test in CFLocale crashes.  The reason for this crash is because on Linux -corebase is loaded and initialized before the objc runtime, so the isa pointer for these constants is NULL.  I added a work around for this so that constant strings could work.  I don't really like how that is implemented.

The main issue here is of library loading order.  It has always been a problem for -corebase and I imagine it will only get worst as it progresses.  Currently, the initialize function for each type (CFBooleanInitialize() for example) calls _CFRuntimeInitStaticInstance() to set the isa.  However, if the objc runtime has not been initialize, the isa is set to NULL.  Later, when the runtime does get loaded, it sets the Class to whatever it is in __CFRuntimeObjCClassTable[].  CF_IS_OBJC() checks this table against the isa pointer in order to decide if this is a ObjC instance or not.  When it tries to send a message to the NULL class... crash.

I've thought up 3 possible solutions--if you think of something else, please bring it up.  They are:

1) Expand the constant table to include all constant instances.  Initialize these constants whenever the objc runtime comes up--in [NSCFType +load].  This is what is currently done for constant strings.

2) Introduce two functions (ie. GSRegisterConstant() and GSInitializeConstants()) and have each initialize function call this to register constants with a table.  Whenever the objc runtime is brought up, the initialize constants function can be called as well.  CFInitialize, the library constructor function, is alreadycalled by [NSCFType +load] to make sure it is up before the objc runtime. This is what I'm leaning towards doing.

3) Have a constant instance table for each type/class and set the isa pointer whenever the specific class is loaded.  This is similar to what is already being done, but instead of having 1 constant instance table, we would have one for each type that needs it.

Anyway, I'm hoping to get some input from some of you guys that know more about the runtime and -base library than I do.

Thanks
Stef

reply via email to

[Prev in Thread] Current Thread [Next in Thread]