-
Notifications
You must be signed in to change notification settings - Fork 61
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
Segmentation fault #8
Comments
I don't think you can get the void test(const int a*, int length) {
int i = 0;
FOR(i, length) {
printf("input: %d\n", a[i]);
}
} and then invoke it with FFI doing something like: mylibrary.test(a, a.length); |
There's a related clang warning as well:
|
Hi @TooTallNate, thanks for your answer. I tried base on your answer but it does not work. I still got "Segmentation fault" error // gcc -shared -fpic mylibrary.c -o mylibrary.so
#include <stdint.h>
#include <stdio.h>
#define FOR(i,n) for (i = 0;i < n;++i)
void test(const int *a, const int length) {
int i;
FOR(i, length) {
printf("input: %d\n", a[i]);
}
} |
Can you show me your JS code as well? |
My js API var ffi = require('ffi');
var ref = require('ref');
var ArrayType = require('ref-array');
// typedef
var int = ref.types.int
// define the "int[]" type
var IntArray = ArrayType(int)
module.exports = function() {
var testAPI = ffi.Library('./mylibrary', {
'test': ['void', [IntArray, int]],
})
return testAPI;
}() my test file var ref = require('ref');
var ArrayType = require('ref-array');
var testAPI = require('./testAPI');
// typedef
var int = ref.types.int
// define the "int[]" type
var IntArray = ArrayType(int)
var a = new IntArray(5) // by length
a.length // 5
a[0] = 0
a[1] = 1
a[2] = -1
a[3] = 2
a[4] = -2
var test = testAPI.test(a, a.length); i'm using
|
That looks like it should be ok to me. Let me try running it locally and I'll get back to you. |
Hi @TooTallNate how it is going. |
I trying to follow the sample in your document but i got this error "Segmentation fault"
C file
js file
Someone else can correct me?
The text was updated successfully, but these errors were encountered: