I dug a bit into the basics of a new Xojo Framework-compatible MacOS X library and got stuck on the Objective C Runtime. Many things are really blazing fast there, and as I never really got accustomed to the Introspection class I set one up using ObjC features. This works nicely so far, but: Could somebody explain me how to read the structure of a objc_method_description? Is that two pointers to CStrings or what?
(If you are interested, tell me and Ill upload the project.)
a selector is not a normal pointer there. Use sel_getName function to query it’s text.
by the way, directly reading in some data structures may give trouble in future.
I’d probably define the structure like this:
name As Ptr // opaque SEL type, use sel_getName to get it as a CString
type As CString
You would then call method_getDescription like this:
Declare Function method_getDescription Lib "/usr/lib/libobjc.dylib" (m As Ptr) As Ptr
Dim descriptionPtr As Ptr = method_getDescription(myMethodPtr)
If descriptionPtr <> Nil Then
Dim description As objc_method_description = descriptionPtr.objc_method_description
// do stuff
Thanks a lot, you two!
What troubles do you mean, Christian? Is there any announcement about deprecating the ObjC framework?
and is it really sel_getName? Makes completely sense, but I still get results that aren’t legible at all.
selectors are not simply string pointers. You pass them like pointers and sel_getName function gives a CString for them.
It’s not deprecated, but for 64bit part of the objc-runtime requires to use accessor functions instead of looking in structures.
Thanks again, Christian!
Somehow this one part doesn’t want to work. Still looks like an encoding error.
But while the rest is doing nicely and I am amazed how fast although I convert a lot between the data types : thanks for the warning again. I check Apple’s docs on each implementation step to see if some deprecation or advice is given and don’t implement those that Apple suggests better not to use.
But another question: Memory is rising fast when I inspect some classes. For some ObjC methods delivering arrays Apple has noted
But what and where is free? I tried to dealloc the ptr I received, and in one case it works, in another one it crashed sometimes.
“free” is in the C standard library. An example:
[code]Declare Sub free Lib “libSystem.dylib” (p As Ptr)
Declare Function objc_copyClassList Lib “libobjc.dylib” (ByRef outCount As UInt32) As Ptr
Dim count As UInt32
Dim mb As MemoryBlock = objc_copyClassList(count)
For i As Integer = 0 To count - 1
Dim p As Ptr = mb.Ptr(i * 4)
// do something with the class p points to
Thanks a lot, Eli!
I finally got the description working too. I understood the docs as if the method would deliver a structure like many AppKit methods do. But it’s more or less the ptr to a struct. Phew!
And having built the method, I found it delivers the same values I already got in form of two independent properties
Oh! Is there a difference in how Core.Memoryblocks are handled compared to the old ones? When I try to call the method like you described on a xojo.core.MB, the compiler tells me it expected a ptr, not a MB.
Will this work on an immutable MB anyway?
I think you need to use the MutableMemoryBlock instead. You can pass it into a declare using MB.Data.
Oh thanks again! I overread that part of the docs
but freeing doesn’t work for MBs as well as MMBs. Okay, guess I’ll have to live with a little leak probably for the next time.