Raymond Toy pushed to branch issue-242-c-call-char-result-wrong at cmucl / cmucl

Commits:

2 changed files:

Changes:

  • tests/issues.lisp
    ... ... @@ -1004,7 +1004,7 @@
    1004 1004
     		 (- n #x100)
    
    1005 1005
     		 n))))
    
    1006 1006
         (dolist (x '(99 -99 1023 -1023))
    
    1007
    -      (assert-equal (sign-extend x) (fun x)))))
    
    1007
    +      (assert-equal (sign-extend x) (fun x) x))))
    
    1008 1008
     
    
    1009 1009
     (define-test issue.242.test-alien-return-signed-short
    
    1010 1010
       (:tag :issues)
    
    ... ... @@ -1019,7 +1019,7 @@
    1019 1019
     		 (- n #x10000)
    
    1020 1020
     		 n))))
    
    1021 1021
         (dolist (x '(1023 -1023 100000 -100000))
    
    1022
    -      (assert-equal (sign-extend x) (fun x)))))
    
    1022
    +      (assert-equal (sign-extend x) (fun x) x))))
    
    1023 1023
     
    
    1024 1024
     (define-test issue.242.test-alien-return-signed-int
    
    1025 1025
       (:tag :issues)
    
    ... ... @@ -1029,7 +1029,7 @@
    1029 1029
     				(function c-call:int c-call:int))
    
    1030 1030
     	    n)))
    
    1031 1031
         (dolist (x '(1023 -1023 #x7fffffff #x-80000000))
    
    1032
    -      (assert-equal x (fun x)))))
    
    1032
    +      (assert-equal x (fun x) x))))
    
    1033 1033
     
    
    1034 1034
     (define-test issue.242.test-alien-return-unsigned-char
    
    1035 1035
       (:tag :issues)
    
    ... ... @@ -1041,7 +1041,7 @@
    1041 1041
     	 (expected (n)
    
    1042 1042
     	   (ldb (byte 8 0) n)))
    
    1043 1043
         (dolist (x '(99 -99 1023 -1023))
    
    1044
    -      (assert-equal (expected x) (fun x)))))
    
    1044
    +      (assert-equal (expected x) (fun x) x))))
    
    1045 1045
     
    
    1046 1046
     (define-test issue.242.test-alien-return-unsigned-short
    
    1047 1047
       (:tag :issues)
    
    ... ... @@ -1053,7 +1053,7 @@
    1053 1053
     	 (expected (n)
    
    1054 1054
     	   (ldb (byte 16 0) n)))
    
    1055 1055
         (dolist (x '(1023 -1023 100000 -100000))
    
    1056
    -      (assert-equal (expected x) (fun x)))))
    
    1056
    +      (assert-equal (expected x) (fun x) x))))
    
    1057 1057
     
    
    1058 1058
     (define-test issue.242.test-alien-return-unsigned-int
    
    1059 1059
       (:tag :issues)
    
    ... ... @@ -1065,4 +1065,30 @@
    1065 1065
     	 (expected (n)
    
    1066 1066
     	   (ldb (byte 32 0) n)))
    
    1067 1067
         (dolist (x '(1023 -1023 #x7fffffff #x-80000000))
    
    1068
    -      (assert-equal (expected x) (fun x)))))
    1068
    +      (assert-equal (expected x) (fun x) x))))
    
    1069
    +
    
    1070
    +(define-test issue.242.test-alien-return-bool
    
    1071
    +  (:tag :issues)
    
    1072
    +  (flet ((fun (n)
    
    1073
    +	   (alien:alien-funcall
    
    1074
    +	    (alien:extern-alien "unsigned_to_bool"
    
    1075
    +				(function c-call:char c-call:unsigned-int))
    
    1076
    +	    n))
    
    1077
    +	 (expected (n)
    
    1078
    +	   (if (zerop n)
    
    1079
    +	       0
    
    1080
    +	       1)))
    
    1081
    +    (dolist (x '(0 1 1000))
    
    1082
    +      (assert-equal (expected x) (fun x) x))))
    
    1083
    +
    
    1084
    +(define-test issue.242.test-alien-return-bool.2
    
    1085
    +  (:tag :issues)
    
    1086
    +  (flet ((fun (n)
    
    1087
    +	   (alien:alien-funcall
    
    1088
    +	    (alien:extern-alien "unsigned_to_bool"
    
    1089
    +				(function alien:boolean c-call:unsigned-int))
    
    1090
    +	    n))
    
    1091
    +	 (expected (n)
    
    1092
    +	   (not (zerop n))))
    
    1093
    +    (dolist (x '(0 1 1000))
    
    1094
    +      (assert-equal (expected x) (fun x) x))))

  • tests/test-return.c
    1
    +#include <stdbool.h>
    
    2
    +
    
    1 3
     signed char
    
    2 4
     int_to_signed_char(int x)
    
    3 5
     {
    
    ... ... @@ -19,18 +21,23 @@ int_to_int(int x)
    19 21
     unsigned char
    
    20 22
     int_to_unsigned_char(int x)
    
    21 23
     {
    
    22
    -  return (signed char) x;
    
    24
    +  return (unsigned char) x;
    
    23 25
     }
    
    24 26
     
    
    25 27
     unsigned short
    
    26 28
     int_to_unsigned_short(int x)
    
    27 29
     {
    
    28
    -  return (signed short) x;
    
    30
    +  return (unsigned short) x;
    
    29 31
     }
    
    30 32
     
    
    31 33
     unsigned int
    
    32 34
     int_to_unsigned_int(int x)
    
    33 35
     {
    
    34
    -  return (int) x;
    
    36
    +  return (unsigned int) x;
    
    37
    +}
    
    38
    +
    
    39
    +_Bool unsigned_to_bool(unsigned u)
    
    40
    +{
    
    41
    +  return (_Bool) u;
    
    35 42
     }
    
    36 43