From ff6b409f28cb1fcba72fb9cb0ad2e1506d1081f3 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 5 Feb 2015 10:33:47 +0100 Subject: [PATCH] Cocoa: avoid atomic-mode problems in clipboard Get data from a clipboard client before going into atomic mode. This correction can avoid an "about to suspend in atomic mode" failure, particularly if a snip fails to copy correctly. --- gui-lib/mred/private/wx/cocoa/clipboard.rkt | 27 ++++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/gui-lib/mred/private/wx/cocoa/clipboard.rkt b/gui-lib/mred/private/wx/cocoa/clipboard.rkt index 73a087db..6d7d57fd 100644 --- a/gui-lib/mred/private/wx/cocoa/clipboard.rkt +++ b/gui-lib/mred/private/wx/cocoa/clipboard.rkt @@ -52,6 +52,9 @@ #f))))) (define/public (set-client c types) + (define bstrs + (for/list ([type (in-list types)]) + (send c get-data type))) (atomically (with-autorelease (let ([pb (tell NSPasteboard generalPasteboard)] @@ -62,18 +65,18 @@ declareTypes: a owner: #f)) (set! client c) - (for ([type (in-list types)]) - (let ([bstr (send c get-data type)]) - (when bstr - (let* ([bstr (if (string? bstr) - (string->bytes/utf-8 bstr) - bstr)] - [data (tell NSData - dataWithBytes: #:type _bytes bstr - length: #:type _NSUInteger (bytes-length bstr))]) - (tellv (tell NSPasteboard generalPasteboard) - setData: data - forType: #:type _NSString (map-type type)))))))))) + (for ([type (in-list types)] + [bstr (in-list bstrs)]) + (when bstr + (let* ([bstr (if (string? bstr) + (string->bytes/utf-8 bstr) + bstr)] + [data (tell NSData + dataWithBytes: #:type _bytes bstr + length: #:type _NSUInteger (bytes-length bstr))]) + (tellv (tell NSPasteboard generalPasteboard) + setData: data + forType: #:type _NSString (map-type type))))))))) (define/public (get-data-for-type type) (log-error "didn't expect clipboard data request"))