mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 09:41:15 +00:00
Archiving fix.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@12623 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
e030a18e39
commit
2ffd921a4c
2 changed files with 51 additions and 17 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
2002-02-21 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSValue.m: Fixed bug in archiving NSValue objects ... was
|
||||||
|
creating faulty archives which would crash on unarchiving.
|
||||||
|
If you have any archives created using the buggy code, try to
|
||||||
|
unarchive them by using the previous version of this file but
|
||||||
|
with the RELEASE() of the decoded NSData object removed. This
|
||||||
|
*might* permit archive recovery, though it will cause a memory leak.
|
||||||
|
|
||||||
2002-02-20 Richard Frith-Macdonald <rfm@gnu.org>
|
2002-02-20 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSUser.m: locking erro fixed by Stephen brandon
|
* Source/NSUser.m: locking erro fixed by Stephen brandon
|
||||||
|
|
|
@ -366,7 +366,7 @@ static NSLock *placeholderLock;
|
||||||
- (void) encodeWithCoder: (NSCoder *)coder
|
- (void) encodeWithCoder: (NSCoder *)coder
|
||||||
{
|
{
|
||||||
unsigned size;
|
unsigned size;
|
||||||
char *data;
|
const char *data;
|
||||||
const char *objctype = [self objCType];
|
const char *objctype = [self objCType];
|
||||||
NSMutableData *d;
|
NSMutableData *d;
|
||||||
|
|
||||||
|
@ -378,11 +378,16 @@ static NSLock *placeholderLock;
|
||||||
[self getValue: (void*)data];
|
[self getValue: (void*)data];
|
||||||
d = [NSMutableData new];
|
d = [NSMutableData new];
|
||||||
[d serializeDataAt: data ofObjCType: objctype context: nil];
|
[d serializeDataAt: data ofObjCType: objctype context: nil];
|
||||||
[coder encodeValueOfObjCType: @encode(id) at: &d];
|
size = [d length];
|
||||||
|
[coder encodeValueOfObjCType: @encode(unsigned) at: &size];
|
||||||
|
NSZoneFree(NSDefaultMallocZone(), (void*)data);
|
||||||
|
data = [d bytes];
|
||||||
|
[coder encodeArrayOfObjCType: @encode(unsigned char) count: size at: data];
|
||||||
RELEASE(d);
|
RELEASE(d);
|
||||||
NSZoneFree(NSDefaultMallocZone(), data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@class NSDataStatic; // Neede for decoding.
|
||||||
|
|
||||||
- (id) initWithCoder: (NSCoder *)coder
|
- (id) initWithCoder: (NSCoder *)coder
|
||||||
{
|
{
|
||||||
char type[64];
|
char type[64];
|
||||||
|
@ -458,9 +463,13 @@ static NSLock *placeholderLock;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NSData *d;
|
static NSData *d = nil;
|
||||||
unsigned cursor = 0;
|
unsigned cursor = 0;
|
||||||
|
|
||||||
|
if (d == nil)
|
||||||
|
{
|
||||||
|
d = [NSDataStatic allocWithZone: NSDefaultMallocZone()];
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* For performance, decode small values directly onto the stack,
|
* For performance, decode small values directly onto the stack,
|
||||||
* For larger values we allocate and deallocate heap space.
|
* For larger values we allocate and deallocate heap space.
|
||||||
|
@ -470,26 +479,42 @@ static NSLock *placeholderLock;
|
||||||
{
|
{
|
||||||
unsigned char data[size];
|
unsigned char data[size];
|
||||||
|
|
||||||
[coder decodeValueOfObjCType: @encode(id) at: &d];
|
[coder decodeValueOfObjCType: @encode(unsigned) at: &size];
|
||||||
|
{
|
||||||
|
unsigned char serialized[size];
|
||||||
|
|
||||||
|
[coder decodeArrayOfObjCType: @encode(unsigned char)
|
||||||
|
count: size
|
||||||
|
at: (void*)serialized];
|
||||||
|
d = [d initWithBytesNoCopy: (void*)serialized length: size];
|
||||||
[d deserializeDataAt: data
|
[d deserializeDataAt: data
|
||||||
ofObjCType: objctype
|
ofObjCType: objctype
|
||||||
atCursor: &cursor
|
atCursor: &cursor
|
||||||
context: nil];
|
context: nil];
|
||||||
|
}
|
||||||
o = [o initWithBytes: data objCType: objctype];
|
o = [o initWithBytes: data objCType: objctype];
|
||||||
RELEASE(d);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned char *data;
|
void *data;
|
||||||
|
|
||||||
data = (void *)NSZoneMalloc(NSDefaultMallocZone(), size);
|
data = (void *)NSZoneMalloc(NSDefaultMallocZone(), size);
|
||||||
[coder decodeValueOfObjCType: @encode(id) at: &d];
|
[coder decodeValueOfObjCType: @encode(unsigned) at: &size];
|
||||||
|
{
|
||||||
|
void *serialized;
|
||||||
|
|
||||||
|
serialized = (void *)NSZoneMalloc(NSDefaultMallocZone(), size);
|
||||||
|
[coder decodeArrayOfObjCType: @encode(unsigned char)
|
||||||
|
count: size
|
||||||
|
at: serialized];
|
||||||
|
d = [d initWithBytesNoCopy: serialized length: size];
|
||||||
[d deserializeDataAt: data
|
[d deserializeDataAt: data
|
||||||
ofObjCType: objctype
|
ofObjCType: objctype
|
||||||
atCursor: &cursor
|
atCursor: &cursor
|
||||||
context: nil];
|
context: nil];
|
||||||
|
NSZoneFree(NSDefaultMallocZone(), serialized);
|
||||||
|
}
|
||||||
o = [o initWithBytes: data objCType: objctype];
|
o = [o initWithBytes: data objCType: objctype];
|
||||||
RELEASE(d);
|
|
||||||
NSZoneFree(NSDefaultMallocZone(), data);
|
NSZoneFree(NSDefaultMallocZone(), data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue