-
Notifications
You must be signed in to change notification settings - Fork 43
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
[Feature] Config to expose unused typedef
s
#320
Comments
Sorry, I don't understand. But aren't these enums and struct? Can you highlight some C code and it's corresponding Dart code that you would like ffigen to generate? |
Generated Dart code are private, so I have to define them myself as workaround. Below are generated Dart code: abstract class _SYSTEM_INFORMATION_CLASS {
} class _SYSTEM_PROCESS_INFORMATION extends ffi.Struct {
} |
Typedefs to enums are never generated (even if it's a referred typedef) I guess we can add a config for targetting these unused typedefs. And also generate referrred typedefs for enum since they can be non-private and be useful. I'll try to make a PR soon, but for now you can simply rename the enum and struct to remove the underscore. |
This feature is also useful when we want to split wrapper type definitions and functions or split the generated bindings to different files when the project becomes complicate and large. e.g., // types.h
typedef void *SomeClassA;
typedef void *SomeClassB;
typedef void (*Callback)(void *);
...and many other similar typedefs. then if we just generate this file, all typedefs will not be generated because they are not used. I know that you may want to say: just include it in the headers that use it! e.g., // moduleA.h
#include "types.h"
// return value is a status code
int create_A(Callback callback);
int A_getB(SomeClassA self, Callback callback); // moduleA.cpp
#include "moduleA.h"
int create_A(Callback callback){
callback(new SomeClassA());
return 0;
}
int A_getB(SomeClassA self, Callback callback){
SomeClassB *b = self->getB(); // here, since SomeClassB doesn't appear in moduleA.h, it will not be generated.
callback(b);
return 0;
} Yes it works, but still, only those used in The above is just a simple usage, if we want to split the bindings to different modules, it will be better to also generate unused typedefs such as Edit 1: This is particularly useful when we want to split different modules, e.g., if a |
dart-archive/ffigen#224 generates only the required typedefs, which results in hacks like this:
https://github.com/Sunbreak/dynamic_load.trial/blob/56953bb6e0b5d4badffb13bf3446cd794c914d26/example/ntdll/winternl.dart#L20
SYSTEM_INFORMATION_CLASS
andSYSTEM_PROCESS_INFORMATION
is a usecase for #359The text was updated successfully, but these errors were encountered: