Comments (5)
Great list and great initiative to start pushing this forward! We can swipe examples from the various places we have them and turn them into nice readable tests. This will improve documentation as well as coverage. Let me know where I can help!
from jnr-ffi.
Checklist (Subject to Change):
C types
Numeric types (#291int
,float
,enum
etc)Numeric pointers (#293int *
,float *
,void**
(pointer of pointers, since pointer is merely a number))- Structure types (
struct
,union
)Containing numerics and numeric pointers (#295int
,int *
,void *
etc)Containing structures and structure pointers (#296struct
,union
,struct *
,union *
etc)- Containing function pointers (
int (*function)(int)
,struct*(*function)(struct *)
etc) - Containing arrays (
int[]
,struct[]
,struct*[]
,void*[]
etc)
- Structure pointers (
struct *
,union *
) - Function pointers (
int (*function)(int)
,struct*(*function)(struct *)
etc) - Arrays (
int[]
,struct[]
,struct*[]
,void*[]
etc)
Global Variables
- Numeric types and their pointers (
int
,float
,enum
,int*
etc) - Structure types and their pointers (
struct
,union
,struct*
,union*
) - Arrays (
int[]
,struct[]
,struct*[]
,void*[]
etc) - Function pointers (
int (*function)(int)
,struct*(*function)(struct *)
etc) - Consider
const
correctness for these as well especially pointers which have 2const
-nesses,const int*
vsint* const
and the combinedconst int* const
Function Invocation
- Pass and return by pointer (Numerics, Structure and Function)
(int *function(int *a, struct *b)
,struct *function(callback_t a, void *b)
etc) - Pass and return by value (Numerics, Structures and Arrays) (we don't support some of this yet but we can write the tests and have them disabled with a message saying not yet implemented)
(int function(int a, struct b)
,struct function(int[] a, struct[] b)
etc)
Memory
Pointer
classStruct
<==>Pointer
conversion- All memory types (
DirectMemoryIO
,BoundedMemoryIO
etc) - Memory lifecycle with regards to JVM GC
Library Loading
- All
LibraryOptions
- Both loading strategies (Reflection/Proxy or Asm/Bytecode)
- Library path selection behavior
- Multi-library single interface mapping, putting mappings of multiple libraries into a single Java interface (haven't tried it but should be possible I think?)
- Bad mapping errors
- Library load and symbol not found errors
Annotations
- Parameter annotations (
@In
,@Pinned
etc) - Type annotations (
@size_t
,@u_int64_t
etc) - Library annotations (
@IgnoreError
,@StdCall
etc)
Final Touches
- Remove added test suite TODOs (any I may have added)
- Code cleanup and/or clarification (make tests that were from different PRs reuse code and add more clarifications when needed)
- If the tests begin to test platform-dependent functionality (which is inevitable) we should see if we can add different platforms on our GitHub Actions workflow
After Completion
Probably turn these into their own issues upon completion:
- Improve user documentation based on specification made from the tests
- Improve in-code documentation and comments based on findings from tests, tests can be individually used as the start of debug sessions which allows for more finely tuned debugging and understanding the code flow
- Create example scenario(s) as tests within the repository, this enforces a tighter coupling (regarding maintenance) of the examples to the main code which I think is better for long term usability by users, in addition to being a "real-world" test case.
from jnr-ffi.
Hello.
Is there any news related to a struct being passed by value? Returning a struct and passing a struct into a parameter to a native function?
I know it's related to:
Right now, I'm kinda stuck because I have to call some native functions and pass structs as value.
I have the source code of the native library (it's an open source project) but making changes to the code will be a nightmare.
I love JNR (congrats! :)) but I'm also thinking on mixing with JNA. JNA deals with struct by value: https://segmentfault.com/a/1190000041817628/en
What do you think about the idea of combining JNR and JNA? Using JNA just to make the calls of the methods having struct by value.
from jnr-ffi.
I think it's probably best for us to have the missing functionality in JNR. I am not opposed to working toward merging or sharing some backend logic for JNR and JNA, and of course we're all looking forward to Project Panama.
from jnr-ffi.
We have a project that we have to create a Java Binding of an IoT solution which is written in C. I'm gonna share a little bit of our experience so far:
- Panama: promising technology but... very poor documentation. We didn't have success in some forms of accessing the native library and we didn't like the way of doing a "jextract" before. Yeah, the stub creation is great but.... Also, we couldn't go to the Panaman because we had to go to the JDK 17 version;
- JNR: We are very happy with the JNR (configuration and usage) but.... does not manage the "struct by value"
- JNA: After using JNR, we tried JNA but... we started to have errors that we didn't have with JNR.
So... no perfect solution. What we did is: go back to JNR and change some native functions (we have the source because it's a open source project). We still don't know if at the end of the day we will have success but it's the path that we have chosen. Also, I don't like to apply a patch to an open source project before using JNR.
If you decided to carry on with the implementation of the "struct by value" in JNR maybe we can help.
from jnr-ffi.
Related Issues (20)
- NoClassDefFoundError when callback method invoked HOT 6
- How to use GBK encoding HOT 1
- JVM crashes on setting callback for GTK3 signals HOT 21
- AsciiStringRef / UTF8StringRef memory safety concerns
- Add support for native `uint64` (`unsigned long long`) using Java `BigInteger`
- Add support for native `long double` using Java `BigDecimal`
- UnsatisfiedLinkError when loading 3 dependent libraries HOT 11
- Unsatisfied link when used in conjunction with jnr-posix HOT 5
- Investigate failing Pointer Boolean tests on Darwin (macOS)
- LibraryLoader.search() path not taken into consideration unless also in LD_LIBRARY_PATH HOT 3
- What's the mapping Java type of C type FILE *?
- [feature request] HOT 1
- Erorr : jnr.ffi.provider.jffi.Provider
- Native Object filling "not working"
- Native C calling Java method HOT 1
- Cannot pass a struct to 'c' function by value
- Multi-dimensional arrays as struct members HOT 1
- Load the static link library HOT 1
- Release new version of jnr-ffi HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jnr-ffi.