add ffi/unsafe/nsalloc' and
ffi/unsafe/nsstring'
original commit: 088d1dadb407132ad3b2398fc50e480e86a2fab5
This commit is contained in:
parent
ab6afa4e96
commit
19f73d1c74
|
@ -1,6 +1,7 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
(require ffi/unsafe/objc
|
(require ffi/unsafe/objc
|
||||||
ffi/unsafe
|
ffi/unsafe
|
||||||
|
ffi/unsafe/nsstring
|
||||||
"../../lock.rkt"
|
"../../lock.rkt"
|
||||||
"utils.rkt")
|
"utils.rkt")
|
||||||
|
|
||||||
|
@ -12,8 +13,8 @@
|
||||||
_NSRect _NSRect-pointer (struct-out NSRect)
|
_NSRect _NSRect-pointer (struct-out NSRect)
|
||||||
_NSRange _NSRange-pointer (struct-out NSRange)
|
_NSRange _NSRange-pointer (struct-out NSRange)
|
||||||
NSObject
|
NSObject
|
||||||
NSString _NSString
|
NSNotFound)
|
||||||
NSNotFound))
|
_NSString)
|
||||||
|
|
||||||
(define _NSInteger _long)
|
(define _NSInteger _long)
|
||||||
(define _NSUInteger _ulong)
|
(define _NSUInteger _ulong)
|
||||||
|
@ -41,23 +42,6 @@
|
||||||
|
|
||||||
(import-class NSObject NSString)
|
(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?
|
(define NSNotFound (if 64-bit?
|
||||||
#x7fffffffffffffff
|
#x7fffffffffffffff
|
||||||
#x7fffffff))
|
#x7fffffff))
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
ffi/unsafe
|
ffi/unsafe
|
||||||
ffi/unsafe/alloc
|
ffi/unsafe/alloc
|
||||||
ffi/unsafe/define
|
ffi/unsafe/define
|
||||||
|
ffi/unsafe/nsalloc
|
||||||
"../common/utils.rkt"
|
"../common/utils.rkt"
|
||||||
"../../lock.rkt")
|
"../../lock.rkt")
|
||||||
|
|
||||||
|
@ -17,13 +18,14 @@
|
||||||
as-objc-allocation-with-retain
|
as-objc-allocation-with-retain
|
||||||
clean-up-deleted
|
clean-up-deleted
|
||||||
retain release
|
retain release
|
||||||
with-autorelease
|
|
||||||
clean-menu-label
|
clean-menu-label
|
||||||
->wxb
|
->wxb
|
||||||
->wx
|
->wx
|
||||||
old-cocoa?
|
old-cocoa?
|
||||||
version-10.6-or-later?
|
version-10.6-or-later?
|
||||||
version-10.7-or-later?)
|
version-10.7-or-later?)
|
||||||
|
with-autorelease
|
||||||
|
call-with-autorelease
|
||||||
define-mz)
|
define-mz)
|
||||||
|
|
||||||
(define cocoa-lib (ffi-lib (format "/System/Library/Frameworks/Cocoa.framework/Cocoa")))
|
(define cocoa-lib (ffi-lib (format "/System/Library/Frameworks/Cocoa.framework/Cocoa")))
|
||||||
|
@ -59,18 +61,6 @@
|
||||||
(lambda (obj)
|
(lambda (obj)
|
||||||
(tellv obj retain))))
|
(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)
|
(define (clean-menu-label str)
|
||||||
(regexp-replace* #rx"&(.)" str "\\1"))
|
(regexp-replace* #rx"&(.)" str "\\1"))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user