Repository: fltk-rs/fltk-rs (language: rust)

Issue:
[BUG] Crate usage compilation errors on Linux arm64
## Describe the bug

The `fltk-rs` crate doesn't compile on Linux for `arm64`. This is due to assumptions FFI casts to `i8` will work the same on any CPU architecture (instead of using `std::os::raw::c_char`).

## To Reproduce

It is assumed that you'll attempt to reproduce the error from an `amd64` machine.

- Checkout the minimal project at https://github.com/yveszoundi/fltk-rs-issue-arm64
- Follow the readme instructions (`README.md`) in that minimal project to reproduce the issue

## Expected behavior

A basic `fltk-rs` project should compile cleanly on Linux arm64, without any issue related to type casting.

## Screenshots

<details>
<summary>Click here to toggle fltk crate compilation error messages</summary>

```
   Compiling fltk v1.4.19
   error[E0308]: mismatched types
       --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/fltk-1.4.19/src/group.rs:1463:71
            |
            1463 |             unsafe { Fl_Terminal_print_char(self.inner.widget() as _, c as i8) }
                 |                      ----------------------                           ^^^^^^^ expected `u8`, found `i8`
                      |                      |
                           |                      arguments to this function are incorrect
                                |
                                note: function defined here
                                    --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/fltk-sys-1.4.19/src/group.rs:4255:12
                                         |
                                         4255 |     pub fn Fl_Terminal_print_char(self_: *mut Fl_Terminal, c: ::std::os::raw::c_char);
                                              |            ^^^^^^^^^^^^^^^^^^^^^^
                                              help: you can convert an `i8` to a `u8` and panic if the converted value doesn't fit
                                                   |
                                                   1463 |             unsafe { Fl_Terminal_print_char(self.inner.widget() as _, (c as i8).try_into().unwrap()) }
                                                        |                                                                       +       +++++++++++++++++++++

error[E0308]: mismatched types
    --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/fltk-1.4.19/src/group.rs:1493:69
         |
         1493 |             unsafe { Fl_Terminal_put_char(self.inner.widget() as _, c as i8, row, col) }
              |                      --------------------                           ^^^^^^^ expected `u8`, found `i8`
                   |                      |
                        |                      arguments to this function are incorrect
                             |
                             note: function defined here
                                 --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/fltk-sys-1.4.19/src/group.rs:4265:12
                                      |
                                      4265 |     pub fn Fl_Terminal_put_char(
                                           |            ^^^^^^^^^^^^^^^^^^^^
                                           help: you can convert an `i8` to a `u8` and panic if the converted value doesn't fit
                                                |
                                                1493 |             unsafe { Fl_Terminal_put_char(self.inner.widget() as _, (c as i8).try_into().unwrap(), row, col) }
                                                     |                                                                     +       +++++++++++++++++++++

For more information about this error, try `rustc --explain E0308`.
error: could not compile `fltk` (lib) due to 2 previous errors
$
```
</details>

## Desktop info
 - OS: Linux (Ubuntu 22.04 -> from GitHub Actions or locally)
 - Version: 1.4.19
 - Display server on linux: Not applicable yet (crate compilation failure)

## Additional info

The issue seems related to incorrect assumptions when casting FFI values.

I assume that the following will do the trick:
- Replace direct casts to `i8` with `std::os::raw::c_char` and let the compiler decide if it should be translated into `i8` or `u8` accordingly to the CPU architecture
- If there are similar issues for `i32`, replace direct casts to `i32` with `std::os::raw::c_int` and let the compiler decide if it should be translated into `i32` or `u32` accordingly to the CPU architecture


Discussion / hints:
I'll create a pull request shortly.

Fix patch:
diff --git a/fltk/src/group.rs b/fltk/src/group.rs
index 63871da0..1768e72b 100644
--- a/fltk/src/group.rs
+++ b/fltk/src/group.rs
@@ -1456,7 +1456,7 @@ pub mod experimental {
         /// - `c` must be ASCII, not utf-8
         /// - Does not trigger redraws
         pub fn print_char(&mut self, c: char) {
-            unsafe { Fl_Terminal_print_char(self.inner.widget() as _, c as i8) }
+            unsafe { Fl_Terminal_print_char(self.inner.widget() as _, c as std::os::raw::c_char) }
         }
 
         ///   Prints single UTF-8 char `c` at current cursor position, and advances the cursor if the character
@@ -1492,7 +1492,7 @@ pub mod experimental {
         /// - Does not trigger redraws
         /// - Does NOT handle control codes, ANSI or XTERM escape sequences.
         pub fn put_char(&mut self, c: char, row: i32, col: i32) {
-            unsafe { Fl_Terminal_put_char(self.inner.widget() as _, c as i8, row, col) }
+            unsafe { Fl_Terminal_put_char(self.inner.widget() as _, c as std::os::raw::c_char, row, col) }
         }
 
         /// Print a single UTF-8 character len at display position `(drow,dcol)`.


Test patch: