Skip to content
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

Use ffigen for C-API bindings #146

Merged
merged 7 commits into from
Nov 12, 2020
Merged

Use ffigen for C-API bindings #146

merged 7 commits into from
Nov 12, 2020

Conversation

vaind
Copy link
Contributor

@vaind vaind commented Nov 10, 2020

Part of dart-archive/ffigen#139 - switches from manual binding definitions to ffigen generated code

@vaind
Copy link
Contributor Author

vaind commented Nov 10, 2020

@greenrobot-team you can have a first look when it works for you. Tests crash at the moment but I don't expect many changes to get it fixed.

@greenrobot-team
Copy link
Member

Won't be able to complete my review until I'm back. Anyhow, most of what I've seen of the first commit seems straight forward.

@Buggaboo
Copy link
Contributor

Buggaboo commented Nov 10, 2020

You might want to check the size of the pointers. They should be machine word size, unless instructed differently to the compiler :/ Struct padding (I assume no packing is applied) could also be an issue.

Really cool tool. I didn't know about it until now. I tried writing my own this summer. I guess I could throw that away now.

@vaind
Copy link
Contributor Author

vaind commented Nov 10, 2020

You might want to check the size of the pointers. They should be machine word size, unless instructed differently to the compiler :/

Thanks, I'm aware of that. I had to do some patching until it's resolved in ffigen

@vaind vaind marked this pull request as ready for review November 10, 2020 16:02
@greenrobot
Copy link
Member

greenrobot commented Nov 10, 2020

So many code changes... Maybe walk me quickly through it tomorrow; e.g. what's generated and what not...

Did you test this on a 32 bit system (in addition to 64 bit ofc); e.g. Android?

@greenrobot
Copy link
Member

It's +10,112 −1,483 LoC and I assume the generated code is most of that. Can you give a high level explanation why it's almost +9K net? Maybe some example?

@greenrobot
Copy link
Member

You might want to check the size of the pointers. They should be machine word size, unless instructed differently to the compiler :/

Thanks, I'm aware of that. I had to do some patching until it's resolved in ffigen

Could you point us to that patch you did?

@vaind
Copy link
Contributor Author

vaind commented Nov 10, 2020

It's +10,112 −1,483 LoC and I assume the generated code is most of that. Can you give a high level explanation why it's almost +9K net? Maybe some example?

Yes, most of it is the generated code, the (hopefully temporary) patch file & objectbox.h, 9777 lines added altogether.

image

The generated code is a lot larger then our manual code because it doesn't use templates (generics) which we used to reduce the amount of manual work (though it has made the code quite a bit less readable) and it is more type safe (all pointers now have types, like Pointer<OBX_Store> instead of the original Pointer<Void>. Also, it's actually complete (with the exception of obx_cursor_* which I've excluded for now (unused), as opposed to the original binding code where we've only defined what we needed.


Could you point us to that patch you did?

https://github.com/objectbox/objectbox-dart/pull/146/files#diff-fdd27307bfa2cd39c097a0ca82b66dfce50d199482400073ea7b37399e74ff22

Did you test this on a 32 bit system (in addition to 64 bit ofc); e.g. Android?

Yes, tested the example app on the 32-bit android. We can't run our complete test-suite on device yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants