-
Notifications
You must be signed in to change notification settings - Fork 24
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
Automated Go bindings & Errors #40
Comments
I did notice that almost every error has a WARN with a relevant message before it, so maybe that could be modified to save the last warning into a global thread-local variable accessed by the Go wrapper, or something of that sort? |
Hmm, actually, the approach I took with my handwritten bindings should do the trick:
There should be minimal, if any error changes between FBInk releases, so this shouldn't be an issue. EDIT: This is going to be a very low level wrapper, so I'm not going to worry about wrapping errors in an actual error type or anything this time around. |
Oh, I see what you're getting at. I was thinking you were wanting full error messages and such.
Yes, that should work. That's the approach I usually take when doing that kind of thing (but I make it a type and add an Error method to it for a nicer message). |
Yeah, I would (and have) done that when hand-writing a wrapper. c-for-go is spitting out int32 return types though, so that's what I'm using here. Also, FBInk error numbers are often context sensitive. The same error number might have different meanings depending on the function that returned it. That means I can't really have a generic message for each error number. Basically, the users will need to consult |
I was out all day, glad you figured it out ;p. The actual error constants should be pretty much set in stone, as most of them are either mandated by POSIX, or Linux, and since this isn't ever going to run on anything other than Linux for obvious reasons, |
On a related note, I'm not quite sure how I feel about having auto-generated binding code in the main repo. I'm perfectly fine with the specific config(s) needed for the tool (i.e., the YAML config here), much like how the cdecl stuff is kept here for the Lua/Python bindings, but I kinda feel like the generated code ought to stay in a dedicated repo? (Not familiar with the Go ecosystem, so, open to any kind of comments on the subject ;)). |
I was wondering about that myself to be honest, Part of the problem is that the module version of Part of the appeal of having the bindings in the main repo, is one can do the following:
It would mean users wouldn't have to install c-for-go themselves to use the library. My view is that the configuration controlling the code generation should live in the same repo as the generated code itself. If you wish though, I can separate everything out into it's own repo, but that will require more maintenance to keep everything up to date. Hmm. decisions decisions... |
@shermp: Those are pretty valid concerns, and I definitely think the deciding factor should be ease of maintenance, so, if that helps, go (ha!) for it ;). |
Maintenance is why I'm investigating auto generated bindings in the first place :p Still not entirely sold on having it all in the main FBInk repo though (thinking about go mod stuff), so I won't completely commit to it just yet. Unfortunately, the Go philosophy is that pre Go modules, Which is fine if one is using pure Go libraries. A bit more awkward with C libraries like FBInk. |
Random unrelated comments, in no particular order:
EDIT: Speaking of enums, not quite sure how problematic it might be if c-for-go honors the compiler's bitness when doing the conversion (i.e., they're
|
Hi @NiLuJe
I've started work on automated bindings using c-for-go here: https://github.com/shermp/FBInk/tree/go-bindings
I'm at the point where I seem to have a working binary, at least with the very limited testing I've done with it.
What I haven't decided on is how I'm actually going to deal with errors. Currently, the functions just return ints with no context.
I hate to say it, but dealing with C
errno
's is a bit of a PITA, doubly so when they're negative. To get the errno constants in c-for-go, one would have to find and include the appropriateerrno.h
file, which is compiler specific etc.Have you any ideas on how I might be able to deal with FBInk errors, hopefully without too mich manual coding?
The text was updated successfully, but these errors were encountered: