[MacRuby] #1485: Using MacRuby to invoke a Obj-C variadic method leads crash
#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 --------------------------------+------------------------------------------- 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> MacRuby <http://macruby.org/>
#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/>
#1485: Using MacRuby to invoke a Obj-C variadic method leads crash --------------------------------+------------------------------------------- Reporter: xareelee@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: blocker | Milestone: Component: MacRuby | Resolution: invalid Keywords: variadic method | --------------------------------+------------------------------------------- Changes (by watson1978@…): * status: new => closed * resolution: => invalid Comment: Please add NS_REQUIRES_NIL_TERMINATION into declaration of Foo.log. [[BR]] And create Bridge Support file using gen_bridge_metadata command. MacRuby cannot know without Bridge Support file what Foo.log method has variable length arguments. I tried your code with https://gist.github.com/2178472 Please see it :) -- Ticket URL: <http://www.macruby.org/trac/ticket/1485#comment:2> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby