When generating C glue code with --c flag, function pointer parameters are rendered with incorrect syntax. The parameter name is placed after the closing parenthesis instead of inside (*).
Reproduction
Input header
typedef struct {
void *ptr;
} Context;
typedef struct {
int value;
} Result;
Result registerCallback(Context ctx, void (*callback)(void *), void (*deleteUserData)(void *));
Command:
bindgen --header bug1-function-pointer.h --package test.native --link-name test --llvm-bin $LLVM_BIN_PATH --c --flavour scala-native05 --c-import "bug1-function-pointer.h" --clang-include .
Generated output (invalid):
void __sn_wrap_test_native_registerCallback(Context *ctx, void (*)(void *) callback, void (*)(void *) deleteUserData, Result *____return) {
Result ____ret = registerCallback(*ctx, callback, deleteUserData);
memcpy(____return, &____ret, sizeof(Result));
}
Expected output (valid C):
void __sn_wrap_test_native_registerCallback(Context *ctx, void (*callback)(void *), void (*deleteUserData)(void *), Result *____return) {
Result ____ret = registerCallback(*ctx, callback, deleteUserData);
memcpy(____return, &____ret, sizeof(Result));
}
Compiler Error
error: expected ')'
void __sn_wrap_test_native_registerCallback(Context *ctx, void (*)(void *) callback, ...
^
Analysis
In C, function pointer parameter declarations require the parameter name inside the (*):
- Invalid:
void (*)(void *) callback
- Valid:
void (*callback)(void *)
When generating C glue code with
--cflag, function pointer parameters are rendered with incorrect syntax. The parameter name is placed after the closing parenthesis instead of inside(*).Reproduction
Input header
Command:
Generated output (invalid):
Expected output (valid C):
Compiler Error
Analysis
In C, function pointer parameter declarations require the parameter name inside the
(*):void (*)(void *) callbackvoid (*callback)(void *)