Skip to content

c_bool is not (always?) c_int, causes miscompilation of extent hook API #53

@Arnavion

Description

@Arnavion

type c_bool = c_int;

This leads to a miscompilation when using API that involves c_bool, ie the extent hook API. For example, when my implementation of this Rust typedef wrote to the supposed c_bool pointers, it ended up smashing other variables in the caller's stack. I'm using the x86_64-unknown-linux-musl and x86_64-unknown-linux-gnu targets with gcc 11, gcc 12 and gcc 13.

jemalloc expects to be using C99 bool via the stdbool.h header, and the equivalent of that is Rust's bool, not c_int. jemalloc does have this header for Windows MSVC that defines it to win32's BOOL which is apparently an int. I'm not sure if even that is required, since web search seems to indicate MSVC also got stdbool.h in VS 2013, but I don't have Windows to check myself.


Workaround: Write the extent hook implementations with the correct signature (using Rust bool), then transmute then into the incorrect signatures that tikv-jemalloc-sys requires (using c_int) via std::mem::transmute.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions