[Issue 9931] Bus error interfacing with C function returning structs with floats

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Apr 14 23:38:56 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9931



--- Comment #4 from Jacob Carlborg <doob at me.com> 2013-04-14 23:38:54 PDT ---
(In reply to comment #3)
> NSRect foo (id screen)
> {
>     alias extern (C) NSRect function (id, SEL) frameFp;
>     auto fp = cast(frameFp) &objc_msgSend_stret;
>     return fp(screen, sel_registerName("visibleFrame".ptr));
> }
> 
> - You omit the pointer to the return value, that might accidently work on some
> ABIs because a hidden pointer to the return value is passed as first argument.

I don't know why it behaves like this but that's how you're supposed to invoke
the function. This is the Objective-C runtime and it's kind of special.

> What's the problem with this?
> 
> NSRect foo(id screen)
> {
>     NSRect res;
>     objc_msgSend_stret(&res, screen, sel_registerName("visibleFrame"));
>     return res;
> }

On Mac OS X 10.6.3 it segfaults. I haven't tried on 10.8.2 yet. It also
segfaults if I cast it to: extern (C) void function (NSRect*, id, SEL).

BTW, the original example doesn't _not_ cause a bus error on Mac OS X 10.6.3.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list