discuss-gnustep
[Top][All Lists]
Advanced

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

Re: ObjectiveC runtime question: easy solution!


From: Lloyd Dupont
Subject: Re: ObjectiveC runtime question: easy solution!
Date: Fri, 20 May 2005 14:50:57 +1000

After lots of test, (and some experimental ASM which I quickly discard for too dim and old and weak skills) I found this nice solution build from idea from the sources: (However an ASM version with a jump would have been much more reliable (regarding argument forwarding, particularly with variable argument list), simple and fast):
-----------------------
DLL_EXPORT retval_t objcsharp_msg_send(id obj, const char* msg, ...)
{
void* args = __builtin_apply_args();
SEL sel = sel_get_uid(msg);
Method_t m = class_get_instance_method (obj->class_pointer, sel);
if(m != NULL)
{
 __builtin_return( __builtin_apply(
  (void(*)()) m->method_imp,
  args,
  method_get_sizeof_arguments(m)
 ));
}
else
{
       SEL frwd_sel = sel_get_any_uid("forwardInvocation:");
    if(sel && __objc_responds_to (obj, frwd_sel))
    {
NSInvocation * i = [[NSInvocation alloc] initWithArgframe: args selector: sel];
     [i autorelease];
     [obj forwardInvocation:i];
    }
    else
    {
objc_error (obj, OBJC_ERR_UNIMPLEMENTED, "ObjectiveC Runtime error, unimplemented method: %s\n", msg);
    }
 return 0;
}
}
-----------------------

for info here was the kind of ASM I was looking at:
---- pseudo ASM (failing) ------
retval_t objc_msgSend(id obj, SEL sel, ...)
{
   asm(" pusha \r\n");
   IMP imp = objc_msg_lookup(obj, sel);
   asm(" popa \r\n");
   asm( "longjmp %0 \r\n" : "=p" (imp) );
}
---------------------------------




----- Original Message ----- From: "Adam Fedor" <fedor@doc.com>
To: "Lloyd Dupont" <lloyd@nova-mind.com>
Cc: "GNUstep Discussion" <discuss-gnustep@gnu.org>
Sent: Friday, May 20, 2005 12:59 AM
Subject: Re: ObjectiveC runtime question: easy solution!


Possible. __builtin_apply isn't really supported by the gcc team, but
if you are just working on windows, you only have to deal with making
sure it works on that platform.


On May 19, 2005, at 1:01 AM, Lloyd Dupont wrote:

I could write something like that:

DLL_EXPORT void* objcsharp_msg_send(id obj, SEL sel, ...)
{
void* args = __builtin_apply_args();
IMP imp = objc_msg_lookup(obj, sel);
size_t argsize = 20 * sizeof(int);
__builtin_return ( __builtin_apply((void(*)())imp, args, argsize) );
}
I have to look at some code to find the correct value of argsize.
but that's the simpliest solution, by far!

----- Original Message -----
From: Lloyd Dupont
To: Lloyd Dupont ; GNUstep Discussion
Sent: Thursday, May 19, 2005 1:42 PM
Subject: Re: ObjectiveC runtime question

I'm trying something like
DLL_EXPORT void* objcsharp_msg_send(id obj, SEL sel, ...)
{
return objc_msg_sendv(obj, sel, __builtin_apply_args ());
}
but that's apparently not correct.....


----- Original Message -----
From: Lloyd Dupont
To: GNUstep Discussion
Sent: Thursday, May 19, 2005 12:14 PM
Subject: ObjectiveC runtime question

I'm trying to write a binding from an other language to ObjectiveC
I was thinking to relay method call by using something like
objc_msg_sendv(id, SEL, ...);

but it's not exactely the case it's
objc_msg_sendv(id, SEL, arglist_t);

which mean it doesn't work like a vararg function how could I translate that?

I was thinking of something like:

myobjc_msg_send(id obj, SEL mtdh, ...)
{
objc_msg_sendv(obj, mthd, arglist);
}

now the question is how to generate a arglist_t from a va_list?
or any other suggestion?

_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
http://lists.gnu.org/mailman/listinfo/discuss-gnustep
_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
http://lists.gnu.org/mailman/listinfo/discuss-gnustep





reply via email to

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