gnustep-dev
[Top][All Lists]
Advanced

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

Methods as dictionary keys using invocation


From: Stefan Urbanek
Subject: Methods as dictionary keys using invocation
Date: Sun, 06 Jul 2003 11:53:37 +0200

Hi,

I have an object (prototype) containing a dictionary. I want to access keys in 
that dictionary using messages. So if i do:
   [proto someKey];
it is analogous to:
   [[proto dictionary] objectForKey:@"someKey"];

However, this used to work some time ago, but now I am getting:
   vacall: va_start type 6 and va_return type 14 disagree.

Problem is, that when i have some (any) class that has a method with same name as 
a key in the dictionary, but has other types, then i get the error message. For 
example, if there is -(int)someKey, the [proto someKey] will fail. If i create a 
protocol (note that i want to avoid this) with method -(id)someKey AND cast proto 
to (id<TheProtocol), then it works.

The two methods in my Prototype class looks like:

- (void)forwardInvocation:(NSInvocation *)invocation
{
   NSString *varName;
   id        val;
   varName = NSStringFromSelector([invocation selector]);
   val = [attributes objectForKey:varName];
   [invocation setReturnValue:&val];
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel
{
   NSMethodSignature *signature = nil;
   signature = [super methodSignatureForSelector:sel];
   if(!signature)
   {
       char *name;
       char *ptr;
       char *types;
       int   argc = 0;

       types = GSTypesFromSelector(sel);
       if(!types || !strcmp(types, "@address@hidden:4"))
       {
           name = GSNameFromSelector(sel);
           ptr = name;

           while(*ptr)
           {
               if(*ptr == ':')
               {
                   argc ++;
               }
               ptr++;
           }
           if(argc == 0)
           {
               sel = GSSelectorFromNameAndTypes(name, "@address@hidden:4");
               types = GSTypesFromSelector(sel);
               signature = [NSMethodSignature signatureWithObjCTypes:types];
           }
       }
   }
   return signature;
}

I admit, that this code is not clean, it is first attempt.

I was consulting this with Alex. GCC generates type information at compilation 
time. From this it seems to me, that invocation is using typed selector 
information generated from GCC, not from NSMethodSignature i have returned. 
(Note, that this used to work).

Thing is that any solution requiring definition of protocols or requiring using 
names of keys that do not conflict with defined methods is not acceptable.

What is wrong with the code?

Thanks for any help,

Stefan Urbanek
--
http://urbanek.host.sk

First they ignore you, then they laugh at you, then they fight you, then you 
win.
- Mahatma Gandhi






reply via email to

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