Handle data disappearing out from underneath me
Handle data disappearing out from underneath me
- Subject: Handle data disappearing out from underneath me
- From: Ken Tozier <email@hidden>
- Date: Sun, 8 Apr 2007 10:24:04 -0400
Hi
My plugin converts NSObjects to handles for storage in a parent
application and am finding that the data the handle points to seems
to disappear out from underneath me. When I fetch the handle from the
parent app at a later time, the handle itself isn't null, but the
data it pointed to is.
Here's how I'm packing the NSObjects into a handle:
BOOL UtilSlugHandleFromNSObject(id inSlug, Handle *result)
{
BOOL exeOK = NO;
NSString *err = nil;
NSData *data;
data = [NSPropertyListSerialization dataFromPropertyList: inSlug
format: NSPropertyListXMLFormat_v1_0
errorDescription: &err];
*result = NULL;
if (err == nil)
{
PtrToHand([data bytes], result, [data length]);
exeOK = YES;
}
else
NSLog(@"Error: %@ serializing slug: %@", err, inSlug);
return exeOK;
}
And here's how I'm pulling the NSObjects back out of the handles
id UtilNSObjectFromSlugHandle(Handle inSlugHandle)
{
id result = nil;
if (inSlugHandle != NULL)
{
NSString *err = nil;
HLock(inSlugHandle);
NSData *slugData = [NSData dataWithBytes: inSlugHandle length:
GetHandleSize(inSlugHandle)];
HUnlock(inSlugHandle);
NSLog(@"In: UtilNSObjectFromSlugHandle, slugData: %@, slugData
length: %i", slugData, [slugData length]);
result = [NSPropertyListSerialization
propertyListFromData: slugData
mutabilityOption: NSPropertyListMutableContainersAndLeaves
format: NULL
errorDescription: &err];
if (err != nil)
NSLog(@"Error: %@ while attempting to deserilize slug: %@", err,
slugData);
}
return result;
}
The NSLog for slugData in UtilNSObjectFromSlugHandle above displays a
data chunk that is mostly filled with ff with a valid length.
Being an autoreleased NSData probably has something to do with it but
I would have thought that PtrToHand did something internally to
prevent the deletion of the data it points to. Is there some other
way I can prevent these disappearing handles?
Thanks for any help
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden