#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/>