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

Pass const void* to C++ binded function #1049

Open
hamptonmoore opened this issue May 9, 2022 · 2 comments
Open

Pass const void* to C++ binded function #1049

hamptonmoore opened this issue May 9, 2022 · 2 comments

Comments

@hamptonmoore
Copy link

hamptonmoore commented May 9, 2022

Hello,

I'm trying to create Rust bindings for the library for the library https://github.com/richgel999/fpng, I'm trying to bind against their function with a signature of

  bool fpng_encode_image_to_memory(const void* pImage, uint32_t w, uint32_t h, uint32_t num_chans, std::vector<uint8_t>& out_buf, uint32_t flags = 0);

So far I have

        unsafe fn fpng_encode_image_to_memory(pImage: *const i32, width: u32, height: u32, num_chans: u32, out_buf: &CxxVector<u8>, flags: u32) -> bool;

Which according to cxx has the signature of bool (*)(const int*, unsigned int, unsigned int, unsigned int, const std::vector<unsigned char>&, unsigned int) while the intended signature would be bool (*)(const void*, unsigned int, unsigned int, unsigned int, std::vector<unsigned char>&, unsigned int)

How do I inform cxx I would like to pass a void pointer to some data? I tried a lot related to passing [u8]s, but could never get it working

Thank you

@Louis-Simon22
Copy link

I would also like to know how to do this

@dtolnay
Copy link
Owner

dtolnay commented Nov 13, 2022

There isn't yet a void binding built in, but it's easy to DIY. In your header add:

using c_void = void;

and then in your extern "C++" module:

    type c_void;
    unsafe fn fpng_encode_image_to_memory(pImage: *const c_void, width: u32,);

LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Nov 22, 2023
Unfortunately this currently requires the use of our own c_void type.
See: dtolnay/cxx#1049

Closes KDAB#719
LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Dec 15, 2023
Unfortunately this currently requires the use of our own c_void type.
See: dtolnay/cxx#1049

Closes KDAB#719
LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Dec 15, 2023
Unfortunately this currently requires the use of our own c_void type.
See: dtolnay/cxx#1049

Closes KDAB#719
LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Dec 15, 2023
Unfortunately this currently requires the use of our own c_void type.
See: dtolnay/cxx#1049

Closes KDAB#719
ahayzen-kdab pushed a commit to KDAB/cxx-qt that referenced this issue Dec 15, 2023
Unfortunately this currently requires the use of our own c_void type.
See: dtolnay/cxx#1049

Closes #719
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

3 participants