Skip to content

Commit

Permalink
* change prefix from MulleObjCObject to MulleObjCInstance, where …
Browse files Browse the repository at this point in the history
…the object can only be an instance and not a class

* change prefix from `MulleObjCObject` to `MulleObjCClass`, where the object can only be a class and not an instance
  • Loading branch information
mulle-nat committed Mar 9, 2020
1 parent 3b930a3 commit 2709c6b
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 49 deletions.
14 changes: 14 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ### > generated by mulle-sde (extensions/mulle-sde/sde/init)
# Tweak GitHub language statistics

# .inc is generally C

*.inc linguist-language=C

# remove boring files
.mulle/** linguist-generated
.vscode/** linguist-generated
cmake/** linguist-generated

# ### < generated by mulle-sde (extensions/mulle-sde/sde/init)

2 changes: 1 addition & 1 deletion .mulle/share/env/environment.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/class/NSInvocation.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ - (void) _releaseArguments
case _C_CHARPTR :
[self getArgument:&s
atIndex:i];
mulle_allocator_free( MulleObjCObjectGetAllocator( self), s);
mulle_allocator_free( MulleObjCInstanceGetAllocator( self), s);
break;
}
}
Expand Down Expand Up @@ -258,7 +258,7 @@ - (void) retainArguments
case _C_CHARPTR :
[self getArgument:&s
atIndex:i];
dup = mulle_allocator_strdup( MulleObjCObjectGetAllocator( self), s);
dup = mulle_allocator_strdup( MulleObjCInstanceGetAllocator( self), s);
[self setArgument:&dup
atIndex:i];
break;
Expand Down
6 changes: 3 additions & 3 deletions src/class/NSMethodSignature.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ - (instancetype) initWithObjCTypes:(char *) types
return( nil);
}

_types = mulle_allocator_strdup( MulleObjCObjectGetAllocator( self), types);
_types = mulle_allocator_strdup( MulleObjCInstanceGetAllocator( self), types);
_bits = 0;

#if 0
Expand All @@ -91,7 +91,7 @@ - (void) dealloc
{
struct mulle_allocator *allocator;

allocator = MulleObjCObjectGetAllocator( self);
allocator = MulleObjCInstanceGetAllocator( self);

if( ! hasExtraMemory( self))
{
Expand Down Expand Up @@ -248,7 +248,7 @@ - (NSUInteger) numberOfArguments

if( ! hasExtraMemory( self))
{
allocator = MulleObjCObjectGetAllocator( self);
allocator = MulleObjCInstanceGetAllocator( self);
self->_infos = mulle_allocator_calloc( allocator, self->_count, sizeof( MulleObjCMethodSignatureTypeinfo));
self->_prettyTypes = mulle_allocator_strdup( allocator, self->_types);
}
Expand Down
17 changes: 17 additions & 0 deletions src/class/NSObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
//
- (instancetype) init;
- (void) dealloc; /* ---> #2# */

// will autorelease properties, except readonly ones!
- (void) finalize;

- (NSUInteger) hash;
Expand Down Expand Up @@ -172,6 +174,21 @@
@class NSInvocation;


@interface NSObject ( RuntimeInit)

//
// Preferably do not use ObjC or objc runtime calls in these
// (then everything is easy). If you do though, you MUST specify
// MULLE_OBJC_DEPENDS_ON_LIBRARY (preferably) or
// MULLE_OBJC_DEPENDS_ON_CLASS. MULLE_OBJC_DEPENDS_ON_LIBRARY is the safer
// choice, due to class cluster initialization. Be sure that what you call
// is where you expect it to be.
//
+ (void) initialize;
+ (void) load;

@end

// class methods available, because NSObject is root
@interface NSObject ( WrapAround)

Expand Down
8 changes: 4 additions & 4 deletions src/class/NSObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ - (void *) forward:(void *) _param

- (void) dealloc
{
_MulleObjCObjectFree( self);
_MulleObjCInstanceFree( self);
}


Expand Down Expand Up @@ -175,7 +175,7 @@ - (void) mullePerformFinalize

- (void) finalize
{
_MulleObjCObjectClearProperties( self);
_MulleObjCInstanceClearProperties( self);
}


