[MacRuby] #1485: Using MacRuby to invoke a Obj-C variadic method leads crash
MacRuby
ruby-noreply at macosforge.org
Fri Mar 23 21:17:59 PDT 2012
#1485: Using MacRuby to invoke a Obj-C variadic method leads crash
--------------------------------+-------------------------------------------
Reporter: xareelee@… | Owner: lsansonetti@…
Type: defect | Status: new
Priority: blocker | Milestone:
Component: MacRuby | Keywords: variadic method
--------------------------------+-------------------------------------------
Description changed by watson1978@…:
Old description:
> I got an Obj-C class like this:
> ============================
> @interface Foo
> /// this method would print the variables.
> + (void) log: (id) firstObj, ...; // Obj-C variadic method. Using nil
> at the end of args.
> @end
>
> @implementation Foo
> + (void) log: (id) firstObj, ...{
> va_list ap
> va_start (ap, firstObj)
> for (id obj = firstObj; obj != nil; obj = va_args(ap, id) ){
> NSLog(@"%@", obj);
> }
> va_end (ap)
> }
> @end
> ============================
>
> If I call the method using Obj-C like this:
> [Foo log: @"1", @"2", @"3", nil];
>
> The console would print:
> => 1
> => 2
> => 3
>
> But if I call the method using MacRuby like this:
> Foo.log ("1", "2", "3", nil)
>
> The Console would print:
> => 1
> => 1 // Yes, it prints the first argument twice!!
> then crash!
>
> Did I do it wrong? Or it is a bug there?
New description:
I got an Obj-C class like this:
============================
{{{
@interface Foo
/// this method would print the variables.
+ (void) log: (id) firstObj, ...; // Obj-C variadic method. Using nil
at the end of args.
@end
@implementation Foo
+ (void) log: (id) firstObj, ...{
va_list ap
va_start (ap, firstObj)
for (id obj = firstObj; obj != nil; obj = va_args(ap, id) ){
NSLog(@"%@", obj);
}
va_end (ap)
}
@end
}}}
============================
If I call the method using Obj-C like this:
[Foo log: @"1", @"2", @"3", nil];
The console would print:
{{{
=> 1
=> 2
=> 3
}}}
But if I call the method using MacRuby like this:
Foo.log ("1", "2", "3", nil)
The Console would print:
{{{
=> 1
=> 1 // Yes, it prints the first argument twice!!
}}}
then crash!
Did I do it wrong? Or it is a bug there?
--
--
Ticket URL: <http://www.macruby.org/trac/ticket/1485#comment:1>
MacRuby <http://macruby.org/>
More information about the macruby-tickets
mailing list