From 19f73d1c74fcee58df9b7b4579faa7a706ac7f4b Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 24 Aug 2012 14:23:34 -0600 Subject: [PATCH] add `ffi/unsafe/nsalloc' and `ffi/unsafe/nsstring' original commit: 088d1dadb407132ad3b2398fc50e480e86a2fab5 --- collects/mred/private/wx/cocoa/types.rkt | 24 ++++-------------------- collects/mred/private/wx/cocoa/utils.rkt | 16 +++------------- 2 files changed, 7 insertions(+), 33 deletions(-) diff --git a/collects/mred/private/wx/cocoa/types.rkt b/collects/mred/private/wx/cocoa/types.rkt index 665aeae1..2679f30a 100644 --- a/collects/mred/private/wx/cocoa/types.rkt +++ b/collects/mred/private/wx/cocoa/types.rkt @@ -1,6 +1,7 @@ #lang racket/base (require ffi/unsafe/objc ffi/unsafe + ffi/unsafe/nsstring "../../lock.rkt" "utils.rkt") @@ -11,9 +12,9 @@ _NSSize _NSSize-pointer (struct-out NSSize) _NSRect _NSRect-pointer (struct-out NSRect) _NSRange _NSRange-pointer (struct-out NSRange) - NSObject - NSString _NSString - NSNotFound)) + NSObject + NSNotFound) + _NSString) (define _NSInteger _long) (define _NSUInteger _ulong) @@ -41,23 +42,6 @@ (import-class NSObject NSString) -(define strings (make-weak-hash)) -(define _NSString (make-ctype _id - (lambda (v) - (or (hash-ref strings v #f) - (let ([s (as-objc-allocation - (tell (tell NSString alloc) - initWithUTF8String: - #:type _string - v))]) - (hash-set! strings v s) - s))) - (lambda (v) - (atomically - (with-autorelease - (let ([s (tell #:type _bytes v UTF8String)]) - (bytes->string/utf-8 s))))))) - (define NSNotFound (if 64-bit? #x7fffffffffffffff #x7fffffff)) diff --git a/collects/mred/private/wx/cocoa/utils.rkt b/collects/mred/private/wx/cocoa/utils.rkt index 67a30325..37d71d66 100644 --- a/collects/mred/private/wx/cocoa/utils.rkt +++ b/collects/mred/private/wx/cocoa/utils.rkt @@ -3,6 +3,7 @@ ffi/unsafe ffi/unsafe/alloc ffi/unsafe/define + ffi/unsafe/nsalloc "../common/utils.rkt" "../../lock.rkt") @@ -17,13 +18,14 @@ as-objc-allocation-with-retain clean-up-deleted retain release - with-autorelease clean-menu-label ->wxb ->wx old-cocoa? version-10.6-or-later? version-10.7-or-later?) + with-autorelease + call-with-autorelease define-mz) (define cocoa-lib (ffi-lib (format "/System/Library/Frameworks/Cocoa.framework/Cocoa"))) @@ -59,18 +61,6 @@ (lambda (obj) (tellv obj retain)))) -(import-class NSAutoreleasePool) - -;; Use `with-autorelease' and `call-with-autorelease' -;; in atomic mode -(define-syntax-rule (with-autorelease expr ...) - (call-with-autorelease (lambda () expr ...))) -(define (call-with-autorelease thunk) - (let ([pool (tell (tell NSAutoreleasePool alloc) init)]) - (begin0 - (thunk) - (tellv pool release)))) - (define (clean-menu-label str) (regexp-replace* #rx"&(.)" str "\\1"))