diff options
| author | Pietro Gagliardi <[email protected]> | 2014-03-01 04:17:32 -0500 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-03-01 04:17:32 -0500 |
| commit | a3b01892fdd13d37eff64d915319fb337a7bfe27 (patch) | |
| tree | 4ce513c4cf7b3cad297aa8402ba15d28ed31db6b /bleh_darwin.m | |
| parent | 6b8a8d2d15ef016650ac277f4439b6f0cfb9b371 (diff) | |
Moved the Objective-C wrappers and helpers out of darwintest.
Diffstat (limited to 'bleh_darwin.m')
| -rw-r--r-- | bleh_darwin.m | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/bleh_darwin.m b/bleh_darwin.m new file mode 100644 index 0000000..f24806c --- /dev/null +++ b/bleh_darwin.m @@ -0,0 +1,46 @@ +/* 28 february 2014 */ + +/* +I wanted to avoid invoking Objective-C directly, preferring to do everything directly with the API. However, there are some things that simply cannot be done too well; for those situations, there's this. It does use the Objective-C runtime, eschewing the actual Objective-C part of this being an Objective-C file. + +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 + +Go wrapper functions (bleh_darwin.go) call these directly and take care of stdint.h -> Go type conversions. +*/ + +#include <objc/message.h> +#include <objc/objc.h> +#include <objc/runtime.h> + +#include <stdint.h> + +#include <Foundation/NSGeometry.h> + +/* +NSUInteger is listed as being in <objc/NSObjCRuntime.h>... which doesn't exist. Rather than relying on undocumented header file locations or explicitly typedef-ing NSUInteger to the (documented) unsigned long, I'll just place things here for maximum safety. I use uintptr_t as that should encompass every possible unsigned long. +*/ + +id _objc_msgSend_uint(id obj, SEL sel, uintptr_t a) +{ + return objc_msgSend(obj, sel, (NSUInteger) a); +} + +/* +These are the objc_msgSend() wrappers around NSRect. The problem is that while on 32-bit systems, NSRect is a concrete structure, on 64-bit systems it's just a typedef to CGRect. While in practice just using CGRect everywhere seems to work, better to be safe than sorry. + +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. +*/ + +#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) +{ + return objc_msgSend(obj, sel, OurRect()); +} + +id _objc_msgSend_rect_uint_uint_bool(id obj, SEL sel, int64_t x, int64_t y, int64_t w, int64_t h, uintptr_t b, uintptr_t c, BOOL d) +{ + return objc_msgSend(obj, sel, OurRect(), (NSUInteger) b, (NSUInteger) c, d); +} |
