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

Seemingly the same array types are not compatible #16

Open
matttrawicki opened this issue Mar 31, 2017 · 1 comment
Open

Seemingly the same array types are not compatible #16

matttrawicki opened this issue Mar 31, 2017 · 1 comment

Comments

@matttrawicki
Copy link

First, thanks for the cool library. But I ran into a head scratcher. Using the node-ffi example in the README.md, I found that any specific array type constructor used in the FFI declaration has to be the exact constructor used to create the array instances when invoking the FFI'd method -- or a segmentation fault 11 occurs. Said another way, two declarations of a "float array" constructor are not compatible.

If we define

const ArrayType = require('ref-array');
const FloatArray = ArrayType('float');

use that in our FFI declaration

const libadd = ffi.Library(__dirname + '/libadd', {
  add: ['float', [ FloatArray, 'int' ] ]
});

then declare the float array constructor a second time

const FloatArray2 = ArrayType('float');

and pass an array created with it to libadd.add, a seg fault occurs.

libadd.add(new FloatArray2([1.1, 2.2, 3.3], 3));

A complete simple example can be found in the "bug" branch of my fork.

@matttrawicki
Copy link
Author

I've been digging through this module and ffi. I see that there's a lot behind these "type definitions". Declaring even seemingly the same thing again is different enough to trip up some of the magic. This quirk popped up only because I was in the midst of a refactor. Now that I've reached the inevitable point which the ffi library declaration is in the same module as the invoker, there's no more issue. If it becomes necessary to share types between modules I will simply create a master module that exports them. Thanks.

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

No branches or pull requests

1 participant