mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 19:10:48 +00:00
Minor memory management fixes.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@17272 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
25a26694d5
commit
d125ffeb05
3 changed files with 69 additions and 49 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2003-07-21 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSFileWrapper.m: Tidy initialisation and fix leak in
|
||||||
|
dealloc.
|
||||||
|
* Source/NSTextAttachment.m: ditto.
|
||||||
|
|
||||||
2003-07-19 Adam Fedor <fedor@gnu.org>
|
2003-07-19 Adam Fedor <fedor@gnu.org>
|
||||||
|
|
||||||
* GNUmakefile: Build Documentation if doc=yes (yes by default).
|
* GNUmakefile: Build Documentation if doc=yes (yes by default).
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include <Foundation/NSFileManager.h>
|
#include <Foundation/NSFileManager.h>
|
||||||
#include <Foundation/NSArchiver.h>
|
#include <Foundation/NSArchiver.h>
|
||||||
#include <Foundation/NSDebug.h>
|
#include <Foundation/NSDebug.h>
|
||||||
|
#include <Foundation/NSAutoreleasePool.h>
|
||||||
|
|
||||||
@implementation NSFileWrapper
|
@implementation NSFileWrapper
|
||||||
|
|
||||||
|
@ -49,59 +50,65 @@
|
||||||
// Init instance of directory type
|
// Init instance of directory type
|
||||||
- (id) initDirectoryWithFileWrappers: (NSDictionary*)docs
|
- (id) initDirectoryWithFileWrappers: (NSDictionary*)docs
|
||||||
{
|
{
|
||||||
NSEnumerator *enumerator;
|
self = [super init];
|
||||||
id key;
|
if (self != nil)
|
||||||
NSFileWrapper *wrapper;
|
|
||||||
[super init];
|
|
||||||
|
|
||||||
_wrapperType = GSFileWrapperDirectoryType;
|
|
||||||
ASSIGN(_wrapperData, [NSMutableDictionary dictionaryWithCapacity: [docs count]]);
|
|
||||||
|
|
||||||
enumerator = [docs keyEnumerator];
|
|
||||||
while ((key = [enumerator nextObject]))
|
|
||||||
{
|
{
|
||||||
wrapper = (NSFileWrapper*)[docs objectForKey: key];
|
NSEnumerator *enumerator;
|
||||||
|
id key;
|
||||||
|
NSFileWrapper *wrapper;
|
||||||
|
|
||||||
if (![wrapper preferredFilename])
|
_wrapperType = GSFileWrapperDirectoryType;
|
||||||
[wrapper setPreferredFilename: key];
|
_wrapperData
|
||||||
|
= [[NSMutableDictionary alloc] initWithCapacity: [docs count]];
|
||||||
|
|
||||||
[_wrapperData setObject: wrapper forKey: key];
|
enumerator = [docs keyEnumerator];
|
||||||
|
while ((key = [enumerator nextObject]) != nil)
|
||||||
|
{
|
||||||
|
wrapper = (NSFileWrapper*)[docs objectForKey: key];
|
||||||
|
|
||||||
|
if (![wrapper preferredFilename])
|
||||||
|
{
|
||||||
|
[wrapper setPreferredFilename: key];
|
||||||
|
}
|
||||||
|
[_wrapperData setObject: wrapper forKey: key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init instance of regular file type
|
// Init instance of regular file type
|
||||||
- (id) initRegularFileWithContents: (NSData*)data
|
- (id) initRegularFileWithContents: (NSData*)data
|
||||||
{
|
{
|
||||||
[super init];
|
self = [super init];
|
||||||
|
if (self != nil)
|
||||||
_wrapperData = [data copyWithZone: [self zone]];
|
{
|
||||||
_wrapperType = GSFileWrapperRegularFileType;
|
_wrapperData = [data copyWithZone: [self zone]];
|
||||||
|
_wrapperType = GSFileWrapperRegularFileType;
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init instance of symbolic link type
|
// Init instance of symbolic link type
|
||||||
- (id) initSymbolicLinkWithDestination: (NSString*)path
|
- (id) initSymbolicLinkWithDestination: (NSString*)path
|
||||||
{
|
{
|
||||||
[super init];
|
self = [super init];
|
||||||
|
if (self != nil)
|
||||||
_wrapperData = [path copyWithZone: [self zone]];
|
{
|
||||||
_wrapperType = GSFileWrapperSymbolicLinkType;
|
_wrapperData = [path copyWithZone: [self zone]];
|
||||||
|
_wrapperType = GSFileWrapperSymbolicLinkType;
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init an instance from the file,
|
/**
|
||||||
// directory, or symbolic link at path.
|
* Init an instance from the file, directory, or symbolic link at path.<br />
|
||||||
// This can create a tree of instances
|
* This can create a tree of instances with a directory instance at the top
|
||||||
// with a directory instance at the top
|
*/
|
||||||
|
|
||||||
- (id) initWithPath: (NSString*)path
|
- (id) initWithPath: (NSString*)path
|
||||||
{
|
{
|
||||||
NSFileManager *fm = [NSFileManager defaultManager];
|
CREATE_AUTORELEASE_POOL(arp);
|
||||||
NSString *fileType;
|
NSFileManager *fm = [NSFileManager defaultManager];
|
||||||
|
NSString *fileType;
|
||||||
|
|
||||||
NSDebugLLog(@"NSFileWrapper", @"initWithPath: %@", path);
|
NSDebugLLog(@"NSFileWrapper", @"initWithPath: %@", path);
|
||||||
|
|
||||||
|
@ -113,20 +120,22 @@
|
||||||
fileType = [[self fileAttributes] fileType];
|
fileType = [[self fileAttributes] fileType];
|
||||||
if ([fileType isEqualToString: @"NSFileTypeDirectory"])
|
if ([fileType isEqualToString: @"NSFileTypeDirectory"])
|
||||||
{
|
{
|
||||||
NSString *filename;
|
NSString *filename;
|
||||||
NSMutableArray *fileWrappers = [NSMutableArray new];
|
NSMutableArray *fileWrappers = [NSMutableArray array];
|
||||||
NSArray *filenames = [fm directoryContentsAtPath: path];
|
NSArray *filenames = [fm directoryContentsAtPath: path];
|
||||||
NSEnumerator *enumerator = [filenames objectEnumerator];
|
NSEnumerator *enumerator = [filenames objectEnumerator];
|
||||||
|
|
||||||
while ((filename = [enumerator nextObject]))
|
while ((filename = [enumerator nextObject]) != nil)
|
||||||
{
|
{
|
||||||
[fileWrappers addObject:
|
NSFileWrapper *w;
|
||||||
AUTORELEASE([[NSFileWrapper alloc] initWithPath:
|
|
||||||
[path stringByAppendingPathComponent: filename]])];
|
w = [[NSFileWrapper alloc] initWithPath:
|
||||||
|
[path stringByAppendingPathComponent: filename]];
|
||||||
|
[fileWrappers addObject: w];
|
||||||
|
RELEASE(w);
|
||||||
}
|
}
|
||||||
self = [self initDirectoryWithFileWrappers:
|
self = [self initDirectoryWithFileWrappers:
|
||||||
[NSDictionary dictionaryWithObjects: fileWrappers forKeys: filenames]];
|
[NSDictionary dictionaryWithObjects: fileWrappers forKeys: filenames]];
|
||||||
RELEASE(fileWrappers);
|
|
||||||
}
|
}
|
||||||
else if ([fileType isEqualToString: @"NSFileTypeRegular"])
|
else if ([fileType isEqualToString: @"NSFileTypeRegular"])
|
||||||
{
|
{
|
||||||
|
@ -138,7 +147,7 @@
|
||||||
self = [self initSymbolicLinkWithDestination:
|
self = [self initSymbolicLinkWithDestination:
|
||||||
[fm pathContentOfSymbolicLinkAtPath: path]];
|
[fm pathContentOfSymbolicLinkAtPath: path]];
|
||||||
}
|
}
|
||||||
|
RELEASE(arp);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,6 +172,7 @@
|
||||||
TEST_RELEASE(_preferredFilename);
|
TEST_RELEASE(_preferredFilename);
|
||||||
TEST_RELEASE(_wrapperData);
|
TEST_RELEASE(_wrapperData);
|
||||||
TEST_RELEASE(_iconImage);
|
TEST_RELEASE(_iconImage);
|
||||||
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -271,23 +271,27 @@
|
||||||
|
|
||||||
@implementation NSTextAttachment
|
@implementation NSTextAttachment
|
||||||
|
|
||||||
- (id)init
|
- (id) init
|
||||||
{
|
{
|
||||||
return [self initWithFileWrapper: nil];
|
return [self initWithFileWrapper: nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
DESTROY(_fileWrapper);
|
DESTROY(_fileWrapper);
|
||||||
DESTROY(_cell);
|
DESTROY(_cell);
|
||||||
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithFileWrapper:(NSFileWrapper *)fileWrapper
|
- (id) initWithFileWrapper:(NSFileWrapper *)fileWrapper
|
||||||
{
|
{
|
||||||
ASSIGN(_fileWrapper, fileWrapper);
|
self = [super init];
|
||||||
_cell = [[NSTextAttachmentCell alloc ] init];
|
if (self != nil)
|
||||||
[_cell setAttachment: self];
|
{
|
||||||
|
ASSIGN(_fileWrapper, fileWrapper);
|
||||||
|
_cell = [[NSTextAttachmentCell alloc ] init];
|
||||||
|
[_cell setAttachment: self];
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue