-
-
Notifications
You must be signed in to change notification settings - Fork 464
Start implementing C wrapper #553
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for starting to work on this. I hope my comments make sens to you.
A lot of casts are now unnecessary due to the `typedefs`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add your sample code from the other repo as well? Do you think you could also add a CMakeLists.txt
? If not, I'll try to add one to this PR myself.
Sure, I can add the example program. RE BTW is it worth adding NULL checks to input arguments? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think I'm out of ideas on how to further improve this, except simply adding the missing functions.
In that regard: note that I added a commit changing the stbi usage to be in line with the other tools. This would then also work for png images.
The following should work as a minimal starting point (not tested):
EDIT: you also need to add the line
No. |
Yeah, I know STBI works for PNGs &c, I was just trying different options and that's what I committed lol
Added also a |
I'll be adding shortly the means to extract the data out of a result but I have a question on "style". The two alternatives I see are: const char* zxing_Result_data(const zxing_Result* result, int* len);
// OR
const zxing_ByteArray* zxing_Result_bytes(const zxing_Result* result);
const char* zxing_ByteArray_data(const zxing_ByteArray* bytes);
int zxing_ByteArray_size(const zxing_ByteArray* bytes); The first approach seems more familiar to me, more C-like: the caller gets a pointer to the internal data array, but ownership is not moved. Users must be careful not to use the pointer after calling The second approach, to get a pointer we need to copy the whole bytes ( |
If we were only concerned with the I believe it would be unwise to mix the ownership of the memory semantics for the different getters. So if we go for ownership transfer for the In general, I would think the API is cleaner if do not transfer the memory ownership. On the other hand: what is a c-api client going to do with the I guess it would be a bit more generic and 'standard' if the returned |
Did I put you off somehow, did I miss an open question your are waiting for the answer or are you simply on vacation? :) |
Nah, don't worry, I won't run away :) I just have a ton of things atm and this isn't a priority right now. |
@axxel Sorry I left this hanging all of a sudden. I'm hoping I'll be able to relax a bit around mid-June and have time to work on this again. |
Hey @axxel, I restarted work on this just now, hoping it would be trivial to add support for the In the meantime, could you help with adding the right CMake files to the right places? And then explain how to use them to build the example program? :D |
I don't see how your latest commit can have any effect on your test program. I'm pretty sure it is something else. |
I went ahead and added a few more properties of DecodeHints and Result. Also added a ctest case. The test program actually outputs some content now. What else would be required for your original use case? |
Hey, thanks for your work! Sorry I was unavailable once again these few days, I'm going slightly insane with some unexpected events lately... For our use case at work we only need As it is, is it ready to be merged or is there anything missing for you? |
* new BUILD_C_API cmake option * implement multi symbol api * add ContentType * add zxing_BarcodeFormatFromString * minor cleanup
I just added I'll be happy to merge it as is and add missing stuff from there when someone speaks up. I intent to eventually simply add the |
Yup, seems to be the most natural.
Makes sense to me. I won't be able to provide any opinion on advanced use-cases, but once I convert our program to use the new C API, I'll report any issues I find. |
This is a sketch implementation to serve as discussion point for #551.
An alternative fork can be found here, and an example program using this WIP wrapper here.
Currently, the program sometimes crashes (with a segfault or a floating point exception) and sometimes "succeeds" ("Result is invalid" is printed to
stderr
). I haven't discovered yet why that is because I can't make it crash insidegdb
:/For now I started with the reading API only, because that's what I had to use and know now how to use. It should be enough, at least for a while, to discuss what needs to be discussed.
As is custom in C, there's a library prefix used to try to avoid identifier collisions -- I chose
zxing
.Identifiers follow an easy rule (I think):
ZXing
is lower-cased, and the namespace separator (::
) is replaced with an underscore (_
):zxing_ImageFormat
forZXing::ImageFormat
);zxing_ImageFormat_RGB
forZXing::ImageFormat::RGB
);zxing_ImageView_format()
forZXing::ImageView.format()
);zxing_ReadBarcode()
forZXing::ReadBarcode()
).I chose this naming scheme simply to make it easy to switch or find the corresponding identifiers from one to the other: someone using the C wrapper should be able to easily find the corresponding C++ identifier and vice-versa.
Some things to improve/consider/discuss:
void *