discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Encode and Decode an NSMapTableKeyCallBacks: expected struct and got


From: Richard Frith-Macdonald
Subject: Re: Encode and Decode an NSMapTableKeyCallBacks: expected struct and got unsigned int
Date: Fri, 16 Apr 2004 06:35:39 +0100


On 13 Apr 2004, at 10:12, Philip Mötteli wrote:

Hi


I encode some information about a MapTable:

        - (void)ecnodeWithCoder:(NSCoder *)aCoder
        {
                …
[aCoder encodeValueOfObjCType:@encode(NSMapTableKeyCallBacks) at:&keyCallBack];
                …
        }


I decode it like this:

        - initWithCoder:(NSCoder *)aCoder
        {
                …
[aCoder decodeValueOfObjCType:@encode(NSMapTableKeyCallBacks) at:&keyCallBack];
                …
        }


This decoding translates into the following call of the unarchiver's decodeValueOfObjCType:

- (void)decodeValueOfObjCType:"{_NSMapTableKeyCallBacks=^?^?^?^?^?^v}" at:0x…


During decoding, the typeCheck function is called:

        typeCheck(t1='{', t2=6 '\006')


Which in turn looks up its parameters in the type map:

        type_map[('\006' & _GSC_MASK)] != '{'


Unfortunately this map doesn't give a satisfying value back:

        Exception: NSInternalInconsistencyException
        REASON: expected struct and got unsigned int


Is this a bug? I mean, I can't change a lot here. Everything is handled by the system.

I don't understand how you are managing to get an exception decoding ... because you should have got an exception when trying to encode the structure!

You can't encode pointers to functions, and a map table callbacks structure contains mostly pointers to functions. These appear in the encoding specification as '^?' sequences ... meaning pointers to unknown items.

Coding/decoding is supposed to store the thing pointed to by a pointer rather than the value of the pointer itsself (because it generally it makes no sense to try to store actual pointers in an archive since when they were restored in another process the things they pointed to would not exist) ... but where the size of the thing pointed to (in this case a function) is unknown, it cannot be stored in the archive, and an exception should be raised.

So ... not a bug, you are just trying to do something that can't reasonably be done. Probably you need to write some custom codein your application to archive a string (or some other object) which describes the information you actually want to store/retrieve,
rather than trying to archive the map table directly.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]