-
Hi, I am trying to create bindings for CFITSIO, but have encountered an issue with binding It's header is: int ffomem(fitsfile **fptr, const char *name, int mode, void **buffptr,
size_t *buffsize, size_t deltasize,
void *(*mem_realloc)(void *p, size_t newsize),
int *status); Binding: int ffomem(PointerByReference fptr, String filename, int ioMode,
//todo How to pass size_t by reference?
Buffer buffer, @size_t LongLongByReference memSize, @size_t long deltaSize, MemRealloc resizer,
IntByReference status);
interface MemRealloc {
@Delegate
void resize(Pointer p, int newSize);//todo size_t, tried with (Byte)Buffer instead of Pointer, but JNR throws on that case
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This is probably the worst situation to be in, a crash with no clue on what causes, though usually when the Hotspot VM crashes it dumps the I think maybe your callback isn't mapped correctly? I might be wrong, interface MemRealloc {
@Delegate
Pointer resize(Pointer p, int newSize);
// Try returning a Pointer instead of void, void *(*mem_realloc)(void *p, size_t newsize) looks like it returns a pointer
} Otherwise I would suggest trying to use int ffomem(Pointer fptr, Pointer filename, int ioMode,
Pointer buffer, Pointer memSize, @size_t long deltaSize, MemRealloc resizer,
Pointer status);
interface MemRealloc {
@Delegate
void resize(Pointer p, int newSize); // And also try returning Pointer as we did above
} Switching to
Pointer myPointer1 = Memory.allocate(...); // Allocate some memory
Pointer myPointer2 = Memory.allocateDirect(...); // Allocate direct memory
Pointer myPointer3 = Memory.allocateTemporary(...); // Allocate temorary memory With and getting the backing And with a I hope this helps, let me know how this works out, I am curious to understand what the problem is. |
Beta Was this translation helpful? Give feedback.
This is probably the worst situation to be in, a crash with no clue on what causes, though usually when the Hotspot VM crashes it dumps the
hs_err_pid.log
files, not dumping it is strange and you may want to look into that. It's unrelated to JNR-FFI but it's worth making sure you get those files being dumped because at the very least you can know which part of your Java code is causing the crash and hopefully figure out where it maps on the native side. Often it's not a JNR-FFI issue but rather, the native library is trying to access some inaccessible or invalid memory, either you didn't allocate the memory, it got freed, or it's not in the correct format the library expects (ie passed a …