Changeset 6041
- Timestamp:
- Mar 14, 2007, 11:32:59 PM (18 years ago)
- File:
-
- 1 edited
-
branches/objc-gf/ccl/lib/foreign-types.lisp (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/objc-gf/ccl/lib/foreign-types.lisp
r6029 r6041 37 37 (interface-dir-name d) 38 38 (interface-dir-subdir d)))) 39 39 40 ;;; We can't reference foreign types early in the cold load, 41 ;;; but we want things like RLET to be able to set a pointer's 42 ;;; type based on the foreign-type's "ordinal". We therefore 43 ;;; seem to have to arrange that certain types have fixed, 44 ;;; "canonical" ordinals. I doubt if we need more than a handful 45 ;;; of these, but let's burn 100 46 47 (defconstant max-canonical-foreign-type-ordinal 100) 48 40 49 ;;; This is intended to try to encapsulate foreign type stuff, to 41 50 ;;; ease cross-compilation (among other things.) … … 58 67 (ff-call-struct-return-by-implicit-arg-function ()) 59 68 (callback-bindings-function ()) 60 (callback-return-value-function ())) 69 (callback-return-value-function ()) 70 (ordinal max-canonical-foreign-type-ordinal) 71 (ordinal-lock (make-lock)) 72 (ordinal-types (make-hash-table :test #'eq :weak :key)) 73 (pointer-types (make-hash-table :test #'equalp))) 74 61 75 62 76 … … 91 105 *host-ftd*) 92 106 107 (defun next-foreign-type-ordinal (&optional (ftd *target-ftd*)) 108 (with-lock-grabbed ((ftd-ordinal-lock ftd)) 109 (incf (ftd-ordinal ftd)))) 110 111 93 112 (defmacro do-interface-dirs ((dir &optional (ftd '*target-ftd*)) &body body) 94 113 `(do-dll-nodes (,dir (ftd-dirlist ,ftd)) … … 183 202 (setf (gethash (make-keyword x) (ftd-translators ftd)) val)) 184 203 204 (defun note-foreign-type-ordinal (type ftd) 205 (let* ((ordinal (and type (foreign-type-ordinal type)))) 206 (when (and ordinal (not (eql 0 ordinal))) 207 (with-lock-grabbed ((ftd-ordinal-lock ftd)) 208 (setf (gethash ordinal (ftd-ordinal-types ftd)) type))))) 209 185 210 (defun info-foreign-type-kind (x &optional (ftd *target-ftd*)) 186 211 (if (info-foreign-type-translator x) … … 193 218 (gethash (make-keyword x) (ftd-definitions ftd))) 194 219 (defun (setf info-foreign-type-definition) (val x &optional (ftd *target-ftd*)) 220 (note-foreign-type-ordinal val ftd) 195 221 (setf (gethash (make-keyword x) (ftd-definitions ftd)) val)) 196 222 (defun clear-info-foreign-type-definition (x &optional (ftd *target-ftd*)) … … 200 226 (gethash (make-keyword x) (ftd-struct-definitions ftd))) 201 227 (defun (setf info-foreign-type-struct) (val x &optional (ftd *target-ftd*)) 228 (note-foreign-type-ordinal val ftd) 202 229 (setf (gethash (make-keyword x) (ftd-struct-definitions ftd)) val)) 203 230 … … 205 232 (gethash (make-keyword x) (ftd-union-definitions ftd))) 206 233 (defun (setf info-foreign-type-union) (val x &optional (ftd *target-ftd*)) 234 (note-foreign-type-ordinal val ftd) 207 235 (setf (gethash (make-keyword x) (ftd-union-definitions ftd)) val)) 208 236 … … 210 238 (gethash (make-keyword x) (ftd-enum-definitions ftd))) 211 239 (defun (setf info-foreign-type-enum) (val x &optional (ftd *target-ftd*)) 240 (note-foreign-type-ordinal val ftd) 212 241 (setf (gethash (make-keyword x) (ftd-enum-definitions ftd)) val)) 213 242 … … 322 351 323 352 (defstruct (foreign-type 324 (:constructor make-foreign-type (&key class bits alignment ))353 (:constructor make-foreign-type (&key class bits alignment ordinal)) 325 354 (:print-object 326 355 (lambda (s out) … … 329 358 (class 'root :type symbol) 330 359 (bits nil :type (or null unsigned-byte)) 331 (alignment (guess-alignment bits) :type (or null unsigned-byte))) 360 (alignment (guess-alignment bits) :type (or null unsigned-byte)) 361 (ordinal (next-foreign-type-ordinal))) 332 362 333 363 … … 602 632 ;;;; Default methods. 603 633 604 (defvar *void-foreign-type* (make-foreign-type :class 'root :bits 0 :alignment 0 ))634 (defvar *void-foreign-type* (make-foreign-type :class 'root :bits 0 :alignment 0 :ordinal 0)) 605 635 606 636 (def-foreign-type-method (root :unparse) (type) … … 1583 1613 (accessors field-name)))))) 1584 1614 1615 (defun canonicalize-foreign-type-ordinals (ftd) 1616 (let* ((canonical-ordinal 0)) ; used for :VOID 1617 (flet ((canonicalize-foreign-type-ordinal (spec) 1618 (let* ((new-ordinal (incf canonical-ordinal))) 1619 (when spec 1620 (let* ((type (parse-foreign-type spec)) 1621 (old-ordinal (foreign-type-ordinal type))) 1622 (unless (eql new-ordinal old-ordinal) 1623 (remhash old-ordinal (ftd-ordinal-types ftd)) 1624 (setf (foreign-type-ordinal type) new-ordinal) 1625 (note-foreign-type-ordinal type ftd)))) 1626 new-ordinal))) 1627 (canonicalize-foreign-type-ordinal :signed) 1628 (canonicalize-foreign-type-ordinal :unsigned) 1629 (canonicalize-foreign-type-ordinal :long) 1630 (canonicalize-foreign-type-ordinal :address) 1631 (canonicalize-foreign-type-ordinal #-darwin-target 1632 '(:struct :<D>l_info) 1633 #+darwin-target nil) 1634 (canonicalize-foreign-type-ordinal '(:struct :timespec)) 1635 (canonicalize-foreign-type-ordinal '(:struct :timeval)) 1636 (canonicalize-foreign-type-ordinal '(:struct :sockaddr_in)) 1637 (canonicalize-foreign-type-ordinal '(:struct :sockaddr_un)) 1638 (canonicalize-foreign-type-ordinal '(:struct :linger)) 1639 (canonicalize-foreign-type-ordinal '(:struct :hostent)) 1640 (canonicalize-foreign-type-ordinal '(:array :unsigned-long 3)) 1641 (canonicalize-foreign-type-ordinal '(:* :char)) 1642 (canonicalize-foreign-type-ordinal '(:struct :stat)) 1643 (canonicalize-foreign-type-ordinal '(:struct :passwd)) 1644 (canonicalize-foreign-type-ordinal #+darwin-target '(:struct :host_basic_info) #-darwin-target nil) 1645 (canonicalize-foreign-type-ordinal '(:struct :in_addr)) 1646 (canonicalize-foreign-type-ordinal '(:struct :cdb-datum)) 1647 (canonicalize-foreign-type-ordinal '(:struct :dbm-constant))))) 1648 1585 1649 (defun install-standard-foreign-types (ftd) 1586 1650 (let* ((*target-ftd* ftd) … … 1658 1722 (reduce #'* dims)))))) 1659 1723 (def-foreign-type-translator * (to) 1660 (make-foreign-pointer-type 1661 :to (if (eq to t) *void-foreign-type* (parse-foreign-type to)) 1662 :bits natural-word-size)) 1724 (let* ((to (if (eq to t) *void-foreign-type* (parse-foreign-type to)))) 1725 (or (gethash to (ftd-pointer-types *target-ftd*)) 1726 (setf (gethash to (ftd-pointer-types *target-ftd*)) 1727 (make-foreign-pointer-type 1728 :to to 1729 :bits natural-word-size))))) 1663 1730 (def-foreign-type-translator boolean (&optional (bits 32)) 1664 1731 (make-foreign-boolean-type :bits bits :signed nil)) … … 1720 1787 (this (* t #|(struct :ucontext)|#)) 1721 1788 (prev (* (struct :xframe-list))))) 1789 (canonicalize-foreign-type-ordinals ftd) 1722 1790 )) 1723 1791
Note:
See TracChangeset
for help on using the changeset viewer.
