Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test compile failure on aarch64-linux: std::os::raw::c_char is unsigned #5495

Open
magneticflux- opened this issue Jun 16, 2024 · 8 comments

Comments

@magneticflux-
Copy link

magneticflux- commented Jun 16, 2024

Contrary to popular belief, char's signedness is undefined; it is commonly signed on x86_64 and unsigned on AArch64 and the Rust raw types follow their C counterparts: https://doc.rust-lang.org/std/os/raw/type.c_char.html

Encountered running tests on AArch64:

error[E0600]: cannot apply unary operator `-` to type `u8`
    --> flux/src/cffi.rs:1152:35
     |
1152 |         let v: Vec<c_char> = vec![-61, 0];
     |                                   ^^^ cannot apply unary operator `-`
     |
     = note: unsigned values cannot be negated
For more information about this error, try `rustc --explain E0600`.
error: could not compile `flux` (lib test) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: builder for '/nix/store/r4bi44lb9wbpyplh31lfg69wv8l6ma9a-libflux-v0.194.5.drv' failed with exit code 101;

The offending unary -:

flux/libflux/flux/src/cffi.rs

Lines 1148 to 1153 in 27fa85d

#[test]
fn parse_with_invalid_utf8() {
let cfname = CString::new("foo.flux").unwrap();
let cfname_ptr: *const c_char = cfname.as_ptr();
let v: Vec<c_char> = vec![-61, 0];
let csrc: *const c_char = &v[0];

-61 should probably be changed to 194.

@magneticflux- magneticflux- changed the title Compile failure on aarch64-linux: std::os::raw::c_char is unsigned Test compile failure on aarch64-linux: std::os::raw::c_char is unsigned Jun 16, 2024
@magneticflux-
Copy link
Author

This seems to work:

diff --git a/libflux/flux/src/cffi.rs b/libflux/flux/src/cffi.rs
index 2e686ec4..9fbae64a 100644
--- a/libflux/flux/src/cffi.rs
+++ b/libflux/flux/src/cffi.rs
@@ -1149,7 +1149,7 @@ from(bucket: v.bucket)
     fn parse_with_invalid_utf8() {
         let cfname = CString::new("foo.flux").unwrap();
         let cfname_ptr: *const c_char = cfname.as_ptr();
-        let v: Vec<c_char> = vec![-61, 0];
+        let v: Vec<c_char> = vec![-61i8 as c_char, 0];
         let csrc: *const c_char = &v[0];
         // Safety: both pointers are valid
         let pkg = unsafe { flux_parse(cfname_ptr, csrc) };

Copy link

This issue has had no recent activity and will be closed soon.

@magneticflux-
Copy link
Author

Still a build failure.

@eclairevoyant
Copy link

autoclose bots are silly.

Copy link

This issue has had no recent activity and will be closed soon.

@magneticflux-
Copy link
Author

*ahem*

Copy link

This issue has had no recent activity and will be closed soon.

@eclairevoyant
Copy link

still real

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants