-
Notifications
You must be signed in to change notification settings - Fork 21
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
Define constants manually from preprocessed header files #49
Comments
On the public static final fields: probably fine if we assume platforms are not changing individual values. May actually be less fragile than enums. However enums are currently used because they give type safety; you know that you're passing an Errno or a SocketOption until a native call eventually unwraps it for you (or you unwrap it yourself for whatever reason). We lose that type-safety if we go with simple fields. It's a about equal, maybe. The library is currently designed around being enums, so that probably won't change in the near term. |
They are noit static Termios_H.java `public abstract class Termios_H<T extends Termios_H.Termios> implements JnrHeader {
} import static de.ibapl.jnrheader.Defined.isDefined; import java.lang.annotation.ElementType; import org.eclipse.jdt.annotation.Nullable; import jnr.ffi.types.int32_t; public abstract class Termios_Lib extends Termios_H<Termios_Lib.LinuxTermios> implements cfsetspeed<Termios_Lib.LinuxTermios>, cfmakeraw<Termios_Lib.LinuxTermios> {
} and a Termiso_Impl.java: ` ackage de.ibapl.jnrheader.linux.x86_64.gnu; import de.ibapl.jnrheader.Defined; public class Termios_Impl extends Termios_Lib {
} |
@enums |
@aploese I think it would be reasonable for us to cleanup/refactor the current generation logic and see what we have at that point. I think it's a little overcomplicated for what it's doing. We also need to consider the possibility of hardware platform being pulled into this, which will require changes to the generation logic as well. |
This looks overcomplicated, yes. But if you look at the code from the user of JNR side, its a bit different. |
@aploese The approach here is much simpler, but it requires us to ship binaries for each platform, correct? The goal of jnr-constants has always been to provide the generated constants without any native dependency, so they could be used with any foreign function interface. Or perhaps you just mean using this mechanism to generate the enums in jnr-constants on each platform? |
I cant see that the current jnr approach is simpler - all enums are fetched as long and then truncated to maybe short.... So how to implement the termios struct which has platform dependant fields (or is this a new issue in jnr-posix ?) |
Why not code the constants manually by using preprocessed files like this for termios.h on Linux:
echo "#include <termios.h>" > c.c
gcc -dD -dI -E c.c > _termios-prepocessed.h
Doing this once will give you all defines,structures, function calls in _termios-prepocessed.h, so you can later check or add something even if you have no access to the said hardware?
I have no idea how the copyright is affected if the preprocessed files are stored in the source repository.
And maybe go away from enums to abstract classes that hold the defined values in final public (long|int|short|String) fields?
The text was updated successfully, but these errors were encountered: