Raymond Toy pushed to branch issue-242-c-call-char-result-wrong at cmucl / cmucl
Commits:
-
d5391d9a
by Raymond Toy at 2023-06-15T15:53:13-07:00
1 changed file:
Changes:
... | ... | @@ -648,10 +648,21 @@ |
648 | 648 | (def-alien-type-method (integer :naturalize-gen) (type alien)
|
649 | 649 | ;; Mask out any unwanted bits. Important if the C code returns
|
650 | 650 | ;; values in %al, or %ax
|
651 | - (case (alien-integer-type-bits type)
|
|
652 | - (8 `(ldb (byte 8 0) ,alien))
|
|
653 | - (16 `(ldb (byte 16 0) ,alien))
|
|
654 | - (t alien)))
|
|
651 | + (if (alien-integer-type-signed type)
|
|
652 | + (case (alien-integer-type-bits type)
|
|
653 | + ;; First, get just the low part of the alien and then
|
|
654 | + ;; sign-extend it appropriately.
|
|
655 | + (8 `(let ((val (ldb (byte 8 0) ,alien)))
|
|
656 | + (if (> val #x7f)
|
|
657 | + (- val #x100))))
|
|
658 | + (16 `(let ((val (ldb (byte 16 0) ,alien)))
|
|
659 | + (if (> val #x7fff)
|
|
660 | + (- val #x10000))))
|
|
661 | + (t alien))
|
|
662 | + (case (alien-integer-type-bits type)
|
|
663 | + (8 `(ldb (byte 8 0) ,alien))
|
|
664 | + (16 `(ldb (byte 16 0) ,alien))
|
|
665 | + (t alien))))
|
|
655 | 666 | |
656 | 667 | ;; signed numbers <= 32 bits need to be sign extended.
|
657 | 668 | ;; I really should use the movsxd instruction, but I don't
|