add ffi/unsafe/nsalloc' and ffi/unsafe/nsstring'

original commit: 088d1dadb407132ad3b2398fc50e480e86a2fab5
This commit is contained in:
Matthew Flatt 2012-08-24 14:23:34 -06:00
parent ab6afa4e96
commit 19f73d1c74
2 changed files with 7 additions and 33 deletions

View File

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

View File

@ -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"))