Changeset 10519
- Timestamp:
- 08/22/08 08:53:55 (3 months ago)
- Files:
-
- trunk/source/lib/db-io.lisp (modified) (12 diffs)
- trunk/source/lib/foreign-types.lisp (modified) (5 diffs)
- trunk/source/library/parse-ffi.lisp (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/source/lib/db-io.lisp
r9243 r10519 506 506 507 507 508 (defstruct (ffi-transparent-union (:include ffi-mem-block) 509 (:constructor 510 make-ffi-transparent-union (&key 511 string name 512 &aux 513 (anon-global-id 514 (unless name 515 (concatenate 'string 516 *ffi-prefix* 517 "-" string))))))) 508 518 (defstruct (ffi-struct (:include ffi-mem-block) 509 519 (:constructor … … 541 551 (defun ffi-union-reference (u) 542 552 (or (ffi-union-name u) (ffi-union-anon-global-id u))) 553 554 (defun ffi-transparent-union-reference (u) 555 (or (ffi-transparent-union-name u) (ffi-transparent-union-anon-global-id u))) 543 556 544 557 (defstruct (ffi-function (:include ffi-type)) … … 591 604 (if (eql ch #\u) 592 605 `(:union ,name) 593 name))) 606 (if (eql ch #\U) 607 `(:transparent-union ,name) 608 name)))) 594 609 (cdr (assoc ch *arg-spec-encoding*))))) 595 610 (if result … … 1100 1115 (defconstant encoded-type-anon-union-ref 17) ; <tag> 1101 1116 (defconstant encoded-type-bitfield-marker 18) ; <nbits> 1117 (defconstant encoded-type-named-transparent-union-ref 19) ; <name> 1118 (defconstant encoded-type-anon-transparent-union-ref 20) ;<tag> 1102 1119 ) 1103 1120 … … 1145 1162 ,@(encode-ffi-field-list (ffi-union-fields u))) 1146 1163 `(,(logior encoded-type-anon-union-ref alt-align-in-bytes-mask) 1164 ,@(encode-ffi-field-list (ffi-union-fields u)))))) 1165 1166 (defun encode-ffi-transparent-union (u) 1167 (let* ((name (ffi-transparent-union-name u)) 1168 (alt-align-in-bytes-mask (ash (or (ffi-transparent-union-alt-alignment-bits u) 1169 0) 1170 (- 5 3)))) 1171 (if name 1172 `(,(logior encoded-type-named-transparent-union-ref alt-align-in-bytes-mask) 1173 ,@(encode-name name) 1174 ,@(encode-ffi-field-list (ffi-union-fields u))) 1175 `(,(logior encoded-type-anon-transparent-union-ref alt-align-in-bytes-mask) 1147 1176 ,@(encode-ffi-field-list (ffi-union-fields u)))))) 1148 1177 … … 1289 1318 (logior encoded-type-anon-union-ref alt-align-bytes-mask)) 1290 1319 ,@(encode-name (ffi-union-reference u))))) 1320 (:transparent-union 1321 (let* ((u (cadr spec)) 1322 (name (ffi-transparent-union-name u)) 1323 (alt-align-bytes-mask (ash (or (ffi-union-alt-alignment-bits u) 1324 0) 1325 (- 5 3))) ) 1326 `(,(if name 1327 (logior encoded-type-named-transparent-union-ref alt-align-bytes-mask) 1328 (logior encoded-type-anon-transparent-union-ref alt-align-bytes-mask)) 1329 ,@(encode-name (ffi-transparent-union-reference u))))) 1291 1330 (:typedef 1292 1331 `(,encoded-type-named-type-ref ,@(encode-name (ffi-typedef-name (cadr spec))))) … … 1340 1379 `(#\l) 1341 1380 '(#\?))))))))))) 1342 ((:struct :union) 1343 `(,(if (eq (car spec) :struct) 1344 #\r 1345 #\u) 1381 ((:struct :union :transparent-union) 1382 `(,(ecase (car spec) 1383 (:struct #\r) 1384 (:union #\u) 1385 (:transparent-union #\U)) 1346 1386 ,@(encode-name (ffi-struct-reference (cadr spec))))) 1347 1387 (:typedef … … 1440 1480 (db-write-byte-list cdbm (ffi-union-reference u) (encode-ffi-union u))) 1441 1481 1482 (defun save-ffi-transparent-union (cdbm u) 1483 (db-write-byte-list cdbm (ffi-transparent-union-reference u) (encode-ffi-transparent-union u))) 1442 1484 1443 1485 … … 1631 1673 :name name))) 1632 1674 qq))) 1633 ((#.encoded-type-anon-struct-ref #.encoded-type-anon-union-ref) 1675 (#.encoded-type-named-transparent-union-ref 1676 (multiple-value-bind (name qq) (%decode-name buf q) 1677 (let* ((already (info-foreign-type-union name))) 1678 (when already 1679 (setf (foreign-record-type-kind already) :transparent-union)) 1680 (values (or already 1681 (setf (info-foreign-type-union name) 1682 (make-foreign-record-type :kind :transparent-union 1683 :name name))) 1684 qq)))) 1685 ((#.encoded-type-anon-struct-ref 1686 #.encoded-type-anon-union-ref 1687 #.encoded-type-anon-transparent-union-ref) 1634 1688 (multiple-value-bind (tag qq) (%decode-name buf q t) 1635 1689 (values (load-record tag) qq)))))) … … 1717 1771 (setf (foreign-record-field-offset field) offset)) 1718 1772 (setq total-bits (+ offset bits)))) 1719 ( :union(setq total-bits (max total-bits bits))))))1773 ((:union :transparent-union) (setq total-bits (max total-bits bits)))))) 1720 1774 (setf (foreign-record-type-fields rtype) parsed-fields 1721 1775 (foreign-record-type-alignment rtype) (or … … 1738 1792 (multiple-value-bind (name q) 1739 1793 (case rcode 1740 ((#.encoded-type-anon-struct-ref #.encoded-type-anon-union-ref) 1794 ((#.encoded-type-anon-struct-ref 1795 #.encoded-type-anon-union-ref 1796 #.encoded-type-anon-transparent-union-ref) 1741 1797 (values nil (1+ p))) 1742 1798 (t … … 1751 1807 (or (info-foreign-type-union name) 1752 1808 (setf (info-foreign-type-union name) 1753 (make-foreign-record-type :kind :union :name name)))) 1809 (make-foreign-record-type :kind 1810 (if (eql rcode encoded-type-named-union-ref) 1811 :union 1812 :transparent-union) 1813 :name name)))) 1754 1814 (make-foreign-record-type 1755 1815 :kind (if (eql rcode encoded-type-anon-struct-ref) 1756 1816 :struct 1757 :union) 1817 (if (eql rcode encoded-type-anon-union-ref) 1818 :union 1819 :transparent-union)) 1758 1820 :name name))) 1759 1821 (%decode-field-list buf q ftd) trunk/source/lib/foreign-types.lisp
r10443 r10519 1000 1000 1001 1001 (def-foreign-type-class (record :include mem-block) 1002 (kind :struct :type (member :struct :union ))1002 (kind :struct :type (member :struct :union :transparent-union)) 1003 1003 (name nil :type (or symbol null)) 1004 1004 (fields nil :type list) … … 1018 1018 (ecase kind 1019 1019 (:struct (info-foreign-type-struct name ftd)) 1020 ( :union(info-foreign-type-union name ftd)))1020 ((:union :transparent-union) (info-foreign-type-union name ftd))) 1021 1021 (case kind 1022 1022 (:struct (setf (info-foreign-type-struct name ftd) 1023 1023 (make-foreign-record-type :name name :kind :struct))) 1024 (:union (setf (info-foreign-type-union name ftd) 1025 (make-foreign-record-type :name name :kind :union))))) 1024 ((:union :transparent-union) 1025 (setf (info-foreign-type-union name ftd) 1026 (make-foreign-record-type :name name :kind kind))))) 1026 1027 (make-foreign-record-type :kind kind)))) 1027 1028 (when fields … … 1087 1088 (setf (foreign-record-field-bits parsed-field) bits) 1088 1089 (setf total-bits (+ offset bits)))) 1089 ( :union1090 ((:union :transparent-union) 1090 1091 (setf total-bits (max total-bits bits))))))) 1091 1092 (values (parsed-fields) … … 1109 1110 (:struct :struct) 1110 1111 (:union :union) 1112 (:transparent-union :transparent-union) 1111 1113 (t '???)) 1112 1114 ,(foreign-record-type-name type) … … 1762 1764 (parse-foreign-record-type :union name fields)) 1763 1765 1766 (def-foreign-type-translator transparent-union (name &rest fields) 1767 (parse-foreign-record-type :transparent-union name fields)) 1768 1764 1769 (def-foreign-type-translator array (ele-type &rest dims) 1765 1770 (when dims trunk/source/library/parse-ffi.lisp
r10045 r10519 44 44 (defvar *ffi-unions*) 45 45 (defvar *ffi-global-unions* nil) 46 (defvar *ffi-transparent-unions* nil) 47 (defvar *ffi-global-transparent-unions* nil) 46 48 (defvar *ffi-structs*) 47 49 (defvar *ffi-global-structs* nil) … … 73 75 :name (unless (digit-char-p (schar string 0)) 74 76 (escape-foreign-name string)))))) 77 78 (defun find-or-create-ffi-transparent-union (string) 79 (or (gethash string *ffi-transparent-unions*) 80 (setf (gethash string *ffi-transparent-unions*) 81 (make-ffi-transparent-union :string string 82 :name (unless (digit-char-p (schar string 0)) 83 (escape-foreign-name string)))))) 75 84 76 85 (defun find-or-create-ffi-objc-class (string) … … 358 367 (:struct-ref (list :struct (find-or-create-ffi-struct (cadr spec)))) 359 368 (:union-ref (list :union (find-or-create-ffi-union (cadr spec)))) 369 (:transparent-union-ref 370 (list :transparent-union (find-or-create-ffi-transparent-union (cadr spec)))) 360 371 (:enum-ref `(:primitive :signed)) 361 372 (:function `(:primitive (* t))) … … 425 436 union))) 426 437 438 (defun process-ffi-transparent-union (form) 439 (destructuring-bind (source-info string fields &optional alignform) 440 (cdr form) 441 (declare (ignore source-info)) 442 (let* ((union (find-or-create-ffi-transparent-union string))) 443 (setf (ffi-transparent-union-ordinal union) (incf *ffi-ordinal*)) 444 (when alignform 445 (setf (ffi-transparent-union-alt-alignment-bits union) (cadr alignform))) 446 (unless (ffi-transparent-union-fields union) 447 (setf (ffi-transparent-union-fields union) 448 (process-ffi-fieldlist fields))) 449 union))) 450 427 451 (defun process-ffi-struct (form) 428 452 (destructuring-bind (source-info string fields &optional alignform) … … 541 565 (:struct (ensure-struct-defined (cadr spec))) 542 566 (:union (ensure-union-defined (cadr spec))) 567 (:transparent-union (ensure-transparent-union-defined (cadr spec))) 543 568 (:pointer (ensure-referenced-type-defined (cadr spec))) 544 569 (:array (ensure-referenced-type-defined (caddr spec))) … … 567 592 (when *ffi-global-unions* 568 593 (setf (gethash (ffi-union-reference u) *ffi-global-unions*) u))) 594 595 (defun record-global-transparent-union (u) 596 (when *ffi-global-transparent-unions* 597 (setf (gethash (ffi-transparent-union-reference u) *ffi-global-transparent-unions*) u))) 569 598 570 599 (defun define-union-from-ffi-info (u) … … 576 605 (ensure-fields-defined fields))))) 577 606 607 (defun define-transparent-union-from-ffi-info (u) 608 (unless (ffi-transparent-union-defined u) 609 (setf (ffi-transparent-union-defined u) t) 610 (record-global-transparent-union u) 611 (when (ffi-transparent-union-name u) 612 (let* ((fields (ffi-transparent-union-fields u))) 613 (ensure-fields-defined fields))))) 614 578 615 (defun ensure-union-defined (u) 579 616 (let* ((name (ffi-union-name u))) … … 581 618 (define-union-from-ffi-info u) 582 619 (ensure-fields-defined (ffi-union-fields u))))) 620 621 (defun ensure-transparent-union-defined (u) 622 (let* ((name (ffi-transparent-union-name u))) 623 (if name 624 (define-transparent-union-from-ffi-info u) 625 (ensure-fields-defined (ffi-transparent-union-fields u))))) 583 626 584 627 (defun record-global-struct (s) … … 610 653 (let* ((target (ffi-typedef-type def))) 611 654 (unless (and (consp target) 612 (member (car target) '(:struct :union : primitive)))655 (member (car target) '(:struct :union :transparent-union :primitive))) 613 656 (ensure-referenced-type-defined target))))) 614 657 … … 630 673 (defun ffi-record-type-p (typeref) 631 674 (case (car typeref) 632 ((:struct :union ) t)675 ((:struct :union :transparent-union) t) 633 676 (:typedef (ffi-record-type-p (ffi-typedef-type (cadr typeref)))) 634 677 (t nil))) … … 659 702 (let* ((*ffi-typedefs* (make-hash-table :test 'string= :hash-function 'sxhash)) 660 703 (*ffi-unions* (make-hash-table :test 'string= :hash-function 'sxhash)) 704 (*ffi-transparent-unions* (make-hash-table :test 'string= :hash-function 'sxhash)) 661 705 (*ffi-structs* (make-hash-table :test 'string= :hash-function 'sxhash)) 662 706 (*ffi-objc-classes* (make-hash-table :test 'string= :hash-function 'sxhash)) … … 691 735 (:enum-ident (push (process-ffi-enum-ident form) defined-constants)) 692 736 (:enum (process-ffi-enum form)) 693 (:union (push (process-ffi-union form) defined-types))))) 737 (:union (push (process-ffi-union form) defined-types)) 738 (:transparent-union (push (process-ffi-transparent-union form) defined-types))))) 694 739 (multiple-value-bind (new-constants new-macros) 695 740 (process-defined-macros defined-macros (reverse defined-constants) argument-macros) … … 706 751 (ffi-struct (define-struct-from-ffi-info x)) 707 752 (ffi-union (define-union-from-ffi-info x)) 753 (ffi-transparent-union (define-transparent-union-from-ffi-info x)) 708 754 (ffi-typedef (define-typedef-from-ffi-info x)) 709 755 (ffi-objc-class (define-objc-class-from-ffi-info x)))) … … 725 771 (*ffi-global-typedefs* (make-hash-table :test 'string= :hash-function 'sxhash)) 726 772 (*ffi-global-unions* (make-hash-table :test 'string= :hash-function 'sxhash)) 773 (*ffi-global-transparent-unions* (make-hash-table :test 'string= :hash-function 'sxhash)) 727 774 (*ffi-global-structs* (make-hash-table :test 'string= :hash-function 'sxhash)) 728 775 (*ffi-global-objc-classes* (make-hash-table :test 'string= :hash-function 'sxhash)) … … 757 804 (save-ffi-union records-cdbm def)) 758 805 *ffi-global-unions*) 806 (maphash #'(lambda (name def) 807 (declare (ignore name)) 808 (save-ffi-transparent-union records-cdbm def)) 809 *ffi-global-transparent-unions*) 810 759 811 (maphash #'(lambda (name def) 760 812 (declare (ignore name))
