diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2025-02-13 18:32:48 +0000 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2025-02-13 18:32:48 +0000 |
commit | a6be8523d564722a1ee3b3b1b21a2f9c78ba3210 (patch) | |
tree | 5322af773bec1823c679d1303e4126322dac18dc | |
parent | 08aa8ffdfb59fd9bdec686d416357958167dad8f (diff) | |
download | txr-a6be8523d564722a1ee3b3b1b21a2f9c78ba3210.tar.gz txr-a6be8523d564722a1ee3b3b1b21a2f9c78ba3210.tar.bz2 txr-a6be8523d564722a1ee3b3b1b21a2f9c78ba3210.zip |
ffi: big endian: broken int8 and uint8 return values.
* ffi.c (ffi_i8_rput, ffi_i8_rget, ffi_u8_rput, ffi_u8_rget):
These functions are not doing the correct job; they are just
casting the pointer to the target type, like on little endian.
The big endian rget must fetch the entire 64 bit word
(ffi_arg) and convert its value to the target type. If
it's a character value, the actual bits are found at
*(src + 7) not at *src. The rput function must do the
reverse; convert the value to the 64 bit ffi_arg and
store that.
-rw-r--r-- | ffi.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -1885,14 +1885,15 @@ static void ffi_i8_rput(struct txr_ffi_type *tft, val n, mem_t *dst, val self) { i8_t v = c_i8(n, self); (void) tft; - *coerce(i8_t *, dst) = v; + *coerce(ffi_arg *, dst) = v; } static val ffi_i8_rget(struct txr_ffi_type *tft, mem_t *src, val self) { + i8_t n = *coerce(ffi_arg *, src); (void) tft; (void) self; - return num_fast(*src); + return num_fast(n); } static void ffi_u8_rput(struct txr_ffi_type *tft, val n, mem_t *dst, val self) @@ -1900,14 +1901,15 @@ static void ffi_u8_rput(struct txr_ffi_type *tft, val n, mem_t *dst, val self) u8_t v = c_u8(n, self); (void) tft; (void) self; - *coerce(u8_t *, dst) = v; + *coerce(ffi_arg *, dst) = v; } static val ffi_u8_rget(struct txr_ffi_type *tft, mem_t *src, val self) { + u8_t n = *coerce(ffi_arg *, src); (void) tft; (void) self; - return num_fast(*coerce(u8_t *, src)); + return num_fast(n); } #if HAVE_I16 |