mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 17:51:01 +00:00
Fix fred's suggestions. Put guard and make more general method the one which is called.
This commit is contained in:
parent
9d252bd5b6
commit
be8980dfb4
2 changed files with 49 additions and 43 deletions
|
@ -88,6 +88,7 @@ extern "C" {
|
||||||
+ (NSData*) archivedDataWithRootObject: (id)anObject;
|
+ (NSData*) archivedDataWithRootObject: (id)anObject;
|
||||||
|
|
||||||
|
|
||||||
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_13,GS_API_LATEST)
|
||||||
/**
|
/**
|
||||||
* Encodes anObject and returns the resulting data object. Allows
|
* Encodes anObject and returns the resulting data object. Allows
|
||||||
* secure coding if specified. Returns an error if an object
|
* secure coding if specified. Returns an error if an object
|
||||||
|
@ -96,6 +97,7 @@ extern "C" {
|
||||||
+ (NSData *) archivedDataWithRootObject: (id)anObject
|
+ (NSData *) archivedDataWithRootObject: (id)anObject
|
||||||
requiringSecureCoding: (BOOL)requiresSecureCoding
|
requiringSecureCoding: (BOOL)requiresSecureCoding
|
||||||
error: (NSError **)error;
|
error: (NSError **)error;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encodes anObject and writes the resulting data ti aPath.
|
* Encodes anObject and writes the resulting data ti aPath.
|
||||||
|
|
|
@ -430,16 +430,27 @@ static NSDictionary *makeReference(unsigned ref)
|
||||||
|
|
||||||
@implementation NSKeyedArchiver
|
@implementation NSKeyedArchiver
|
||||||
|
|
||||||
/*
|
|
||||||
* When I tried this on MacOS 10.3 it encoded the object with the key 'root',
|
|
||||||
* so this implementation does the same.
|
|
||||||
*/
|
|
||||||
+ (NSData *) archivedDataWithRootObject: (id)anObject
|
+ (NSData *) archivedDataWithRootObject: (id)anObject
|
||||||
|
requiringSecureCoding: (BOOL)requiresSecureCoding
|
||||||
|
error: (NSError **)error
|
||||||
|
{
|
||||||
|
NSData *d = nil;
|
||||||
|
|
||||||
|
if (requiresSecureCoding == YES)
|
||||||
|
{
|
||||||
|
if (error != NULL)
|
||||||
|
{
|
||||||
|
*error = [NSError errorWithDomain: @"NSKeyedArchiver"
|
||||||
|
code: 0
|
||||||
|
userInfo: nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
NSMutableData *m = nil;
|
NSMutableData *m = nil;
|
||||||
NSKeyedArchiver *a = nil;
|
NSKeyedArchiver *a = nil;
|
||||||
NSData *d = nil;
|
|
||||||
|
|
||||||
|
error = NULL;
|
||||||
NS_DURING
|
NS_DURING
|
||||||
{
|
{
|
||||||
m = [[NSMutableData alloc] initWithCapacity: 10240];
|
m = [[NSMutableData alloc] initWithCapacity: 10240];
|
||||||
|
@ -456,29 +467,22 @@ static NSDictionary *makeReference(unsigned ref)
|
||||||
DESTROY(a);
|
DESTROY(a);
|
||||||
[localException raise];
|
[localException raise];
|
||||||
}
|
}
|
||||||
NS_ENDHANDLER
|
NS_ENDHANDLER;
|
||||||
|
}
|
||||||
|
|
||||||
return AUTORELEASE(d);
|
return AUTORELEASE(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When I tried this on MacOS 10.3 it encoded the object with the key 'root',
|
||||||
|
* so this implementation does the same.
|
||||||
|
*/
|
||||||
+ (NSData*) archivedDataWithRootObject: (id)anObject
|
+ (NSData*) archivedDataWithRootObject: (id)anObject
|
||||||
requiringSecureCoding: (BOOL)requiresSecureCoding
|
|
||||||
error: (NSError **)error
|
|
||||||
{
|
{
|
||||||
NSData *data = nil;
|
return [self archivedDataWithRootObject: anObject
|
||||||
if (requiresSecureCoding == YES)
|
requiringSecureCoding: NO
|
||||||
{
|
error: NULL];
|
||||||
*error = [NSError errorWithDomain: @"NSKeyedArchiver"
|
|
||||||
code: 0
|
|
||||||
userInfo: nil];
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
error = NULL;
|
|
||||||
data = [self archivedDataWithRootObject: anObject];
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
+ (BOOL) archiveRootObject: (id)anObject toFile: (NSString*)aPath
|
+ (BOOL) archiveRootObject: (id)anObject toFile: (NSString*)aPath
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue