heck that NSAllocateObject() is given a class

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13585 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2002-05-03 10:10:38 +00:00
parent fd76f80aaf
commit 756b517706
2 changed files with 19 additions and 12 deletions

View file

@ -10,6 +10,8 @@
that would just crash. that would just crash.
In GSRegisterCurrentThread(), add code to handle the case where the In GSRegisterCurrentThread(), add code to handle the case where the
NSThread class has not been initialised. NSThread class has not been initialised.
* Source/NSObject.m: NSAllocateObject() raise exception if passed
something other than a class to allocate an instance of.
2002-05-02 Richard Frith-Macdonald <rfm@gnu.org> 2002-05-02 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -437,10 +437,11 @@ GSFinalize(void* object, void* data)
inline NSObject * inline NSObject *
NSAllocateObject(Class aClass, unsigned extraBytes, NSZone *zone) NSAllocateObject(Class aClass, unsigned extraBytes, NSZone *zone)
{ {
id new = nil; id new;
int size = aClass->instance_size + extraBytes; int size;
NSCAssert((CLS_ISCLASS(aClass)), @"Bad class for new object"); NSCAssert((CLS_ISCLASS(aClass)), @"Bad class for new object");
size = aClass->instance_size + extraBytes;
if (zone == GSAtomicMallocZone()) if (zone == GSAtomicMallocZone())
{ {
new = NSZoneMalloc(zone, size); new = NSZoneMalloc(zone, size);
@ -522,14 +523,16 @@ NSAllocateObject (Class aClass, unsigned extraBytes, NSZone *zone)
#ifndef NDEBUG #ifndef NDEBUG
extern void GSDebugAllocationAdd(Class c, id o); extern void GSDebugAllocationAdd(Class c, id o);
#endif #endif
id new = nil; id new;
int size = aClass->instance_size + extraBytes + sizeof(struct obj_layout); int size;
if (CLS_ISCLASS (aClass))
NSCAssert((CLS_ISCLASS(aClass)), @"Bad class for new object");
size = aClass->instance_size + extraBytes + sizeof(struct obj_layout);
if (zone == 0)
{ {
if (zone == 0) zone = NSDefaultMallocZone();
zone = NSDefaultMallocZone();
new = NSZoneMalloc(zone, size);
} }
new = NSZoneMalloc(zone, size);
if (new != nil) if (new != nil)
{ {
memset (new, 0, size); memset (new, 0, size);
@ -589,10 +592,12 @@ GSObjCZone(NSObject *object)
inline NSObject * inline NSObject *
NSAllocateObject (Class aClass, unsigned extraBytes, NSZone *zone) NSAllocateObject (Class aClass, unsigned extraBytes, NSZone *zone)
{ {
id new = nil; id new;
int size = aClass->instance_size + extraBytes; int size;
if (CLS_ISCLASS (aClass))
new = NSZoneMalloc (zone, size); NSCAssert((CLS_ISCLASS(aClass)), @"Bad class for new object");
size = aClass->instance_size + extraBytes;
new = NSZoneMalloc (zone, size);
if (new != nil) if (new != nil)
{ {
memset (new, 0, size); memset (new, 0, size);