Description
When llcppg converts a C/C++ class or struct that has member variables acting as callback (function) pointers, the generated Go type should carry the // llgo:type C directive, the same way it is already applied to converted typedefs of function pointer types. Currently the directive is omitted, so the callbacks inside such types are not treated with the C calling convention.
Affected Case
TestPython in the tool package. The converted MemAllocatorEx contains multiple callback fields but has no // llgo:type C directive:
type MemAllocatorEx struct {
Ctx c.Pointer
Malloc func(c.Pointer, uintptr) c.Pointer
Calloc func(c.Pointer, uintptr, uintptr) c.Pointer
Realloc func(c.Pointer, c.Pointer, uintptr) c.Pointer
Free func(c.Pointer, c.Pointer)
}
The expected output is:
// llgo:type C
type MemAllocatorEx struct {
// ...
}
The expected output for TestPython is therefore currently wrong and needs to be corrected.
Expected Behavior
If a class/struct has any member variable that is a callback (function pointer), llcppg should add // llgo:type C to the generated type. The logic should be consistent with how function-pointer typedefs are handled.
Proposed Fix
- In the type conversion path for records (struct/class), detect whether any field is a function pointer type.
- If so, emit
// llgo:type C on the generated type, reusing the existing typedef logic.
- Update the
TestPython expected output (and any other affected test cases) accordingly.
Note: the struct body above is illustrative, so please replace it with the actual generated output from the TestPython expected file before filing.
Description
When llcppg converts a C/C++ class or struct that has member variables acting as callback (function) pointers, the generated Go type should carry the
// llgo:type Cdirective, the same way it is already applied to convertedtypedefs of function pointer types. Currently the directive is omitted, so the callbacks inside such types are not treated with the C calling convention.Affected Case
TestPythonin thetoolpackage. The convertedMemAllocatorExcontains multiple callback fields but has no// llgo:type Cdirective:The expected output is:
The expected output for
TestPythonis therefore currently wrong and needs to be corrected.Expected Behavior
If a class/struct has any member variable that is a callback (function pointer), llcppg should add
// llgo:type Cto the generated type. The logic should be consistent with how function-pointertypedefs are handled.Proposed Fix
// llgo:type Con the generated type, reusing the existingtypedeflogic.TestPythonexpected output (and any other affected test cases) accordingly.Note: the struct body above is illustrative, so please replace it with the actual generated output from the
TestPythonexpected file before filing.