On 2012-10-14 19:38:21 +0000, Jacob Carlborg <d...@me.com> said:

On 2012-10-11 20:19, Michel Fortin wrote:

Most likely, the object objc_msgSend is called on has been deallocated,
which would mean that windowSendEvent is called with a deallocated
NSWindow object as its first argument.

I found the problem now, it's really embarrassing. I had missed passing the argument of any super call taking one argument:

https://github.com/d-widget-toolkit/dwt-mac/commit/d6674c1074e8a58600cb5052a79b784ae0d3b366

By

the way, that line is half-fishy:

        
super_struct.super_class = cast(objc.Class) OS.objc_msgSend(id, OS.sel_superclass);

It'll work as long as you have only one level of derived classes, and only as long as you don't have a class that overrides the superclass method (which would be weird, I acknowledge). You should be aware of this if you're creating new object classes, especially the first part (the second part is only relevant if you wish to implement some kind of proxy objects).

Theoretically, I think it'd be better to use directly functions from the Objective-C runtime[1], which also avoids the dynamic dispatch overhead of objc_msgSend:

        super_struct.super_class = class_getSuperclass(object_getClass(id));

Note however that this is still not equivalent to calling:

        [super method:arg0];

because this last one gets the class pointer at compile-tome from its static symbol, so there's no overhead at all (and it works with derived classes of derived classes too).

[1]: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html

--


Michel Fortin
michel.for...@michelf.ca
http://michelf.ca/

Reply via email to