Skip to content

Align and size assertion failures #92

@EarthyOrange

Description

@EarthyOrange
cpp!{{
    #include <stdlib.h>
    #include <errno.h>
}}

fn as_cstr_ptr(str: &str) -> Result<*const u8> {

    let c_string: *const u8 = CString::new(str)?.as_bytes_with_nul().as_ptr();
    Ok(c_string)
}

pub fn set_env_variable(name: &str, value: &str, overwrite: i32) -> Result<i32> {
    let c_name_ptr = as_cstr_ptr(name)?;
    let c_value_ptr = as_cstr_ptr(value)?;
    let ret_val: i32 = cpp!(
        unsafe [
            c_name_ptr as "const char *",
            c_value_ptr as "const char *",
            overwrite as "int"
        ] -> i32 as "int"
        {
            return setenv(c_name_ptr, c_value_ptr, overwrite) != 0 ? errno : 0;
        }
    );
    match ret_val {
        0 => Ok(0),
        code => Err(StdlibError::from(code)),
    }
}

I have the above code snippet, where I am simply trying to call C++'s setenv method. For each of the argument passed to the macro, I see the assertion failure messages (from cpp_macros-0.5.5/src/lib.rs) of the following format.

"size_of for argument `{}` does not match between c++ and rust"
"align_of for argument `{}` does not match between c++ and rust"

Can some light be please shown on:

  • when/why these assertions fail?
  • how to fix them?
  • what is the impact of the size and alignment mismatch?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions