Skip to content

Commit

Permalink
changes to adapt to mulle-c11 4.0.0
Browse files Browse the repository at this point in the history
* fix some new bugs introduced by the NSThread rewrite
  • Loading branch information
codeon-nat committed Feb 21, 2020
1 parent fb7ff48 commit 4883765
Show file tree
Hide file tree
Showing 16 changed files with 463 additions and 68 deletions.
1 change: 1 addition & 0 deletions .mulle/share/sde/version/mulle-objc/vscode-clang
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.16.0
29 changes: 29 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"_comment": "All? It's often convenient in library projects too",
"name": "Debug MulleObjC",
"type": "cppdbg",
"MIMode": "lldb",
"request": "launch",
"stopAtEntry": true,
"program": "${workspaceFolder}/kitchen/Debug/MulleObjC",
"args": [],
"environment": [],
"cwd": "${workspaceFolder}",
"additionalSOLibSearchPath": "${workspaceFolder}/dependency/Debug/lib:${workspaceFolder}/dependency/lib",
"windows": {
"miDebuggerPath": "C:\\mingw64\\bin\\mulle-lldb-mi.exe",
"program": "${workspaceFolder}/kitchen/Debug/MulleObjC.exe"
},
"osx": {
"miDebuggerPath": "/usr/local/bin/mulle-lldb-mi"
},
"linux": {
"miDebuggerPath": "/usr/bin/mulle-lldb-mi"
},
"preLaunchTask": "Debug"
}
]
}
16 changes: 16 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"files.exclude": {
"__error": "Not found",
"**/stash": true,
"**/build": true,
"**/var": true,
"**/dependency": true
},
"files.watcherExclude": {
"__error": "Not found",
"**/stash": true,
"**/build": true,
"**/var": true,
"**/dependency": true
}
}
4 changes: 2 additions & 2 deletions src/MulleObjCUniverse.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

#include "include.h"

MULLE_C_CONST_NON_NULL_RETURN
MULLE_C_CONST_NONNULL_RETURN
static inline struct _mulle_objc_universe *MulleObjCGetUniverse( void)
{
return( mulle_objc_global_inlineget_universe( __MULLE_OBJC_UNIVERSEID__));
}


