[MacRuby] #1448: Pointer#to_object causes a segmentation fault
#1448: Pointer#to_object causes a segmentation fault --------------------------------+------------------------------------------- Reporter: l.rieder@… | Owner: lsansonetti@… Type: defect | Status: new Priority: critical | Milestone: Component: MacRuby | Keywords: segfault --------------------------------+------------------------------------------- I am running this bit of code: {{{ $ macruby -e "framework 'cocoa'; p NSJSONSerialization.dataWithJSONObject({}, options: 0, error: nil).bytes.to_object"Segmentation Segmentation fault: 11 }}} Expected output would be a String like "{}". It results in a segmentation fault. Here is the log https://gist.github.com/1759848. I am running macruby-nightly. -- Ticket URL: <http://www.macruby.org/trac/ticket/1448> MacRuby <http://macruby.org/>
#1448: Pointer#to_object causes a segmentation fault --------------------------------+------------------------------------------- Reporter: l.rieder@… | Owner: lsansonetti@… Type: defect | Status: new Priority: critical | Milestone: Component: MacRuby | Keywords: segfault --------------------------------+------------------------------------------- Comment(by watson1978@…): NSData.bytes returns variable of void*. I guess that It is difficult what knows actual variable size. btw, if you serialize JSON, try following. {{{ framework 'cocoa' data = NSJSONSerialization.dataWithJSONObject({:foo => 42}, options: 0, error: nil) json = NSJSONSerialization.JSONObjectWithData(data, options:0, error:nil) p json }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/1448#comment:1> MacRuby <http://macruby.org/>
#1448: Pointer#to_object causes a segmentation fault --------------------------------+------------------------------------------- Reporter: l.rieder@… | Owner: lsansonetti@… Type: defect | Status: new Priority: critical | Milestone: Component: MacRuby | Keywords: segfault --------------------------------+------------------------------------------- Comment(by eloy.de.enige@…): I think you need: {{{ irb(main):010:0> data = NSJSONSerialization.dataWithJSONObject({:foo => 42}, options: 0, error: nil) => #<NSConcreteData:0x40073fe40> irb(main):011:0> NSString.alloc.initWithData(data, encoding:NSUTF8StringEncoding) => "{\"foo\":42}" }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/1448#comment:2> MacRuby <http://macruby.org/>
#1448: Pointer#to_object causes a segmentation fault --------------------------------+------------------------------------------- Reporter: l.rieder@… | Owner: lsansonetti@… Type: defect | Status: new Priority: critical | Milestone: Component: MacRuby | Keywords: segfault --------------------------------+------------------------------------------- Comment(by eloy.de.enige@…): Oops, use NSMutableString, not NSString, otherwise this will lead to problems when other Ruby code that uses multi_json expects the string to be mutable. -- Ticket URL: <http://www.macruby.org/trac/ticket/1448#comment:3> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby