[Issue 9931] Mac OS X ABI not followed when returning structs for extern (C)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Apr 25 23:09:44 PDT 2013


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


Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla at digitalmars.com


--- Comment #21 from Walter Bright <bugzilla at digitalmars.com> 2013-04-25 23:09:41 PDT ---
(In reply to comment #0)
> This code:
> 
> http://pastebin.com/U5XdFfDq

Here's the code from pastebin. I'd prefer small examples to be posted here
rather than linked to.
--------------------------------------------
version (D_LP64)
    alias double CGFloat;
else
    alias float CGFloat;

struct NSRect
{
    NSPoint origin;
    NSSize size;
}

public struct NSPoint {
    public CGFloat x;// = 0.0;
    public CGFloat y;// = 0.0;
}

struct NSSize {
    public CGFloat width;// = 0.0;
    public CGFloat height;// = 0.0;
}

alias char* SEL;
alias objc_class* Class;
alias objc_object* id;

struct objc_object
{
    Class isa;
}

struct objc_class;

extern (C)
{
    Class objc_getClass (in char* name);
    id objc_msgSend (id theReceiver, SEL theSelector, ...);
    void objc_msgSend_stret(void* stretAddr, id theReceiver, SEL theSelector,
...);
    SEL sel_registerName (in char* str);
}
extern (C) int printf(in char*, ...);

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));
}

int main ()
{
    auto cls = objc_getClass("NSScreen".ptr);

    alias extern (C) id function (id, SEL) screenFp;
    auto screen = (cast(screenFp)&objc_msgSend)(cast(id) cls,
sel_registerName("mainScreen".ptr));

    auto frame = foo(screen);

    printf("x=%f y=%f width=%f height=%f\n".ptr, frame.origin.x,
frame.origin.y, frame.size.width, frame.size.height);
    return 0;
}

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