MULLE_C_CONST_NON_NULL_RETURN
MULLE_C_CONST_NONNULL_RETURN
static inline struct _mulle_objc_universe *MulleObjCObjectGetUniverse( id self)
{
if( ! self)
Expand Down
6 changes: 5 additions & 1 deletion src/class/NSObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ - (BOOL) __isClassClusterPlaceholderObject

universe = _mulle_objc_infraclass_get_universe( infraCls);
placeholderInfracls = mulle_objc_universe_lookup_infraclass_nofail( universe, classid);
_mulle_objc_class_setup( _mulle_objc_infraclass_as_class( placeholderInfracls));

placeholder = _MulleObjCClassAllocateObject( placeholderInfracls, 0);
placeholder->_cls = infraCls;
_mulle_objc_object_constantify_noatomic( placeholder);
Expand All @@ -334,12 +336,14 @@ + (mulle_objc_classid_t) __instantiatePlaceholderClassid
+ (instancetype) instantiate
{
struct _mulle_objc_object *placeholder;
mulle_objc_classid_t classid;

retry:
placeholder = _mulle_objc_infraclass_get_placeholder( self);
if( ! placeholder)
{
placeholder = _MulleObjCClassNewInstantiatePlaceholder( self, [self __instantiatePlaceholderClassid]);
classid = [self __instantiatePlaceholderClassid];
placeholder = _MulleObjCClassNewInstantiatePlaceholder( self, classid);
if( ! _mulle_objc_infraclass_set_placeholder( self, placeholder))
{
_MulleObjCObjectFree( (id) placeholder);
Expand Down
32 changes: 18 additions & 14 deletions src/class/NSThread.m
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ static void _mulle_objc_thread_become_universethread( struct _mulle_objc_unive
assert( thread != _mulle_objc_universe_get_thread( universe));

rc = _mulle_objc_universe_retain( universe);
if( universe->debug.trace.universe)
mulle_objc_universe_trace( universe, "mulle-thread %p retained the universe (%ld)",
(void *) thread, rc);

// during the main thread bang, this is already done
mulle_objc_thread_setup_threadinfo( universe);
Expand All @@ -141,7 +138,6 @@ static void _mulle_objc_thread_become_universethread( struct _mulle_objc_unive
{
mulle_thread_t thread;


//
// the universe will do this, if we are the
// "main" thread
Expand All @@ -152,9 +148,6 @@ static void _mulle_objc_thread_become_universethread( struct _mulle_objc_unive
if( unset)
mulle_objc_thread_unset_threadinfo( universe); // can't call Objective-C anymore

if( universe->debug.trace.universe)
mulle_objc_universe_trace( universe, "mulle-thread %p releases the universe",
(void *) thread);
_mulle_objc_universe_release( universe);
}

Expand Down Expand Up @@ -219,12 +212,15 @@ static void _MulleThreadDeregisterInUniverse( NSThread *threadObject,
threadObject = [NSThread new];
_mulle_atomic_pointer_nonatomic_write( &threadObject->_thread, (void *) mulle_thread_self());

_MulleThreadRegisterInUniverse( threadObject, universe, NO);

// create pool configuration
//
// create pool configuration, ahead of register so it can
// send a notification
//
assert( mulle_objc_universe_lookup_infraclass_nofail( universe, @selector( NSAutoreleasePool)));
mulle_objc_thread_new_poolconfiguration( universe);

_MulleThreadRegisterInUniverse( threadObject, universe, NO);

return( threadObject);
}

Expand Down Expand Up @@ -635,19 +631,27 @@ static void bouncyBounce( void *arg)
// so register this thread to be able to to ObjC calls
_mulle_objc_thread_become_universethread( universe);

//
// create pool configuration, ahead of register so it can
// send a notification
//
assert( mulle_objc_universe_lookup_infraclass_nofail( universe, @selector( NSAutoreleasePool)));
mulle_objc_thread_new_poolconfiguration( universe);

// make threadObject known to universe and thread
_MulleThreadRegisterInUniverse( threadObject, universe, YES);

// the caller will have retained it on out behalf already once,
// so reduce this again, and also the thread count now
//
// for a short moment, the number of threads will be one too high
// but its important so you don get races if you are polling
// +mulleIsMultiThreaded
//
_mulle_objc_universe_release( universe);
info = _mulle_objc_universe_get_universefoundationinfo( universe);
_mulle_atomic_pointer_decrement( &info->thread.n_threads);


// create autoreleaspool
mulle_objc_thread_new_poolconfiguration( universe);

[threadObject main];
}

Expand Down
1 change: 1 addition & 0 deletions src/function/MulleObjCAllocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ static inline void MulleObjCObjectDeallocateMemory( id self, void *p)


// resist the urge to add placeholder detection code here
// resist the urge to add _mulle_objc_class_setup here
__attribute__((returns_nonnull))
static inline id _MulleObjCClassAllocateObject( Class infraCls, NSUInteger extra)
{
Expand Down
16 changes: 16 additions & 0 deletions src/function/MulleObjCFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,19 @@ static inline void *MulleObjCInstanceGetExtraBytes( id obj)
}

NSUInteger MulleObjCClassGetLoadAddress( Class cls);


//
// In your +load methods, if you cache the class for use in C functions
// you must ensure, that the class is already properly loaded and
// initialized (this will trigger +initialize). You could also
// "just" call [self class]
//
//static void MulleObjCClassTouch( Class cls)
//{
// struct _mulle_objc_class *p;

// p = _mulle_objc_infraclass_as_class( cls);
// _mulle_objc_class_setup( p);
//}

2 changes: 1 addition & 1 deletion src/mulle-objc-threadfoundationinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static inline struct _mulle_objc_poolconfiguration *
/*
* Universe interface
*/
MULLE_C_CONST_NON_NULL_RETURN
MULLE_C_CONST_NONNULL_RETURN
struct _mulle_objc_threadfoundationinfo *
mulle_objc_thread_get_threadfoundationinfo( struct _mulle_objc_universe *universe);

Expand Down
2 changes: 1 addition & 1 deletion src/mulle-objc-threadfoundationinfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#import "NSThread.h"


MULLE_C_CONST_NON_NULL_RETURN
MULLE_C_CONST_NONNULL_RETURN
struct _mulle_objc_threadfoundationinfo *
mulle_objc_thread_get_threadfoundationinfo( struct _mulle_objc_universe *universe)
{
Expand Down
3 changes: 1 addition & 2 deletions src/mulle-objc-universeconfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ static void reset_testallocator( struct _mulle_objc_universe *universe)
config->universe.allocator,
&config->foundation.exceptiontable);

roots->teardown_callback = config->callbacks.teardown;

roots->teardown_callback = config->callbacks.teardown;
foundation.universefriend.data = roots;
foundation.staticstringclass = config->universe.staticstringclass;
foundation.universefriend.finalizer = foundationinfo_finalize;
Expand Down
2 changes: 1 addition & 1 deletion src/mulle-objc-universefoundationinfo-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ struct _mulle_objc_universefoundationinfo
};


MULLE_C_CONST_NON_NULL_RETURN static inline
MULLE_C_CONST_NONNULL_RETURN static inline
struct _mulle_objc_universefoundationinfo *
_mulle_objc_universe_get_universefoundationinfo( struct _mulle_objc_universe *universe)
{
Expand Down
25 changes: 17 additions & 8 deletions src/protocol/MulleObjCClassCluster.m
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,23 @@ void _mulle_objc_warn_classcluster( struct _mulle_objc_infraclass *self)
if( ! strncmp( name, "NS", 2) ||
! strncmp( name, "MulleObjC", 9))
{
fprintf( stderr, "warning: Class %08x \"%s\" is a subclass of "
"MulleObjCClassCluster but it gets allocated directly.\n"
"(Non classcluster Foundation subclasses should implement "
"+alloc, for user classes this is fine as\n"
"NSAllocateObject will be used)\n"
"break on _mulle_objc_warn_classcluster to debug)\n",
_mulle_objc_infraclass_get_classid( self),
name);
struct _mulle_objc_universe *universe;

universe = _mulle_objc_infraclass_get_universe( self);
mulle_objc_universe_fprintf(
universe,
stderr,
"warning: Class %08x \"%s\" is a subclass of "
"MulleObjCClassCluster but it gets allocated directly.\n"
"(Non classcluster Foundation subclasses should implement "
"+alloc, for user classes this is fine as\n"
"NSAllocateObject will be used)\n"
"break on _mulle_objc_warn_classcluster to debug)\n",
_mulle_objc_infraclass_get_classid( self),
name);

if( universe->debug.warn.crash)
abort();
}
}
#endif
Expand Down
Loading

0 comments on commit 4883765

Please sign in to comment.