Changeset 5890


Ignore:
Timestamp:
Feb 10, 2007, 11:01:15 PM (18 years ago)
Author:
Gary Byers
Message:

Deftype for CF-FLOAT.

Handle callback-error-returns on x86-64.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/examples/objc-support.lisp

    r5865 r5890  
    55(eval-when (:compile-toplevel :load-toplevel :execute)
    66  (require "BRIDGE"))
     7
     8(defun allocate-objc-object (class)
     9  (send class 'alloc))
     10
    711
    812#-apple-objc-2.0
     
    1014  (def-foreign-type :<CGF>loat :float)
    1115  (def-foreign-type :<NSUI>nteger :unsigned)'
    12   (def-foreign-type :<NSI>nteger :signed))
     16  (def-foreign-type :<NSI>nteger :signed)
     17  )
    1318
    1419(defconstant +cgfloat-zero+
    1520  #+(and apple-objc-2.0 64-bit-target) 0.0d0
    1621  #-(and apple-objc-2.0 64-bit-target) 0.0f0)
     22
     23(deftype cg-float ()
     24    #+(and apple-objc-2.0 64-bit-target) 'double-float
     25    #-(and apple-objc-2.0 64-bit-target) 'single-float)
    1726
    1827#+apple-objc
     
    178187    (error (c) (external-call "__NSRaiseError" :address (ns-exception c) :void))))
    179188
     189#+ppc-target
    180190(defun objc-callback-error-return (condition return-value-pointer return-address-pointer)
    181   (%set-object return-address-pointer 0
    182                (%reference-external-entry-point (load-time-value (external "__NSRaiseError"))))
     191  ;; On PPC, the "address" of an external entry point is always
     192  ;; aligned on a 32-bit word boundary.  On PPC32, it can always
     193  ;; be represented as a fixnum; on PPC64, it might be a pointer
     194  ;; instead.
     195  ;; Note that this clobbers the actual (foreign) return address,
     196  ;; replacing it with the address of #__NSRaiseError.  Note also
     197  ;; that storing the NSException object as the return value has
     198  ;; the desired effect of causing #__NSRaiseError to be called
     199  ;; with that NSException as its argument (because r3 is used both
     200  ;; as the canonical return value register and used to pass the
     201  ;; first argument on PPC.)
     202  (let* ((addr (%reference-external-entry-point (load-time-value (external "__NSRaiseError")))))
     203    (if (type addr 'fixnum)
     204      (%set-object return-address-pointer 0 addr)
     205      (setf (%get-ptr return-address-pointer 0) addr)))
    183206  (setf (%get-ptr return-value-pointer 0) (ns-exception condition))
    184207  nil)
    185208
     209#+x8664-target
     210(progn
     211(defloadvar *x8664-objc-callback-error-return-trampoline*
     212    (let* ((code-bytes '(#x48 #x89 #xc7      ; movq %rax %rdi
     213                         #x66 #x48 #x0f #x7e ; movd %xmm0,%rax
     214                         #x52                ; pushq %rdx
     215                         #xff #xe0))         ; jmp *rax
     216           (nbytes (length code-bytes))
     217           (ptr (#_malloc nbytes)))
     218      (dotimes (i nbytes ptr)
     219        (setf (%get-unsigned-byte ptr i) (pop code-bytes)))))
     220
     221(defun objc-callback-error-return (condition return-value-pointer return-address-pointer)
     222  ;; The callback glue reserves space for %rax at return-value-pointer-8,
     223  ;; for %rdx at -16, for %xmm0 at -24.  Store NS-EXCEPTION in the
     224  ;; %rax slot, the address of #__NSRaiseError in the %rdx slot, the
     225  ;; original return address in the %xmm0 slot, and force a return to
     226  ;; the trampoline code above.
     227  (setf (%get-ptr return-value-pointer -8) (ns-exception condition)
     228        (%get-ptr return-value-pointer -16) (%get-ptr return-address-pointer 0)
     229        (%get-ptr return-address-pointer 0) *x8664-objc-callback-error-return-trampoline*)
     230  ;; A foreign entry point is always an integer on x8664.
     231  (let* ((addr (%reference-external-entry-point (load-time-value (external "__NSRaiseError")))))
     232    (if (< addr 0)                      ;unlikely
     233      (setf (%%get-signed-longlong return-value-pointer -24) addr)
     234      (setf (%%get-unsigned-longlong return-value-pointer -24) addr)))
     235  nil)
     236
     237
     238
     239)
     240
     241
    186242)
    187243
     
    192248
    193249;;; Create a new immutable dictionary just like src, replacing the
    194 ;;; value of "newkey" with "newvalue".
     250;;; value of each key in key-value-pairs with the corresponding value.
    195251(defun copy-dictionary (src &rest key-value-pairs)
    196252  (declare (dynamic-extent key-value-pairs))
Note: See TracChangeset for help on using the changeset viewer.