mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +00:00
First pass at hybrid GC mode. This will try use retain-release mode if the collector is not running. Code will run in retain/release mode unless something compiled with -fobjc-gc-only is loaded.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@33174 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
86fa2414ec
commit
4db587f9d6
3 changed files with 131 additions and 23 deletions
|
@ -234,6 +234,10 @@ NSZoneName (NSZone *zone)
|
|||
__strong void *
|
||||
NSAllocateCollectable(NSUInteger size, NSUInteger options)
|
||||
{
|
||||
if (!objc_collecting_enabled())
|
||||
{
|
||||
return calloc(1, size);
|
||||
}
|
||||
id obj = objc_gc_allocate_collectable(size,
|
||||
((options & NSScannedOption) == NSScannedOption));
|
||||
if ((options & NSCollectorDisabledOption) == NSCollectorDisabledOption)
|
||||
|
@ -246,19 +250,26 @@ NSAllocateCollectable(NSUInteger size, NSUInteger options)
|
|||
__strong void *
|
||||
NSReallocateCollectable(void *ptr, NSUInteger size, NSUInteger options)
|
||||
{
|
||||
if (!objc_collecting_enabled())
|
||||
{
|
||||
return realloc(ptr, size);
|
||||
}
|
||||
return objc_gc_reallocate_collectable(ptr, size,
|
||||
((options & NSScannedOption) == NSScannedOption));
|
||||
}
|
||||
|
||||
id NSMakeCollectable(id obj)
|
||||
{
|
||||
objc_gc_release(obj);
|
||||
if (objc_collecting_enabled())
|
||||
{
|
||||
objc_gc_release(obj);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
NSZone*
|
||||
NSCreateZone (NSUInteger start, NSUInteger gran, BOOL canFree)
|
||||
{
|
||||
NSLog(@" *** Creating a zone while running GC is ignored.");
|
||||
return &default_zone;
|
||||
}
|
||||
|
||||
|
@ -268,15 +279,6 @@ NSDefaultMallocZone (void)
|
|||
return &default_zone;
|
||||
}
|
||||
|
||||
// This is an ugly hack. We should be using NSAllocateCollectable() without
|
||||
// NSScannedOption, not trying to fudge this with stuff that's totally
|
||||
// incompatible with Apple's design.
|
||||
NSZone*
|
||||
GSAtomicMallocZone (void)
|
||||
{
|
||||
return &default_zone;
|
||||
}
|
||||
|
||||
NSZone*
|
||||
NSZoneFromPointer (void *ptr)
|
||||
{
|
||||
|
@ -318,15 +320,23 @@ NSZoneMalloc (NSZone *zone, NSUInteger size)
|
|||
void*
|
||||
NSZoneCalloc (NSZone *zone, NSUInteger elems, NSUInteger bytes)
|
||||
{
|
||||
// FIXME: Overflow checking
|
||||
size_t size = elems * bytes;
|
||||
return objc_gc_allocate_collectable(size, YES);
|
||||
if (objc_collecting_enabled())
|
||||
{
|
||||
// FIXME: Overflow checking
|
||||
size_t size = elems * bytes;
|
||||
return objc_gc_allocate_collectable(size, YES);
|
||||
}
|
||||
return calloc(elems, bytes);
|
||||
}
|
||||
|
||||
void*
|
||||
NSZoneRealloc (NSZone *zone, void *ptr, NSUInteger size)
|
||||
{
|
||||
return objc_gc_reallocate_collectable(ptr, size, YES);
|
||||
if (objc_collecting_enabled())
|
||||
{
|
||||
return objc_gc_reallocate_collectable(ptr, size, YES);
|
||||
}
|
||||
return realloc(ptr, size);
|
||||
}
|
||||
|
||||
void NSZoneFree (NSZone *zone, void *ptr) { }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue