rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

add option to map specific C type to Rust type

Open Dushistov opened this issue 2 years ago • 1 comments

when bindgen (0.59.2) translate this to Rust

typedef void (* C4NULLABLE C4LogCallback)(C4LogDomain, C4LogLevel, const char *fmt, va_list args);
void c4log_writeToCallback(C4LogLevel level, C4LogCallback callback, bool preformatted) C4API;

I got this type for C4LogCallback.

unsafe extern "C" fn(_, C4LogLevel, _, *mut __va_list_tag)

I want replace the last argument *mut __va_list_tag with VaList from va_list crate.

I also I have similar problem when I convert bitmap.h from Android Sdk. This header include jni.h and so:

int32_t AndroidBitmap_getDataSpace(JNIEnv* env, jobject jbitmap)

uses generated by bindgen Rust type JNIEnv defined in jni.h, but at the same time I use jni crate where this type defined, so I want map C type JNIEnv to jni::JNIEnv.

Dushistov avatar Jan 31 '22 16:01 Dushistov

For the JNIEnv case it's easy, blocklist the JNIEnv type and add a raw use jni::JNIEnv;, we do that pretty extensively.

The *mut __va_list_tag needs some more thought probably.

emilio avatar Feb 04 '22 10:02 emilio