Expand All @@ -195,7 +195,7 @@ - (void) dealloc
"deallocing object %p still in autoreleasepool", self);
}
#endif
_MulleObjCObjectFree( self);
_MulleObjCInstanceFree( self);
}


Expand Down Expand Up @@ -346,7 +346,7 @@ + (instancetype) instantiate
placeholder = _MulleObjCClassNewInstantiatePlaceholder( self, classid);
if( ! _mulle_objc_infraclass_set_placeholder( self, placeholder))
{
_MulleObjCObjectFree( (id) placeholder);
_MulleObjCInstanceFree( (id) placeholder);
goto retry;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/class/NSThread.m
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ - (void) dealloc
assert( ! self->_runLoop);
assert( ! self->_userInfo);

_MulleObjCObjectFree( self);
_MulleObjCInstanceFree( self);
}


Expand Down
18 changes: 9 additions & 9 deletions src/function/MulleObjCAllocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@


__attribute__((const))
static inline struct mulle_allocator *MulleObjCObjectGetAllocator( id obj)
static inline struct mulle_allocator *MulleObjCInstanceGetAllocator( id obj)
{
struct _mulle_objc_class *cls;
struct _mulle_objc_infraclass *infra;
Expand Down Expand Up @@ -71,40 +71,40 @@ static inline struct mulle_allocator *MulleObjCClassGetAllocator( Class cls)
#pragma mark -
#pragma mark allocate memory to return char * autoreleased

void *MulleObjCAutoreleasedCalloc( NSUInteger n,
void *MulleObjCCallocAutoreleased( NSUInteger n,
NSUInteger size);

#pragma mark -
#pragma mark allocate memory for objects

static inline void *MulleObjCObjectAllocateNonZeroedMemory( id self, NSUInteger size)
{
return( _mulle_allocator_malloc( MulleObjCObjectGetAllocator( self), size));
return( _mulle_allocator_malloc( MulleObjCInstanceGetAllocator( self), size));
}


static inline void *MulleObjCObjectReallocateNonZeroedMemory( id self, void *p, NSUInteger size)
{
return( _mulle_allocator_realloc( MulleObjCObjectGetAllocator( self), p, size));
return( _mulle_allocator_realloc( MulleObjCInstanceGetAllocator( self), p, size));
}


static inline void *MulleObjCObjectAllocateMemory( id self, NSUInteger size)
{
return( _mulle_allocator_calloc( MulleObjCObjectGetAllocator( self), 1, size));
return( _mulle_allocator_calloc( MulleObjCInstanceGetAllocator( self), 1, size));
}


static inline void *MulleObjCObjectDuplicateCString( id self, char *s)
{
return( _mulle_allocator_strdup( MulleObjCObjectGetAllocator( self), s));
return( _mulle_allocator_strdup( MulleObjCInstanceGetAllocator( self), s));
}


static inline void MulleObjCObjectDeallocateMemory( id self, void *p)
{
if( p)
_mulle_allocator_free( MulleObjCObjectGetAllocator( self), p);
_mulle_allocator_free( MulleObjCInstanceGetAllocator( self), p);
}


Expand Down Expand Up @@ -142,11 +142,11 @@ static inline id _MulleObjCClassAllocateNonZeroedObject( Class infraCls,
}


void _MulleObjCObjectClearProperties( id obj);
void _MulleObjCInstanceClearProperties( id obj);


// this does not zero properties
void _MulleObjCObjectFree( id obj);
void _MulleObjCInstanceFree( id obj);


static inline id NSAllocateObject( Class infra, NSUInteger extra, NSZone *zone)
Expand Down
51 changes: 23 additions & 28 deletions src/function/MulleObjCAllocation.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@
#include <stdarg.h>


int _MulleObjCObjectClearProperty( struct _mulle_objc_property *property,
struct _mulle_objc_infraclass *cls,
void *self);
// the parameters are shuffled this way, because its a walk callback

int _MulleObjCObjectClearProperty( struct _mulle_objc_property *property,
struct _mulle_objc_infraclass *cls,
void *self)
int _MulleObjCInstanceClearProperty( struct _mulle_objc_property *property,
struct _mulle_objc_infraclass *cls,
void *self);

int _MulleObjCInstanceClearProperty( struct _mulle_objc_property *property,
struct _mulle_objc_infraclass *cls,
void *self)
{
uint32_t bits;
ptrdiff_t offset;
Expand Down Expand Up @@ -105,20 +107,20 @@ int _MulleObjCObjectClearProperty( struct _mulle_objc_property *property,
void NSDeallocateObject( id self)
{
if( self)
_MulleObjCObjectFree( self);
_MulleObjCInstanceFree( self);
}


# pragma mark - improve dealloc speed for classes that don't have properties that need to be released


int _MulleObjCInfraclassWalkClearableProperties( struct _mulle_objc_infraclass *infra,
mulle_objc_walkpropertiescallback f,
void *userinfo);
int _MulleObjCClassWalkClearableProperties( struct _mulle_objc_infraclass *infra,
mulle_objc_walkpropertiescallback f,
void *userinfo);

int _MulleObjCInfraclassWalkClearableProperties( struct _mulle_objc_infraclass *infra,
mulle_objc_walkpropertiescallback f,
void *userinfo)
int _MulleObjCClassWalkClearableProperties( struct _mulle_objc_infraclass *infra,
mulle_objc_walkpropertiescallback f,
void *userinfo)
{
struct _mulle_objc_propertylist *list;
struct mulle_concurrent_pointerarrayreverseenumerator rover;
Expand All @@ -145,36 +147,29 @@ int _MulleObjCInfraclassWalkClearableProperties( struct _mulle_objc_infraclass
// in MulleObjC the superclass is always searched
superclass = _mulle_objc_infraclass_get_superclass( infra);
if( superclass && superclass != infra)
return( _MulleObjCInfraclassWalkClearableProperties( superclass, f, userinfo));
return( _MulleObjCClassWalkClearableProperties( superclass, f, userinfo));

return( 0);
}


void _MulleObjCObjectClearProperties( id obj)
void _MulleObjCInstanceClearProperties( id obj)
{
extern int _MulleObjCObjectClearProperty( struct _mulle_objc_property *,
struct _mulle_objc_infraclass *cls,
void *);
extern int _MulleObjCInfraclassWalkClearableProperties( struct _mulle_objc_infraclass *,
mulle_objc_walkpropertiescallback,
void *);

struct _mulle_objc_class *cls;
struct _mulle_objc_infraclass *infra;

// walk through properties and release them
cls = _mulle_objc_object_get_isa( obj);
// if it's a meta class it's an error during debug
infra = _mulle_objc_class_as_infraclass( cls);
_MulleObjCInfraclassWalkClearableProperties( infra,
_MulleObjCObjectClearProperty,
obj);
_MulleObjCClassWalkClearableProperties( infra,
_MulleObjCInstanceClearProperty,
obj);
}


// this does not zero properties
void _MulleObjCObjectFree( id obj)
void _MulleObjCInstanceFree( id obj)
{
struct _mulle_objc_objectheader *header;
struct _mulle_objc_universefoundationinfo *config;
Expand Down Expand Up @@ -285,7 +280,7 @@ void MulleObjCObjectSetDuplicatedCString( id self, char **ivar, char *s)
if( s == *ivar)
return;

allocator = MulleObjCObjectGetAllocator( self);
allocator = MulleObjCInstanceGetAllocator( self);
if( s)
s = mulle_allocator_strdup( allocator, s);

Expand All @@ -294,7 +289,7 @@ void MulleObjCObjectSetDuplicatedCString( id self, char **ivar, char *s)
}


void *MulleObjCAutoreleasedCalloc( NSUInteger n,
void *MulleObjCCallocAutoreleased( NSUInteger n,
NSUInteger size)
{
size_t total;
Expand Down
2 changes: 1 addition & 1 deletion test/.mulle/share/env/environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ case "${MULLE_SHELL_MODE}" in
alias t="mulle-sde test rerun --serial"
alias tt="mulle-sde test craft ; mulle-sde test rerun --serial"
alias T="mulle-sde test craft ; mulle-sde test"
alias TT="mulle-sde test clean ; mulle-sde test"
alias TT="mulle-sde test clean all; mulle-sde test"
alias r="mulle-sde reflect"
alias l="mulle-sde list --files"
fi
Expand Down

0 comments on commit 2709c6b

Please sign in to comment.