Fixed 32-bit Mac OS X builds (and also got rid of clang's current warnings): turns out the correct usage of objc_msgSend_stret() is not in the official docs...

This commit is contained in:
Pietro Gagliardi 2014-03-01 15:58:54 -05:00
parent 4f49935563
commit b45db58261
1 changed files with 12 additions and 3 deletions

View File

@ -6,6 +6,7 @@ I wanted to avoid invoking Objective-C directly, preferring to do everything dir
The main culprits are:
- data types listed as being defined in nonexistent headers
- 32-bit/64-bit type differences that are more than just a different typedef
- wrong documentation
Go wrapper functions (bleh_darwin.go) call these directly and take care of stdint.h -> Go type conversions.
*/
@ -29,12 +30,18 @@ These are the objc_msgSend() wrappers around NSRect. The problem is that while o
I use int64_t for maximum safety, as my coordinates are stored as Go ints and Go int -> C int (which is what is documented as happening) isn't reliable.
*/
/*
This is not documented in the docs, but is in various places on apple.com. In fact, the docs are actually WRONG: they imply you pass a pointer to the structure as the first argument to objc_msgSend_stret! And there might be some cases where we can't use stret because the struct is small enough... we'll see.
*/
static NSRect (*objc_msgSend_stret_rect)(id, SEL, ...) =
(NSRect (*)(id, SEL, ...)) objc_msgSend_stret;
struct xrect objc_msgSend_stret_rect_noargs(id obj, SEL sel)
{
NSRect s;
struct xrect t;
objc_msgSend_stret(&s, obj, sel);
s = objc_msgSend_stret_rect(obj, sel);
t.x = (int64_t) s.origin.x;
t.y = (int64_t) s.origin.y;
t.width = (int64_t) s.size.width;
@ -42,7 +49,6 @@ struct xrect objc_msgSend_stret_rect_noargs(id obj, SEL sel)
return t;
}
#define OurRect() (NSMakeRect((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h))
id _objc_msgSend_rect(id obj, SEL sel, int64_t x, int64_t y, int64_t w, int64_t h)
@ -64,12 +70,15 @@ id _objc_msgSend_rect_uint_uint_bool(id obj, SEL sel, int64_t x, int64_t y, int6
Same as NSRect above, but for NSSize now.
*/
static NSSize (*objc_msgSend_stret_size)(id, SEL, ...) =
(NSSize (*)(id, SEL, ...)) objc_msgSend_stret;
struct xsize objc_msgSend_stret_size_noargs(id obj, SEL sel)
{
NSSize s;
struct xsize t;
objc_msgSend_stret(&s, obj, sel);
s = objc_msgSend_stret_size(obj, sel);
t.width = (int64_t) s.width;
t.height = (int64_t) s.height;
return t;