Questions tagged [jnr]

JNR (Java Native Runtime) is a Java library for calling native code. It is used for binding native libraries and native memory.

About

JNR (Java Native Runtime) is a Java library for calling native code. It is used for binding native libraries and native memory. It is supported by a rich Runtime library.

The justifications for using JNR are:

  • Native IO, symlinks, FS-walking,
  • Unmanaged memory
  • Selectable stdio, process IO
  • Low-level or other sockets (UNIX, ICMP, ...)
  • New APIs (graphics, crypto, OS, ...)

Useful links

  1. Java Native Runtime presentation by Charles Oliver Nutter
  2. github: jnr repository
32 questions
14
votes
2 answers

What is the difference between JNA and JNR

According to the image from here both libraries work according to the same principle. But I believe that there is a difference between them. What is this difference?
Pavel_K
  • 10,748
  • 13
  • 73
  • 186
10
votes
1 answer

How to return by value from native function?

I have the following C++ method compiled using Visual Studio 2017: extern "C" __declspec( dllexport ) Info* __stdcall GetInfo(InfoProvider* infoProvider) { static_assert(std::is_pod::value, "Must be Plain Old Data in order to be safely…
sgnsajgon
  • 664
  • 2
  • 13
  • 56
6
votes
1 answer

How to copy native memory to DirectByteBuffer

I know one way - using memcpy on C++ side: C++ method: void CopyData(void* buffer, int size) { memcpy(buffer, source, size); } JNR mapping: void CopyData(@Pinned @Out ByteBuffer byteBuffer, @Pinned @In int size); Java invocation: ByteBuffer…
sgnsajgon
  • 664
  • 2
  • 13
  • 56
6
votes
1 answer

how to specify a JNR Pointer like that of python ctypes

Using python's ctypes, it's possible to specify a pointer that takes a type: class METADATA(Structure): _fields_ = [("classes", c_int), ("names", POINTER(c_char_p))] With JNR, it looks like this: public static class Metadata…
zcaudate
  • 13,998
  • 7
  • 64
  • 124
5
votes
2 answers

Callback/closure with JNR taking a pointer argument

I'm using JNR and trying to pass a callback function with the following C-equivalent signature: int fn(void const*, void const**, void**) into some C function. I have declared the callback nested in the JNR library interface on the Java side…
user
  • 4,920
  • 3
  • 25
  • 38
3
votes
0 answers

How to return a struct by value using JNR?

I'm trying to work with the openh264 native library from Java code using JNR. The function I'm calling is defined in openh264's C header file to return a simple struct by value: typedef struct _tagVersion { unsigned int uMajor; unsigned int…
zakgof
  • 213
  • 2
  • 8
3
votes
0 answers

Cannsandra Driver & jnr-Unixsocket - java.lang.UnsatisfiedLinkError: could not load FFI provider jnr.ffi.provider.jffi.Provider

I am using cassandra and jnr-unix socket in my project and both uses jnr-ffi. Not getting any error in my local, but getting error in test env. The versions are, Cassandra version - 3.3.2 jnr-unixsocket - 0.12 Error happens on calling…
user1578872
  • 7,808
  • 29
  • 108
  • 206
3
votes
0 answers

How to map a C-struct with bitfields in JNR?

I have the following struct that i want to map using JNR-FFI. Note that this struct contains bitfields. Unfortunatly there is no JavaDoc or any other kind of doc available. typedef struct _DCB { DWORD DCBlength; DWORD BaudRate; DWORD fBinary …
Chriss
  • 5,157
  • 7
  • 41
  • 75
2
votes
1 answer

Could not load FFI provider when using module-info.java

my Linux Java application uses bluetooth devices. I use this library in order to communicate with bluez stack : https://github.com/hypfvieh/bluez-dbus. It worked very well until I added module-info.java to my client code. Suddenly I got this…
VladRia
  • 1,475
  • 3
  • 20
  • 32
2
votes
0 answers

jnr-ffi Mapping to C Libray Crashes when calling c function

I have a key value database which is written in C with following functions to set and get values. typedef uint64_t ARK; #define ARC ARK int ark_set(ARK *ark, uint64_t klen, void *key, uint64_t vlen, void *val, int64_t *rval) int ark_get(ARK *ark,…
Riyaz
  • 120
  • 7
2
votes
1 answer

JNR-FFI how to read array of structs from pointer to pointer

I am trying to interface with a C library libzbc using jnr-ffi. There is a function: int zbc_list_zones ( struct zbc_device * dev, uint64_t sector, enum zbc_reporting_options ro, struct zbc_zone ** zones, unsigned int * …
Sidias-Korrado
  • 383
  • 3
  • 12
2
votes
2 answers

UnsatisifedLinkedError : Could not locate stub library in jar file

I am trying to use this jnr-jffi library. It appears to have a dependency on jffi so I have also built that and included in my libs folder. My code to load the native code is as follows: MATH_LIB =…
jim
  • 8,670
  • 15
  • 78
  • 149
2
votes
1 answer

App running under SBT doesn't find a class from Classpath jar

I have a Scala project using sbt. It runs perfectly well under Eclipse, however, trying to run it under sbt (sbt 'run mount 1440' — including the parameters I need) leads to a ClassNotFoundException — it can not find…
Ilia Ershov
  • 25
  • 1
  • 7
2
votes
0 answers

JNA equivalent of JNR's ObjectReferenceManager?

JNR has this thing called the ObjectReferenceManager that makes keeping track of references really convenient. An object is passed to it and a unique id (a Pointer, but it's really just an id afaik) is passed back that can be used to kill the…
user
  • 4,920
  • 3
  • 25
  • 38
1
vote
2 answers

How can I call a function from JAVA/JNA if I only know the offset from another function?

I know that in libaaa.so there is an exported (the symbol is in the text/code section) function obj1() at address 0x12345 from the start of the library. CLibrary libaaa = (CLibrary)Native.load("aaa", CLibrary.class); I want to invoke a function…
1
2 3