git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@17804 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2003-10-08 16:26:59 +00:00
parent 2c18a5ea43
commit c4b038113d
4 changed files with 127 additions and 7 deletions

View file

@ -12,7 +12,8 @@
* Source/NSArray.m: Fix memory leak initialising from coder.
* Source/NSCountedSet.m: ditto
* Source/NSSet.m: ditto
Memory leak fixes adapted from patch by <Roland.Schwingel@onevision.de>
* Source/NSDebug.m: Hook to change allocation checking functions.
Memory fixes adapted from patch by <Roland.Schwingel@onevision.de>
2003-10-07 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -45,6 +45,7 @@
* GSDebugAllocationClassList()
* GSDebugAllocationList()
* GSDebugAllocationListAll()
* GSSetDebugAllocationFunctions()
*
* When the previous functions have allowed you to find a memory leak,
* and you know that you are leaking objects of class XXX, but you are
@ -154,6 +155,14 @@ GS_EXPORT NSString* GSDebugFunctionMsg(const char *func, const char *file,
*/
GS_EXPORT NSString* GSDebugMethodMsg(id obj, SEL sel, const char *file,
int line, NSString *fmt);
/**
* This functions allows to set own function backcalls for debugging allocation
* of objects. Useful if you intend to write your own objectalloc.
*/
GS_EXPORT void GSSetDebugAllocationFunctions(void (*newAddObjectFunc)(Class c, id o),
void (*newRemoveObjectFunc)(Class c, id o));
#endif
/**

View file

@ -3481,8 +3481,39 @@ static NSCharacterSet *tokenSet = nil;
- (NSString*) contentSubtype
{
GSMimeHeader *hdr = [self headerNamed: @"content-type"];
NSString *val = nil;
return [hdr objectForKey: @"Subtype"];
if (hdr != nil)
{
val = [hdr objectForKey: @"Subtype"];
if (val == nil)
{
val = [hdr value];
if (val != nil)
{
NSRange r;
r = [val rangeOfString: @"/"];
if (r.length > 0)
{
val = [val substringFromIndex: r.location + 1];
r = [val rangeOfString: @"/"];
if (r.length > 0)
{
val = [val substringToIndex: r.location];
}
val = [val stringByTrimmingSpaces];
[hdr setObject: val forKey: @"Subtype"];
}
else
{
val = nil;
}
}
}
}
return val;
}
/**
@ -3491,8 +3522,30 @@ static NSCharacterSet *tokenSet = nil;
- (NSString*) contentType
{
GSMimeHeader *hdr = [self headerNamed: @"content-type"];
NSString *val = nil;
return [hdr objectForKey: @"Type"];
if (hdr != nil)
{
val = [hdr objectForKey: @"Type"];
if (val == nil)
{
val = [hdr value];
if (val != nil)
{
NSRange r;
r = [val rangeOfString: @"/"];
if (r.length > 0)
{
val = [val substringToIndex: r.location];
val = [val stringByTrimmingSpaces];
}
[hdr setObject: val forKey: @"Type"];
}
}
}
return val;
}
/**

View file

@ -62,6 +62,12 @@ static NSLock *uniqueLock;
static const char* _GSDebugAllocationList(BOOL difference);
static const char* _GSDebugAllocationListAll(void);
void _GSDebugAllocationAdd(Class c, id o);
void _GSDebugAllocationRemove(Class c, id o);
void (*_GSDebugAllocationAddFunc)(Class c, id o) = _GSDebugAllocationAdd;
void (*_GSDebugAllocationRemoveFunc)(Class c, id o) = _GSDebugAllocationRemove;
@interface GSDebugAlloc : NSObject
+ (void) initialize;
+ (void) _becomeThreaded: (NSNotification*)notification;
@ -92,6 +98,37 @@ static const char* _GSDebugAllocationListAll(void);
@end
/**
* This functions allows to set own function backcalls for debugging allocation
* of objects. Useful if you intend to write your own objectalloc.
*/
void
GSSetDebugAllocationFunctions(void (*newAddObjectFunc)(Class c, id o),
void (*newRemoveObjectFunc)(Class c, id o))
{
if (uniqueLock != nil)
{
[uniqueLock lock];
}
if (newAddObjectFunc && newRemoveObjectFunc)
{
_GSDebugAllocationAddFunc = newAddObjectFunc;
_GSDebugAllocationRemoveFunc = newRemoveObjectFunc;
}
else
{
// Back to default
_GSDebugAllocationAddFunc = _GSDebugAllocationAdd;
_GSDebugAllocationRemoveFunc = _GSDebugAllocationRemove;
}
if (uniqueLock != nil)
{
[uniqueLock unlock];
}
}
/**
* This function activates or deactivates object allocation debugging.<br />
* Returns the previous state.<br />
@ -189,6 +226,12 @@ GSDebugAllocationActiveRecordingObjects(Class c)
void
GSDebugAllocationAdd(Class c, id o)
{
(*_GSDebugAllocationAddFunc)(c,o);
}
void
_GSDebugAllocationAdd(Class c, id o)
{
if (debug_allocation)
{
@ -455,11 +498,15 @@ GSDebugAllocationList(BOOL changeFlag)
return "Debug allocation system is not active!\n";
}
if (uniqueLock != nil)
[uniqueLock lock];
{
[uniqueLock lock];
}
ans = _GSDebugAllocationList(changeFlag);
d = [NSData dataWithBytes: ans length: strlen(ans) + 1];
if (uniqueLock != nil)
[uniqueLock unlock];
{
[uniqueLock unlock];
}
return (const char*)[d bytes];
}
@ -555,11 +602,15 @@ GSDebugAllocationListAll()
return "Debug allocation system is not active!\n";
}
if (uniqueLock != nil)
[uniqueLock lock];
{
[uniqueLock lock];
}
ans = _GSDebugAllocationListAll();
d = [NSData dataWithBytes: ans length: strlen(ans)+1];
if (uniqueLock != nil)
[uniqueLock unlock];
{
[uniqueLock unlock];
}
return (const char*)[d bytes];
}
@ -619,6 +670,12 @@ _GSDebugAllocationListAll(void)
void
GSDebugAllocationRemove(Class c, id o)
{
(*_GSDebugAllocationRemoveFunc)(c,o);
}
void
_GSDebugAllocationRemove(Class c, id o)
{
if (debug_allocation)
{