[MacRuby] #1340: Troubles casting a Pointer from void* to something useful
#1340: Troubles casting a Pointer from void* to something useful ------------------------------------+--------------------------------------- Reporter: mrada@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ------------------------------------+--------------------------------------- I've got an odd behavior where I am given a void* from a function, and I try to cast it into something useful, but cannot. The documentation for the function says I should be given a CFStringRef, and so I cast it and try to access it, but it looks like it is jumping right into the data structure. I cannot call CFString functions on the pointer, or first index. If I try #[1], it will segfault, I think trying to figure out what the object is (generated from the example code further down): {{{ 0 libobjc.A.dylib 0x00007fff8200a3e6 object_getClass + 11 1 miniruby 0x00000001000deaa4 rb_objc_convert_immediate + 36 (objc.m:570) 2 miniruby 0x000000010013beb9 rb_vm_dispatch + 9177 (dispatcher.cpp:161) }}} Example code: {{{ framework 'Cocoa' current_keyboard = TISCopyCurrentKeyboardInputSource() name = TISGetInputSourceProperty(current_keyboard, KTISPropertyLocalizedName) p name[0] p name.type name.cast!('^{__CFString}') p name[0] # => NSCFString p name[1] # segfault CFStringGetLength(name) # => segfault CFStringGetLength(name[0]) # => uncaught objective-c exception name.cast!('@') p name[0] # => NSCFString p name[1] # segfault CFStringGetLength(name) # => segfault CFStringGetLength(name[0]) # => uncaught objective-c exception }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/1340> MacRuby <http://macruby.org/>
#1340: Troubles casting a Pointer from void* to something useful ------------------------------------+--------------------------------------- Reporter: mrada@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ------------------------------------+--------------------------------------- Comment(by lsansonetti@…): Sadly that's the only use case that MacRuby's Pointer class does not support. This API is declared as returning a `void *' type, which MacRuby assumes it a pointer to *something*, however here it returns a direct reference to a CFString. The #cast! method allows you to change the type of the object being pointed to, but here what you would need instead is a way to cast the Pointer object itself to something else. Pointer#to_object maybe? -- Ticket URL: <http://www.macruby.org/trac/ticket/1340#comment:1> MacRuby <http://macruby.org/>
#1340: Troubles casting a Pointer from void* to something useful ------------------------------------+--------------------------------------- Reporter: mrada@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: blocker | Milestone: MacRuby 0.11 Component: MacRuby | Resolution: fixed Keywords: | ------------------------------------+--------------------------------------- Changes (by lsansonetti@…): * status: new => closed * resolution: => fixed * milestone: => MacRuby 0.11 Comment: Added as https://github.com/MacRuby/MacRuby/commit/e9946381b0021740448845af500bed4e15... -- Ticket URL: <http://www.macruby.org/trac/ticket/1340#comment:2> MacRuby <http://macruby.org/>
#1340: Troubles casting a Pointer from void* to something useful ------------------------------------+--------------------------------------- Reporter: mrada@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: blocker | Milestone: MacRuby 0.11 Component: MacRuby | Resolution: fixed Keywords: | ------------------------------------+--------------------------------------- Comment(by mrada@…): It works! [[Image(http://cdn0.knowyourmeme.com/i/000/106/887/original/backpain-1292835351.jpg)]] -- Ticket URL: <http://www.macruby.org/trac/ticket/1340#comment:3> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby