Code Monkey home page Code Monkey logo

node-ffi-napi's Introduction

node-ffi-napi

Node.js Foreign Function Interface for N-API

Greenkeeper badge

NPM Version NPM Downloads Build Status Coverage Status Dependency Status

node-ffi-napi is a Node.js addon for loading and calling dynamic libraries using pure JavaScript. It can be used to create bindings to native libraries without writing any C++ code.

It also simplifies the augmentation of node.js with C code as it takes care of handling the translation of types across JavaScript and C, which can add reams of boilerplate code to your otherwise simple C. See the example/factorial for an example of this use case.

WARNING: node-ffi-napi assumes you know what you're doing. You can pretty easily create situations where you will segfault the interpreter and unless you've got C debugger skills, you probably won't know what's going on.

WARNING: The original API of node-ffi is left mostly untouched in the N-API wrapper. However, the API did not have very well-defined properties in the context of garbage collection and multi-threaded execution. It is recommended to avoid any multi-threading usage of this library if possible.

Example

var ffi = require('ffi-napi');

var libm = ffi.Library('libm', {
  'ceil': [ 'double', [ 'double' ] ]
});
libm.ceil(1.5); // 2

// You can also access just functions in the current process by passing a null
var current = ffi.Library(null, {
  'atoi': [ 'int', [ 'string' ] ]
});
current.atoi('1234'); // 1234

For a more detailed introduction, see the node-ffi tutorial page.

Requirements

  • Linux, OS X, Windows, or Solaris.
  • libffi comes bundled with node-ffi-napi; it does not need to be installed on your system.
  • The current version is tested to run on Node 6 and above.

Installation

Make sure you've installed all the necessary build tools for your platform, then invoke:

$ npm install ffi-napi

Source Install / Manual Compilation

To compile from source it's easiest to use node-gyp:

$ npm install -g node-gyp

Now you can compile node-ffi-napi:

$ git clone git://github.com/node-ffi-napi/node-ffi-napi.git
$ cd node-ffi
$ node-gyp rebuild

Types

The types that you specify in function declarations correspond to ref's types system. So see its docs for a reference if you are unfamiliar.

V8 and 64-bit Types

Internally, V8 stores integers that will fit into a 32-bit space in a 32-bit integer, and those that fall outside of this get put into double-precision floating point numbers. This is problematic because FP numbers are imprecise. To get around this, the methods in node-ffi that deal with 64-bit integers return strings and can accept strings as parameters.

Call Overhead

There is non-trivial overhead associated with FFI calls. Comparing a hard-coded binding version of strtoul() to an FFI version of strtoul() shows that the native hard-coded binding is orders of magnitude faster. So don't just use the C version of a function just because it's faster. There's a significant cost in FFI calls, so make them worth it.

License

MIT License. See the LICENSE file.

node-ffi-napi's People

Contributors

addaleax avatar atishay avatar ckarper avatar clangen avatar d3m3vilurr avatar daveosborne avatar du-song avatar fredericgermain avatar greenkeeper[bot] avatar indutny avatar ionphractal avatar jasonmay avatar joelpurra avatar justinfreitag avatar kjunichi avatar mcnameej avatar mithgol avatar mkundgol avatar nikmikov avatar odidev avatar orlandov avatar ossdev07 avatar pimterry avatar raphaelr avatar rbranson avatar tootallnate avatar unbornchikken avatar wadey avatar xingrz avatar zhaoda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-ffi-napi's Issues

Error when trying to install node-ffi-napi

To make things clear, I have windows-build-tools installed and I set the npm config to python 2.7 folder. (64 bits node and python).

C:\Users\Practicas02\Documents\Proyectos\Navegador Electron ADIF\Aplicacion Electron\electron_adif\app>npm install ffi-napi

> [email protected] install C:\Users\Practicas02\Documents\Proyectos\Navegador Electron ADIF\Aplicacion Electron\electron_adif\app\node_modules\ref-napi
> node-gyp rebuild


C:\Users\Practicas02\Documents\Proyectos\Navegador Electron ADIF\Aplicacion Electron\electron_adif\app\node_modules\ref-napi>if not defined npm_config_node_gyp (node "C:\Users\Practicas02\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Users\Practicas02\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Los proyectos de esta solución se van a compilar de uno en uno. Para habilitar la compilación en paralelo, agregue el modificador "/m".
  win_delay_load_hook.cc
  Generando c¾digo
  All 1 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
  Generaci¾n de c¾digo finalizada
  nothing.vcxproj -> C:\Users\Practicas02\Documents\Proyectos\Navegador Electron ADIF\Aplicacion Electron\electron_adif\app\node_modules\ref-napi\build\Release\\nothing.node
  binding.cc
  win_delay_load_hook.cc
     Creando biblioteca C:\Users\Practicas02\Documents\Proyectos\Navegador Electron ADIF\Aplicacion Electron\electron_adif\app\node_modules\ref-napi\build\Release\binding.lib y objeto C:\Users\Practicas02\Documents\Proyectos\Navegad
  or Electron ADIF\Aplicacion Electron\electron_adif\app\node_modules\ref-napi\build\Release\binding.exp
  Generando c¾digo
  All 242 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
  Generaci¾n de c¾digo finalizada
  binding.vcxproj -> C:\Users\Practicas02\Documents\Proyectos\Navegador Electron ADIF\Aplicacion Electron\electron_adif\app\node_modules\ref-napi\build\Release\\binding.node

> [email protected] install C:\Users\Practicas02\Documents\Proyectos\Navegador Electron ADIF\Aplicacion Electron\electron_adif\app\node_modules\ffi-napi
> node-gyp rebuild


C:\Users\Practicas02\Documents\Proyectos\Navegador Electron ADIF\Aplicacion Electron\electron_adif\app\node_modules\ffi-napi>if not defined npm_config_node_gyp (node "C:\Users\Practicas02\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Users\Practicas02\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Los proyectos de esta solución se van a compilar de uno en uno. Para habilitar la compilación en paralelo, agregue el modificador "/m".
  Building assembly file ..\..\..\deps\libffi\src\x86\win64.asm
   Assembling: ..\..\..\deps\libffi\src\x86\win64.asm
  prep_cif.c
  types.c
  raw_api.c
  java_raw_api.c
  closures.c
  ffi.c
  win_delay_load_hook.cc
  ffi.vcxproj -> C:\Users\Practicas02\Documents\Proyectos\Navegador Electron ADIF\Aplicacion Electron\electron_adif\app\node_modules\ffi-napi\build\Release\\libffi.lib
  nothing.vcxproj -> C:\Users\Practicas02\Documents\Proyectos\Navegador Electron ADIF\Aplicacion Electron\electron_adif\app\node_modules\ffi-napi\build\Release\\nothing.lib
  ffi.cc
  callback_info.cc
  threaded_callback_invokation.cc
  win32-dlfcn.cc
  win_delay_load_hook.cc
c:\users\practicas02\documents\proyectos\navegador electron adif\aplicacion electron\electron_adif\app\node_modules\ffi-napi\src\ffi.cc(3): fatal error C1083: No se puede abrir el archivo incluir: 'get-uv-event-loop-napi.h': No such
 file or directory [C:\Users\Practicas02\Documents\Proyectos\Navegador Electron ADIF\Aplicacion Electron\electron_adif\app\node_modules\ffi-napi\build\ffi_bindings.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\Practicas02\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System Windows_NT 10.0.16299
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Practicas02\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\Practicas02\Documents\Proyectos\Navegador Electron ADIF\Aplicacion Electron\electron_adif\app\node_modules\ffi-napi
gyp ERR! node -v v10.11.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN [email protected] requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint@^4.1.1 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint-plugin-jsx-a11y@^5.1.1 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint@>=1.6.0 <5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Practicas02\AppData\Roaming\npm-cache\_logs\2018-10-08T08_18_49_857Z-debug.log

Installation fails on Windows 10 x64 (Node 10.9.0, Python 3.7.0)

I'm trying to install the lib using the information of README, but I'm getting the following error on installation:

PS C:\Users\renan.gomes\Desktop\development\ffi-test> yarn add ffi-napi
yarn add v1.6.0
(node:7000) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
[1/2] ⡀ ref-napi: using [email protected] | win32 | x64
[-/2] ⢀ waiting...
[-/2] ⢀ waiting...
[-/2] ⢀ waiting...
error C:\Users\renan.gomes\Desktop\development\ffi-test\node_modules\ref-napi: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: C:\Users\renan.gomes\Desktop\development\ffi-test\node_modules\ref-napi
Output:
C:\Users\renan.gomes\Desktop\development\ffi-test\node_modules\ref-napi>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "" rebuild )
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | win32 | x64
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "C:\Program Files (x86)\Python37-32\python.EXE", you can set the PYTHON env variable.
gyp ERR! stack     at PythonFinder.failNoPython (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:492:19)
gyp ERR! stack     at PythonFinder.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:517:16)
gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\polyfills.js:284:29
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:152:21)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\renan.gomes\Desktop\development\ffi-test\node_modules\ref-napi

My Node Version:

PS C:\Users\renan.gomes\Desktop\development\ffi-test> node -v
v10.9.0

I see something about Python on error message, so here's my Python version too:

PS C:\Users\renan.gomes\Desktop\development\ffi-test> py --version
Python 3.7.0

An in-range update of ref-napi is breaking the build 🚨

The dependency ref-napi was updated from 1.4.2 to 1.4.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

ref-napi is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build passed (Details).
  • coverage/coveralls: First build on greenkeeper/ref-napi-1.4.3 at 89.057% (Details).
  • continuous-integration/appveyor/branch: AppVeyor build failed (Details).

Commits

The new version differs by 4 commits.

  • f0775c1 v1.4.3
  • 33d46e7 Update to jquery-3.4.1.min.js
  • 4b8f542 chore: update marked to version 0.7.0
  • 7137ebc chore: update node-addon-api to version 2.0.0

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Introducing ffi-napi into electron (angular Rendering process) gets an error, Could not locate the bindings file. Tried:

I have seen similar error reports, but they can't solve my problem,

I'm using angular as the electron rendering process,The error occurs when the ffi-napi module is introduced

import('ffi-napi').then(ffi => {
});

core.js:6014 ERROR Error: Uncaught (in promise): Error: Could not locate the bindings file. Tried:
→ F:\WebStorm\workspace\cloud-game-pc-platform\build\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\build\Debug\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\build\Release\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\out\Debug\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\Debug\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\out\Release\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\Release\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\build\default\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\compiled\12.8.1\win32\x64\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\addon-build\release\install-root\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\addon-build\debug\install-root\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\addon-build\default\install-root\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\lib\binding\node-v75-win32-x64\binding.node
Error: Could not locate the bindings file. Tried:
→ F:\WebStorm\workspace\cloud-game-pc-platform\build\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\build\Debug\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\build\Release\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\out\Debug\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\Debug\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\out\Release\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\Release\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\build\default\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\compiled\12.8.1\win32\x64\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\addon-build\release\install-root\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\addon-build\debug\install-root\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\addon-build\default\install-root\binding.node
→ F:\WebStorm\workspace\cloud-game-pc-platform\lib\binding\node-v75-win32-x64\binding.node
at bindings (bindings.js:126)
at Object../node_modules/ref-napi/lib/ref.js (ref.js:7)
at webpack_require (bootstrap:790)
at fn (bootstrap:150)
at Object../node_modules/ffi-napi/lib/ffi.js (ffi.js:7)
at webpack_require (bootstrap:790)
at fn (bootstrap:150)
at fn.t (bootstrap:194)
at ZoneDelegate.invoke (zone-evergreen.js:359)
at Object.onInvoke (core.js:39699)
at resolvePromise (zone-evergreen.js:797)
at resolvePromise (zone-evergreen.js:754)
at zone-evergreen.js:858
at ZoneDelegate.invokeTask (zone-evergreen.js:391)
at Object.onInvokeTask (core.js:39680)
at ZoneDelegate.invokeTask (zone-evergreen.js:390)
at Zone.runTask (zone-evergreen.js:168)
at drainMicroTaskQueue (zone-evergreen.js:559)

Minimum demo

https://github.com/liangshen001/cloud-game-pc-platform.git

git clone https://github.com/liangshen001/cloud-game-pc-platform.git
cd cloud-game-pc-platform
npm i
Manually modify angular webpack target (web => electron-renderer)

cloud-game-pc-platform\node_modules\webpack\lib\WebpackOptionsDefaulter.js 42:29

this.set("target", "web"); => this.set("target", "electron-renderer");

npm run ngx-electron:server-start
You get a window that looks like this:

截屏2020-03-14上午10 30 15

Click the test button,Get the error

截屏2020-03-14上午10 31 15

environment

System: Windows10 64x
node: v12.16.1
npm: 6.12.0
ffi-napi: 2.4.7

Thank you in advance!!!

Add support for Windows on ARM (AArch64)

node-ffi-napi currently embeds libffi-3.0.11 which predates Windows on ARM (AArch64).

To support Windows on ARM64, node-ffi-napi will probably need two individual updates (in this order):
(1) update node-ffi-napi to libffi-3.3 (with any ffi.cc/ff.h file updates necessary to suppor libffi-3.3)
(2) for WoA: update the node-gyp and ffi.cc/ffi.h files to support Windows on ARM (AArch64)

I have done some preliminary testing, and I am able to basically just replace libffi-3.0.11 with libffi-3.3 in the /deps/libffi folder (while keeping the existing node-gyp file). I did need to patch up the libffi header paths when building either via "npm install" or with VS2017 generally...but libffi's main project (ffi) compiles without incident.

Note: the libffi-3.3 update was already opened as in issue; this is not intended to be a duplicate issue.
#47

I have not spent any time with AArch64 at a low level, but unless Microsoft is using significantly differently calling conventions for AArch64 we could ideally reuse some of the work already done here:
#45

add support for prebuilt binaries

it would be nice to be able to install this module without needing to install the build-tools (especially on windows). for example, like how the zeromq module handles this with prebuilt binaries.

An in-range update of nyc is breaking the build 🚨

Version 11.7.3 of nyc was just published.

Branch Build failing 🚨
Dependency nyc
Current Version 11.7.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

nyc is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build passed Details
  • coverage/coveralls First build on greenkeeper/nyc-11.7.3 at 89.057% Details
  • continuous-integration/appveyor/branch AppVeyor build failed Details

Commits

The new version differs by 2 commits.

  • 43bda0c chore(release): 11.7.3
  • c20f8da security: address all vulnerabilities (#836)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

ffi-napi 2.5.0 crashes on Node 14 on macOS 10.15.4

In an empty directory:

projects/test/testffi ❯ npm i ffi-napi

...

projects/test/testffi took 11s ❯ node
Welcome to Node.js v14.0.0.
Type ".help" for more information.
> os.version()
'Darwin Kernel Version 19.4.0: Wed Mar  4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64'

> require('ffi-napi')


#
# Fatal error in , line 0
# Check failed: result.second.
#
#
#
#FailureMessage Object: 0x7ffeefbf3330
 1: 0x1000d5142 node::NodePlatform::GetStackTracePrinter()::$_3::__invoke() [/usr/local/bin/node]
 2: 0x100a18c31 V8_Fatal(char const*, ...) [/usr/local/bin/node]
 3: 0x100378436 v8::internal::GlobalBackingStoreRegistry::Register(std::__1::shared_ptr<v8::internal::BackingStore>) [/usr/local/bin/node]
 4: 0x10018d9e7 v8::ArrayBuffer::GetBackingStore() [/usr/local/bin/node]
 5: 0x100063174 node::Buffer::New(node::Environment*, char*, unsigned long, void (*)(char*, void*), void*) [/usr/local/bin/node]
 6: 0x100062f0b node::Buffer::New(v8::Isolate*, char*, unsigned long, void (*)(char*, void*), void*) [/usr/local/bin/node]
 7: 0x10005ea05 napi_create_external_buffer [/usr/local/bin/node]
 8: 0x10418c99e Napi::Buffer<char> Napi::Buffer<char>::New<Napi::Value FFI::WrapPointer<_ffi_type>(Napi::Env, _ffi_type*, unsigned long)::'lambda'(Napi::Env, char*)>(napi_env__*, char*, unsigned long, _ffi_type) [/Users/nsabovic/projects/test/testffi/node_modules/ffi-napi/build/Release/ffi_bindings.node]
 9: 0x10418742b FFI::FFI::InitializeBindings(Napi::Env, Napi::Object) [/Users/nsabovic/projects/test/testffi/node_modules/ffi-napi/build/Release/ffi_bindings.node]
10: 0x10418b2a3 __napi_Init(napi_env__*, napi_value__*) [/Users/nsabovic/projects/test/testffi/node_modules/ffi-napi/build/Release/ffi_bindings.node]
11: 0x10005e048 napi_module_register_by_symbol(v8::Local<v8::Object>, v8::Local<v8::Value>, v8::Local<v8::Context>, napi_value__* (*)(napi_env__*, napi_value__*)) [/usr/local/bin/node]
12: 0x100061e83 std::__1::__function::__func<node::binding::DLOpen(v8::FunctionCallbackInfo<v8::Value> const&)::$_0, std::__1::allocator<node::binding::DLOpen(v8::FunctionCallbackInfo<v8::Value> const&)::$_0>, bool (node::binding::DLib*)>::operator()(node::binding::DLib*&&) [/usr/local/bin/node]
13: 0x100061034 node::binding::DLOpen(v8::FunctionCallbackInfo<v8::Value> const&) [/usr/local/bin/node]
14: 0x1001cd7ea v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [/usr/local/bin/node]
15: 0x1001cce74 v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/usr/local/bin/node]
16: 0x1001cc698 v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/usr/local/bin/node]
17: 0x10074fe79 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit [/usr/local/bin/node]
zsh: illegal hardware instruction  node

Callback in thread crash or freeze

Hi,

In an electron app, a crash (on Windows) or a freeze (on Linux) occured when a callback is called in c++ thread. No problem if the same callback is called in the main thread.

Js code

var ref = require('ref-napi');
var ffi = require('ffi-napi');

let mainWindow
let callbackLiveStateChange
let lib

function createWindow () {
     lib= new ffi.Library("Lib", {
	"setStateChangeCallback": ["void", ["pointer"]]
    });
        
    // Create the browser window.
    mainWindow = new BrowserWindow({width: 1960, height: 1280, alwaysOnTop: false, transparent: true, frame: false})

    // and load the index.html of the app.
    mainWindow.loadFile('html/index.html')
    
    // Callback from the native lib back into js
    callbackStateChange = ffi.Callback('void', ['uint8'],
      function(state) {
           console.log("STATE : ",state);
      });
      lib.setStateChangeCallback(callbackStateChange)
    
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)

// Quit when all windows are closed.
app.on('window-all-closed', function () {
  
  console.log("quit")    
    
  // On OS X it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', function () {
  // On OS X it's common to re-create a window in the app when the
  // dock icon is clicked and there are no other windows open.
  if (mainWindow === null) {
    createWindow()
  }
})

// Make an extra reference to the callback pointer to avoid GC
app.on('exit', function() {
  callbackStateChange
});

C++ code

void processCallback(void(*a_callback)(uint8_t))
{
	a_callback(5);
}

void setStateChangeCallback(void(*a_callback)(uint8_t))
{
	processCallback(a_callback); // OK

	std::thread t = std::thread(processCallback,a_callback);  // KO
	t.join();
}

`

Callback crash

Platform: Windows 7 x64
After migrating to ffi-napi, app crashes with stack (VS2015):

Exception thrown at 0x000000013F2703AC in node.exe: 0xC0000005: Access violation reading location 0x0000000400000002.

 	node.exe!000000013f2703ac()	Unknown
>	binding.node!`anonymous namespace'::ReadObject(const Napi::CallbackInfo & args) Line 125	C++
 	binding.node!Napi::details::WrapCallback<<lambda_4b130013be4a466940e6fe08d32cda83> >(Napi::details::CallbackData<Napi::Value (__cdecl*)(Napi::CallbackInfo const &),Napi::Value>::Wrapper::__l2::<lambda_4b130013be4a466940e6fe08d32cda83> callback) Line 73	C++
 	binding.node!Napi::details::CallbackData<Napi::Value (__cdecl*)(Napi::CallbackInfo const &),Napi::Value>::Wrapper(napi_env__ * env, napi_callback_info__ * info) Line 96	C++

on Platform: Ubuntu 18 x64

/home/poweruser/node-libclang/node_modules/ffi-napi/lib/_foreign_function.js:61
    bindings.ffi_call(cif, funcPtr, result, argsList);
             ^

Error: TypeError: Cannot read property 'cb' of undefined
    at Object.proxy [as clang_visitChildren] (/home/poweruser/node-libclang/node_modules/ffi-napi/lib/_foreign_function.js:61:14)
    at Cursor.visitChildren (/home/poweruser/node-libclang/lib/cursor.js:163:7)
    at Object.<anonymous> (/home/poweruser/node-libclang/test/test.js:13:11)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:279:19)

Reproduction steps:

git clone https://github.com/ZFail/node-libclang
cd node-libclang
git checkout d159884786add0ae37d5aba065851f094e505f4f
yarn install
cd test
node test.js

Expected behaviour
when using node-ffi:

git clone https://github.com/ZFail/node-libclang
cd node-libclang
git checkout 0925a4cbc89ba24f888e0e68cb8794c862ffcf39
yarn install
cd test
node test.js

prints

<pid>
test_struct
test_struct_t

An in-range update of node-addon-api is breaking the build 🚨

The dependency node-addon-api was updated from 1.5.0 to 1.6.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

node-addon-api is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).
  • coverage/coveralls: First build on greenkeeper/node-addon-api-1.6.0 at 89.057% (Details).
  • continuous-integration/appveyor/branch: AppVeyor build succeeded (Details).

Release Notes for Release 1.6.0

SemVer minor release to pull changes since the last release. Mostly minor fixes and additions. The motivations for release are the addition of a new feature Napi::CallbackScope, that helps to have the equivalent of the scope associated with a callback in place when making certain N-API calls. Furthermore there are some additions on tests and improvements on documentation about the ABI stability.

Commits

The new version differs by 9 commits.

  • 322dc09 Updates for release 1.6.0
  • 8ce605c build: avoid using package-lock.json
  • fa3a615 src: use MakeCallback() -> Call() in AsyncWorker
  • 2342415 test: create test objects in the stack instead of the heap
  • 67b7db0 test: write tests for Array class
  • 729f6dc test: add arraybuffer tests
  • 405f3e5 src: implement CallbackScope class
  • 015d953 doc: fix Napi::Reference link
  • fd65078 README.md: link to new ABI stability guide

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Upgrade to libffi 3.3

Libffi 3.3 was released a few weeks ago. It would be nice to see you use the 3.3 release so we can get a better handle on node-ffi-napi local changes, and get better test coverage.

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml
  • The new Node.js version is in-range for the engines in 1 of your package.json files, so that was left alone

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Access volation while using ffi.Callback

I'm using ffi-napi to use windows api.
It is good at first time, but sometimes my app crashed.
After many tests, I found ffi.Callback create null pointer exception.
It doesn't problem at first time, but calling many time of my function cause exit code 0xC0000005 (access volation)

I attached code below. (This simple code cause problem.)

I really like this library. Please fix this problem.

const ffi = require('ffi-napi');
const {DTypes} = require('win32-def');
const LOOP_COUNT = 10000;
const user32 = ffi.Library('user32', {
  EnumWindows: [DTypes.BOOL, [DTypes.POINT, DTypes.LPARAM]],
});

function enumWindows() {
  const fn = ffi.Callback(DTypes.BOOL, [DTypes.HWND, DTypes.LPARAM], ()=> {
    return false;
  });
  const result = user32.EnumWindows(fn, 0);
  console.log('EnumWindows -> done', result, fn.address());
}


for (let i = 0; i < LOOP_COUNT; i++) {
  enumWindows()
}

My develop enviroment:
Windows 10 Home (1809)
Visual Studio 2017
Node.js v8.15.0 (tested 11.9.0 too)

An in-range update of node-gyp-build is breaking the build 🚨


☝️ Important announcement: Greenkeeper will be saying goodbye 👋 and passing the torch to Snyk on June 3rd, 2020! Find out how to migrate to Snyk and more at greenkeeper.io


The dependency node-gyp-build was updated from 4.2.1 to 4.2.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

node-gyp-build is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • coverage/coveralls: First build on greenkeeper/node-gyp-build-4.2.2 at 89.094% (Details).
  • continuous-integration/appveyor/branch: AppVeyor build failed (Details).

Commits

The new version differs by 3 commits.

  • 7e1f184 4.2.2
  • cadbc9a Use env.npm_config_* for electron and upcoming npm (#30)
  • e046b9f Upgrade tape devDependency to 5.0.0 (#31)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Example with Vue

I am having trouble getting a working example. I figured using vue create would be an easy way to get started but I get errors. I would really appreciate a hint as to how to get started.

Thanks!

I am running Ubuntu with
node 10.10.0
yarn 1.10.1
node-gyp 3.8.0
vue 3.0.4

I run

vue create testvue (use defaults)
cd testvue
vue add electron-builder
yarn add ffi-napi
Modify src/main.js as follows

import ffi from 'ffi-napi'
import Vue from 'vue'
import App from './App.vue'

Vue.config.productionTip = false

new Vue({
  render: h => h(App)
}).$mount('#app')

yarn serve:electron
The page does not show and the following error occurs in the Console:

path.js:28 Uncaught TypeError: Path must be a string. Received undefined
at assertPath (path.js:28)
at dirname (path.js:1364)
at Function.getRoot (bindings.js?dfc1:151)
at bindings (bindings.js?dfc1:60)
at eval (webpack-internal:///./node_modules/ref-napi/lib/ref.js:7)
at Object../node_modules/ref-napi/lib/ref.js (app.js:1889)
at webpack_require (app.js:725)
at fn (app.js:102)
at eval (webpack-internal:///./node_modules/ffi-napi/lib/ffi.js:7)
at Object../node_modules/ffi-napi/lib/ffi.js (app.js:1727)

App crashing with below error

In our app when registering ffi.callback it is crashing with below error.

Fatal error in HandleScope::HandleScope

Entering the V8 API without proper locking in place

Any pointer or solution will be helpful.

thanks in adavance.

Cannot load shared object file (.so in linux) when setting process.env.LD_LIBRARY_PATH in nodejs.

Cannot load shared object file (.so in linux) when setting process.env.LD_LIBRARY_PATH in nodejs.

OS: debian_9.9.0_amd64
NODE: v12.9.1
ffi-napi: 2.4.5

code, test.js

const ffi = require('ffi-napi')

const libPath = '/home/app/resources'
process.env.PATH = `${process.env.PATH}${path.delimiter}${libPath}`
// unable to load ${libPath}/api.so
process.env.LD_LIBRARY_PATH = libPath

// load /home/app/resources/api.so
ffi.Library('api', {
  'Add': ['long', ['long', 'long']]
})

console.log(ffi.Add(1, 2))

result:
image

If running with LD_LIBRARY_PATH=/home/app/resources node test.js , it is normal.
But it can not load shared object file (.so in linux) when setting process.env.LD_LIBRARY_PATH in nodejs.

Callback is still getting garbage collected.

Our macOS electron app uses nodobjc with ffi, and we have been getting "ffi: callback has been garbage collected" errors. To detect the error, I added test code to our app that will loop forever making async calls from javascript, one at a time, waiting for completion each time. Somewhere between 0 and 200 iterations, we get the error, usually at 50 to 100, but it does seem randomish.

Last week I created a local "nodobjc-napi" on my machine, that uses ffi-napi 2.4.0, which has the workaround of Callback is garbage collected.

My test code still sees the same error with the same frequency. I searched my node_modules and app/node_modules for the original ffi, but all I see is ffi-napi, so as far as I can tell the workaround is active.

We use nodobjc for our authentication flow, and if it doesn't work, then about 2% of our customers (randomishly distributed) won't be able to sign in at any given time.

Is there some way I can help to diagnose this, or to be a test bed if anyone wants to experiment? I can try adding delays, additional logging, other code, I can stay up late and spend some time on weekends. What I can't do is actually solve the problem, because I lack the skill set. Help!

node-gyp rebuild failed on OSX 10.15 Catalina

Node version: v10.18.1
Yarn version: 1.19.0
sw_vers output:

ProductName:	Mac OS X
ProductVersion:	10.15.2
BuildVersion:	19C57

I have all the building tools for OSX and my mac passes the acid tests on node-gyp tests for Catalina and node-gyp

It fails when I try to install with yarn add ffi-napi

Logs

yarn add ffi-napi
yarn add v1.19.0
$ node ./internals/scripts/CheckYarn.js
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning "react-final-form > [email protected]" has unmet peer dependency "typescript@>=3.7.0".
warning " > [email protected]" has unmet peer dependency "@types/react@^15.0.0 || ^16.0.0".
warning " > [email protected]" has unmet peer dependency "eslint-plugin-react-hooks@^1.7.0".
warning " > [email protected]" has incorrect peer dependency "eslint@^5.12.0".
warning " > [email protected]" has incorrect peer dependency "eslint-formatter-pretty@^2.1.1".
warning " > [email protected]" has incorrect peer dependency "eslint-plugin-compat@^2.7.0".
warning " > [email protected]" has incorrect peer dependency "eslint-plugin-flowtype@^3.13.0".
warning " > [email protected]" has incorrect peer dependency "eslint-plugin-jest@^22.16.0".
warning " > [email protected]" has incorrect peer dependency "babel-eslint@^7.2.3".
warning " > [email protected]" has incorrect peer dependency "eslint@^4.1.1".
warning " > [email protected]" has incorrect peer dependency "eslint-plugin-flowtype@^2.34.1".
warning " > [email protected]" has incorrect peer dependency "eslint-plugin-jsx-a11y@^5.1.1".
warning "eslint-plugin-jest > @typescript-eslint/experimental-utils > @typescript-eslint/typescript-estree > [email protected]" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
[4/4] 🔨  Building fresh packages...
[6/15] ⠈ electron
[11/15] ⠈ ref-napi
[-/15] ⠈ waiting...
[-/15] ⠈ waiting...
error /Users/guilherme/Documents/Documents/Projects/Machine Learning/mee/SAT/app/node_modules/ref-napi: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: /Users/guilherme/Documents/Documents/Projects/Machine Learning/mee/SAT/app/node_modules/ref-napi
Output:
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | darwin | x64
gyp info find Python using Python version 2.7.16 found at "/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python"
gyp info spawn /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
gyp info spawn args [ '/Users/guilherme/.nvm/versions/node/v10.18.1/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/guilherme/Documents/Documents/Projects/Machine Learning/mee/SAT/app/node_modules/ref-napi/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/guilherme/.nvm/versions/node/v10.18.1/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/guilherme/Library/Caches/node-gyp/10.18.1/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/guilherme/Library/Caches/node-gyp/10.18.1',
gyp info spawn args   '-Dnode_gyp_dir=/Users/guilherme/.nvm/versions/node/v10.18.1/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/guilherme/Library/Caches/node-gyp/10.18.1/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/guilherme/Documents/Documents/Projects/Machine Learning/mee/SAT/app/node_modules/ref-napi',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CC(target) Release/obj.target/nothing/node_modules/node-addon-api/src/nothing.o
  LIBTOOL-STATIC Release/nothing.a
Traceback (most recent call last):
  File "./gyp-mac-tool", line 611, in <module>
    sys.exit(main(sys.argv[1:]))
  File "./gyp-mac-tool", line 30, in main
    exit_code = executor.Dispatch(args)
  File "./gyp-mac-tool", line 45, in Dispatch
    return getattr(self, method)(*args[1:])
  File "./gyp-mac-tool", line 248, in ExecFilterLibtool
    if not libtool_re.match(line) and not libtool_re5.match(line):
TypeError: cannot use a string pattern on a bytes-like object
make: *** [Release/nothing.a] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/guilherme/.nvm/versions/node/v10.18.1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:191:23)
gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Darwin 19.2.0
gyp ERR! command "/Users/guilherme/.nvm/versions/node/v10.18.1/bin/node" "/Users/guilherme/.nvm/versions/node/v10.18.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/guilherme/Documents/Documents/Projects/Machine Learning/mee/SAT/app/node_modules/ref-napi

How to call Struct and C pointer

I am trying to call a function where i have to parse a pointer to SVG. The problem is that it doesn't return anything. When I call a pointer to function in JS, would that return buffer?

Setting WinAPI low level hooks using Node.js ffi-napi

I'm trying to implement a simple program for Windows which hooks lowlevel mouse events in Node.js (TypeScript) using ffi-napi and WinAPI.

Here's my code:

import * as ffi from 'ffi-napi';
import * as ref from 'ref-napi';
import { types } from 'ref-napi';

const StructType = require('ref-struct-di')(ref);

/* Types */
const LONG = types.long;
const ULONG = types.ulong;
const INT = types.int;
const UINT = types.uint;
const DWORD = ULONG;
const BOOL = INT;

const HANDLE = types.uint64;
const HHOOK = HANDLE;
const HWND = HANDLE;
const HINSTANCE = HANDLE;

const WPARAM = types.uint64;
const LPARAM = types.int64;
const LRESULT = types.int64;

const HOOKPROC = 'pointer';

/* Necessary structs */

const POINT = StructType({
    x: LONG,
    y: LONG
});

const MSG = StructType({
    hwnd: HWND,
    message: UINT,
    wParam: WPARAM,
    lParam: LPARAM,
    time: DWORD,
    pt: POINT,
    lPrivate: DWORD
});

type WindowsHookCallback = (nCode: number, wParam: number, lParam: number) => number;

/* User32 bindings */

const u32 = ffi.Library('user32', {
    'SetWindowsHookExW': [HHOOK, [INT, HOOKPROC, HINSTANCE, DWORD]],
    'UnhookWindowsHookEx': [BOOL, [HHOOK]],
    'CallNextHookEx': [LRESULT, [HHOOK, INT, WPARAM, LPARAM]],
    'GetMessageW': [BOOL, [MSG, HWND, UINT, UINT]],
    'TranslateMessage': [BOOL, [MSG]],
    'DispatchMessageW': [LRESULT, [MSG]]
});

/* Some wrappers for them next */

function SetWindowsHookEx(idHook: number, lpfn: WindowsHookCallback, hmod: number, dwThreadId: number): number {
    const callback = ffi.Callback(LRESULT, [INT, WPARAM, LPARAM], lpfn);
    return u32.SetWindowsHookExW(idHook, callback, hmod, dwThreadId);
}

function UnhookWindowsHookEx(hhk: number): number {
    return u32.UnhookWindowsHookEx(hhk);
}

function CallNextHookEx(hhk: number, nCode: number, wParam: number, lParam: number): number {
    return u32.CallNextHookEx(hhk, nCode, wParam, lParam);
}

function GetMessageW(lpMsg: any, hWnd: number, wMsgFilterMin: number, wMsgFilterMax: number): number {
    return u32.GetMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
}

function TranslateMessage(lpMsg: any): number {
    return u32.TranslateMessage(lpMsg);
}

function DispatchMessageW(lpMsg: any): number {
    return u32.DispatchMessageW(lpMsg);
}

/* Necessary consts */

const
    WM_LBUTTONDOWN = 0x0201,
    WM_LBUTTONUP = 0x0202;
    WH_MOUSE_LL = 14;

let hHook= 0;

/* Callback for our low level hook */

function MouseHookCallback(nCode: number, wParam: number, lParam: number): number {
    if (nCode >= 0) {
        if (wParam === WM_LBUTTONDOWN) {
            console.log('Left Button Down');
        } else if (wParam === WM_LBUTTONUP) {
            console.log('Left Button Up');
        }
    }
    return CallNextHookEx(hHook, nCode, wParam, lParam);
}

/* Set the hook */
hHook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookCallback, 0, 0);

/* Message loop */
let msg = new MSG();
while (GetMessageW(msg.ref(), 0, 0, 0)) {
    TranslateMessage(msg.ref());
    DispatchMessageW(msg.ref());
}

It detects mouse clicks fine but gets interrupted when mouse is moved more than a few pixels. I can't find out where is the problem. Is it a problems with ffi-napi/ref-napi or I do something wrong? Could someone please explain me?

I wrote same program in C:

#include <stdio.h>
#include <Windows.h>

HHOOK hHook;

LRESULT CALLBACK MouseHookCallback(int nCode, WPARAM wParam, LPARAM lParam) {
    if (nCode >= 0) {
        if (wParam == WM_LBUTTONDOWN) {
            printf("Left Button Down\n");
        }
        else if (wParam == WM_LBUTTONUP) {
            printf("Left Button Up\n");
        }
    }
    return CallNextHookEx(hHook, nCode, wParam, lParam);
}

int main()
{
    hHook = SetWindowsHookExW(WH_MOUSE_LL, MouseHookCallback, 0, 0);

    MSG msg;
    while (GetMessageW(&msg, 0, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessageW(&msg);
    }
}

but it works excellent and doesn't crash if I move mouse on any distance.

Not working with electron 3.0.10

When it will start supporting node.Js v10.2.1 and Electron v3.0.10. When i am using it in electron I am getting following error.

`Error: /Users/hrishabhkumar/.nvm/versions/node/v10.2.1/bin/node exited with code 1
Output:
yarn run v1.12.3
$ node-gyp rebuild
CC(target) Release/obj.target/nothing/../node-addon-api/src/nothing.o
LIBTOOL-STATIC Release/nothing.a
CC(target) Release/obj.target/ffi/deps/libffi/src/prep_cif.o
CC(target) Release/obj.target/ffi/deps/libffi/src/types.o
CC(target) Release/obj.target/ffi/deps/libffi/src/raw_api.o
CC(target) Release/obj.target/ffi/deps/libffi/src/java_raw_api.o
CC(target) Release/obj.target/ffi/deps/libffi/src/closures.o
CC(target) Release/obj.target/ffi/deps/libffi/src/x86/ffi.o
CC(target) Release/obj.target/ffi/deps/libffi/src/x86/ffi64.o
CC(target) Release/obj.target/ffi/deps/libffi/src/x86/darwin.o
CC(target) Release/obj.target/ffi/deps/libffi/src/x86/darwin64.o
LIBTOOL-STATIC Release/libffi.a
CXX(target) Release/obj.target/ffi_bindings/src/ffi.o
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Error output:
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | darwin | x64
gyp info spawn /usr/bin/python
gyp info spawn args [ '/Users/hrishabhkumar/.nvm/versions/node/v10.2.1/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/Users/hrishabhkumar/My-studio/my-studio/node_modules/ffi-napi/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/Users/hrishabhkumar/.nvm/versions/node/v10.2.1/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/Users/hrishabhkumar/.electron-gyp/iojs-1.8.7/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/Users/hrishabhkumar/.electron-gyp/iojs-1.8.7',
gyp info spawn args '-Dnode_gyp_dir=/Users/hrishabhkumar/.nvm/versions/node/v10.2.1/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/Users/hrishabhkumar/.electron-gyp/iojs-1.8.7/<(target_arch)/iojs.lib',
gyp info spawn args '-Dmodule_root_dir=/Users/hrishabhkumar/My-studio/my-studio/node_modules/ffi-napi',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
In file included from ../deps/libffi/src/closures.c:210:
../deps/libffi/src/dlmalloc.c:2932:33: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
used = fp - (m->topsize + TOP_FOOT_SIZE);
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)

../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1275:14: note: expanded from macro 'align_offset'
((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :
^
../deps/libffi/src/dlmalloc.c:2932:33: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
used = fp - (m->topsize + TOP_FOOT_SIZE);
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1276:34: note: expanded from macro 'align_offset'
((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))
^
../deps/libffi/src/dlmalloc.c:3289:39: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE;
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1275:14: note: expanded from macro 'align_offset'
((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :
^
../deps/libffi/src/dlmalloc.c:3289:39: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE;
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1276:34: note: expanded from macro 'align_offset'
((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))
^
../deps/libffi/src/dlmalloc.c:3383:41: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE);
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1275:14: note: expanded from macro 'align_offset'
((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :
^
../deps/libffi/src/dlmalloc.c:3383:41: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE);
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1276:34: note: expanded from macro 'align_offset'
((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))
^
../deps/libffi/src/dlmalloc.c:3461:40: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
asize = granularity_align(nb + TOP_FOOT_SIZE + SIZE_T_ONE);
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
^
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1275:14: note: expanded from macro 'align_offset'
((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :
^
../deps/libffi/src/dlmalloc.c:2143:6: note: expanded from macro 'granularity_align'
(((S) + (mparams.granularity)) & ~(mparams.granularity - SIZE_T_ONE))
^
../deps/libffi/src/dlmalloc.c:3461:40: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
asize = granularity_align(nb + TOP_FOOT_SIZE + SIZE_T_ONE);
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
^
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1276:34: note: expanded from macro 'align_offset'
((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))
^
../deps/libffi/src/dlmalloc.c:2143:6: note: expanded from macro 'granularity_align'
(((S) + (mparams.granularity)) & ~(mparams.granularity - SIZE_T_ONE))
^
../deps/libffi/src/dlmalloc.c:3475:51: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
asize = granularity_align(nb - m->topsize + TOP_FOOT_SIZE + SIZE_T_ONE);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
^
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1275:14: note: expanded from macro 'align_offset'
((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :
^
../deps/libffi/src/dlmalloc.c:2143:6: note: expanded from macro 'granularity_align'
(((S) + (mparams.granularity)) & ~(mparams.granularity - SIZE_T_ONE))
^
../deps/libffi/src/dlmalloc.c:3475:51: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
asize = granularity_align(nb - m->topsize + TOP_FOOT_SIZE + SIZE_T_ONE);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
^
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1276:34: note: expanded from macro 'align_offset'
((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))
^
../deps/libffi/src/dlmalloc.c:2143:6: note: expanded from macro 'granularity_align'
(((S) + (mparams.granularity)) & ~(mparams.granularity - SIZE_T_ONE))
^
../deps/libffi/src/dlmalloc.c:3487:26: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
asize < nb + TOP_FOOT_SIZE + SIZE_T_ONE) {
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1275:14: note: expanded from macro 'align_offset'
((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :
^
../deps/libffi/src/dlmalloc.c:3487:26: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
asize < nb + TOP_FOOT_SIZE + SIZE_T_ONE) {
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1276:34: note: expanded from macro 'align_offset'
((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))
^
../deps/libffi/src/dlmalloc.c:3488:49: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
size_t esize = granularity_align(nb + TOP_FOOT_SIZE + SIZE_T_ONE - asize);
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
^
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1275:14: note: expanded from macro 'align_offset'
((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :
^
../deps/libffi/src/dlmalloc.c:2143:6: note: expanded from macro 'granularity_align'
(((S) + (mparams.granularity)) & ~(mparams.granularity - SIZE_T_ONE))
^
../deps/libffi/src/dlmalloc.c:3488:49: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
size_t esize = granularity_align(nb + TOP_FOOT_SIZE + SIZE_T_ONE - asize);
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
^
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1276:34: note: expanded from macro 'align_offset'
((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))
^
../deps/libffi/src/dlmalloc.c:2143:6: note: expanded from macro 'granularity_align'
(((S) + (mparams.granularity)) & ~(mparams.granularity - SIZE_T_ONE))
^
../deps/libffi/src/dlmalloc.c:3512:23: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
size_t req = nb + TOP_FOOT_SIZE + SIZE_T_ONE;
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1275:14: note: expanded from macro 'align_offset'
((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :
^
../deps/libffi/src/dlmalloc.c:3512:23: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
size_t req = nb + TOP_FOOT_SIZE + SIZE_T_ONE;
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1276:34: note: expanded from macro 'align_offset'
((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))
^
../deps/libffi/src/dlmalloc.c:3525:43: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
size_t asize = granularity_align(nb + TOP_FOOT_SIZE + SIZE_T_ONE);
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
^
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1275:14: note: expanded from macro 'align_offset'
((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :
^
../deps/libffi/src/dlmalloc.c:2143:6: note: expanded from macro 'granularity_align'
(((S) + (mparams.granularity)) & ~(mparams.granularity - SIZE_T_ONE))
^
../deps/libffi/src/dlmalloc.c:3525:43: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
size_t asize = granularity_align(nb + TOP_FOOT_SIZE + SIZE_T_ONE);
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
^
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1276:34: note: expanded from macro 'align_offset'
((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))
^
../deps/libffi/src/dlmalloc.c:2143:6: note: expanded from macro 'granularity_align'
(((S) + (mparams.granularity)) & ~(mparams.granularity - SIZE_T_ONE))
^
../deps/libffi/src/dlmalloc.c:3535:26: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
if (ssize > nb + TOP_FOOT_SIZE) {
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1275:14: note: expanded from macro 'align_offset'
((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :
^
../deps/libffi/src/dlmalloc.c:3535:26: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
if (ssize > nb + TOP_FOOT_SIZE) {
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1276:34: note: expanded from macro 'align_offset'
((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))
^
../deps/libffi/src/dlmalloc.c:3555:47: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE);
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1275:14: note: expanded from macro 'align_offset'
((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :
^
../deps/libffi/src/dlmalloc.c:3555:47: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE);
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1276:34: note: expanded from macro 'align_offset'
((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))
^
../deps/libffi/src/dlmalloc.c:3559:64: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
init_top(m, mn, (size_t)((tbase + tsize) - (char*)mn) -TOP_FOOT_SIZE);
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1275:14: note: expanded from macro 'align_offset'
((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :
^
../deps/libffi/src/dlmalloc.c:3559:64: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
init_top(m, mn, (size_t)((tbase + tsize) - (char*)mn) -TOP_FOOT_SIZE);
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1276:34: note: expanded from macro 'align_offset'
((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))
^
../deps/libffi/src/dlmalloc.c:3627:59: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
if (!cinuse(p) && (char*)p + psize >= base + size - TOP_FOOT_SIZE) {
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1275:14: note: expanded from macro 'align_offset'
((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :
^
../deps/libffi/src/dlmalloc.c:3627:59: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
if (!cinuse(p) && (char*)p + psize >= base + size - TOP_FOOT_SIZE) {
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1276:34: note: expanded from macro 'align_offset'
((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))
^
../deps/libffi/src/dlmalloc.c:3658:12: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead /
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1275:14: note: expanded from macro 'align_offset'
((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :
^
../deps/libffi/src/dlmalloc.c:3658:12: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead /
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2188:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1688:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void)((char*)(p) + TWO_SIZE_T_SIZES))
^
../deps/libffi/src/dlmalloc.c:1276:34: note: expanded from macro 'align_offset'
((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))
^
28 warnings generated.
In file included from ../src/ffi.cc:1:
In file included from ../src/ffi.h:22:
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:930:24: error: unknown type name 'napi_async_context'
napi_async_context context = nullptr) const;
^
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:933:24: error: unknown type name 'napi_async_context'
napi_async_context context = nullptr) const;
^
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:937:24: error: unknown type name 'napi_async_context'
napi_async_context context = nullptr) const;
^
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:930:43: error: cannot initialize a parameterof type 'int' with an rvalue of type 'nullptr_t'
napi_async_context context = nullptr) const;
^ ~~~~~~~
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:930:43: note: passing argument to parameter 'context' here
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:933:43: error: cannot initialize a parameterof type 'int' with an rvalue of type 'nullptr_t'
napi_async_context context = nullptr) const;
^ ~~~~~~~
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:933:43: note: passing argument to parameter 'context' here
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:937:43: error: cannot initialize a parameterof type 'int' with an rvalue of type 'nullptr_t'
napi_async_context context = nullptr) const;
^ ~~~~~~~
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:937:43: note: passing argument to parameter 'context' here
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:959:7: error: unknown type name 'napi_deferred'
napi_deferred _deferred;
^
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:1111:30: error: unknown type name 'napi_async_context'
napi_async_context context = nullptr) const;
^
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:1114:30: error: unknown type name 'napi_async_context'
napi_async_context context = nullptr) const;
^
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:1118:30: error: unknown type name 'napi_async_context'
napi_async_context context = nullptr) const;
^
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:1111:49: error: cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'
napi_async_context context = nullptr) const;
^ ~~~~~~~
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:1111:49: note: passing argument to parameter'context' here
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:1114:49: error: cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'
napi_async_context context = nullptr) const;
^ ~~~~~~~
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:1114:49: note: passing argument to parameter'context' here
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:1118:49: error: cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'
napi_async_context context = nullptr) const;
^ ~~~~~~~
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:1118:49: note: passing argument to parameter'context' here
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:1685:14: error: unknown type name 'napi_async_context'
operator napi_async_context() const;
^
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:1689:5: error: unknown type name 'napi_async_context'
napi_async_context _context;
^
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:1758:20: error: unknown type name 'napi_node_version'
static const napi_node_version* GetNodeVersion(Env env);
^
In file included from ../src/ffi.cc:1:
In file included from ../src/ffi.h:22:
In file included from /Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi.h:1764:
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi-inl.h:403:24: error: use of undeclared identifier 'napi_is_promise'
napi_status status = napi_is_promise(_env, _value, &result);
^
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi-inl.h:414:24: error: use of undeclared identifier 'napi_is_dataview'
napi_status status = napi_is_dataview(_env, _value, &result);
^
/Users/hrishabhkumar/My-studio/my-studio/node_modules/node-addon-api/napi-inl.h:501:24: error: use of undeclared identifier 'napi_create_double'
napi_status status = napi_create_double(env, val, &value);
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Release/obj.target/ffi_bindings/src/ffi.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/Users/hrishabhkumar/.nvm/versions/node/v10.2.1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack at ChildProcess.emit (events.js:182:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
gyp ERR! System Darwin 18.2.0
gyp ERR! command "/Users/hrishabhkumar/.nvm/versions/node/v10.2.1/bin/node" "/Users/hrishabhkumar/.nvm/versions/node/v10.2.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/hrishabhkumar/My-studio/my-studio/node_modules/ffi-napi
gyp ERR! node -v v10.2.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
error Command failed with exit code 1.

at ChildProcess.childProcess.once.code (/Users/hrishabhkumar/My-studio/my-studio/node_modules/builder-util/src/util.ts:244:14)
at Object.onceWrapper (events.js:273:13)
at ChildProcess.emit (events.js:182:13)
at maybeClose (internal/child_process.js:961:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:248:5)
From previous event:
at runCallback (timers.js:696:18)
at tryOnImmediate (timers.js:667:5)
at processImmediate (timers.js:649:5)
From previous event:
at /Users/hrishabhkumar/My-studio/my-studio/node_modules/app-builder-lib/src/util/yarn.ts:155:24
From previous event:
at _rebuild (/Users/hrishabhkumar/My-studio/my-studio/node_modules/app-builder-lib/src/util/yarn.ts:179:5)
at rebuild (/Users/hrishabhkumar/My-studio/my-studio/node_modules/app-builder-lib/out/util/yarn.js:163:19)
at /Users/hrishabhkumar/My-studio/my-studi`

Can't install MacOS- error at node-gyp

I'm having an issue installing in all node versions at the node-gyp rebuild step. I've tried node 8, 10, and now 11. All were using update node-gyp. I have the necessary xcode and python requirements.

Node Version: 11.9.0
NPM: 6.5.0
MacOS 10.14.5
python: 2.7.16

> node-gyp rebuild

  CXX(target) Release/obj.target/binding/src/binding.o
../src/binding.cc:222:30: warning: 'BooleanValue' is deprecated: Use maybe version [-Wdeprecated-declarations]
  bool persistent = info[3]->BooleanValue();
                             ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8.h:2568:3: note: 'BooleanValue' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version", bool BooleanValue() const);
  ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
../src/binding.cc:253:26: warning: 'Uint32Value' is deprecated: Use maybe version [-Wdeprecated-declarations]
  size_t size = info[2]->Uint32Value();
                         ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8.h:2571:3: note: 'Uint32Value' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version", uint32_t Uint32Value() const);
  ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
../src/binding.cc:360:23: warning: 'Utf8Value' is deprecated: Use Isolate version [-Wdeprecated-declarations]
    String::Utf8Value _str(in);
                      ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8.h:2991:5: note: 'Utf8Value' has been explicitly marked deprecated here
    V8_DEPRECATED("Use Isolate version",
    ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
../src/binding.cc:447:23: warning: 'Utf8Value' is deprecated: Use Isolate version [-Wdeprecated-declarations]
    String::Utf8Value _str(in);
                      ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8.h:2991:5: note: 'Utf8Value' has been explicitly marked deprecated here
    V8_DEPRECATED("Use Isolate version",
    ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
../src/binding.cc:521:26: warning: 'Uint32Value' is deprecated: Use maybe version [-Wdeprecated-declarations]
  size_t size = info[1]->Uint32Value();
                         ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8.h:2571:3: note: 'Uint32Value' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version", uint32_t Uint32Value() const);
  ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
../src/binding.cc:550:32: warning: 'Uint32Value' is deprecated: Use maybe version [-Wdeprecated-declarations]
  uint32_t numZeros = info[1]->Uint32Value();
                               ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8.h:2571:3: note: 'Uint32Value' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version", uint32_t Uint32Value() const);
  ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
../src/binding.cc:643:8: warning: 'ForceSet' is deprecated [-Wdeprecated-declarations]
  Nan::ForceSet(target, Nan::New<v8::String>("endianness").ToLocalChecked(), Nan::New<v8::String>(CheckEndianness()).ToLocalChecked(), static_cast<PropertyAttribute>(ReadOnly|DontDelete));
       ^
../../../../nan/nan_maybe_43_inl.h:130:1: note: 'ForceSet' has been explicitly marked deprecated here
NAN_DEPRECATED inline Maybe<bool> ForceSet(
^
../../../../nan/nan.h:103:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
../src/binding.cc:644:8: warning: 'ForceSet' is deprecated [-Wdeprecated-declarations]
  Nan::ForceSet(target, Nan::New<v8::String>("NULL").ToLocalChecked(), WrapNullPointer(), static_cast<PropertyAttribute>(ReadOnly|DontDelete));
       ^
../../../../nan/nan_maybe_43_inl.h:130:1: note: 'ForceSet' has been explicitly marked deprecated here
NAN_DEPRECATED inline Maybe<bool> ForceSet(
^
../../../../nan/nan.h:103:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
8 warnings generated.
  SOLINK_MODULE(target) Release/binding.node

> [email protected] install /Users/jschofie/Desktop/rust_projects/rust-in-other/node-ffi/node_modules/ref-struct/node_modules/ref
> node-gyp rebuild

  CXX(target) Release/obj.target/binding/src/binding.o
../src/binding.cc:222:30: warning: 'BooleanValue' is deprecated: Use maybe version [-Wdeprecated-declarations]
  bool persistent = info[3]->BooleanValue();
                             ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8.h:2568:3: note: 'BooleanValue' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version", bool BooleanValue() const);
  ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
../src/binding.cc:253:26: warning: 'Uint32Value' is deprecated: Use maybe version [-Wdeprecated-declarations]
  size_t size = info[2]->Uint32Value();
                         ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8.h:2571:3: note: 'Uint32Value' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version", uint32_t Uint32Value() const);
  ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
../src/binding.cc:360:23: warning: 'Utf8Value' is deprecated: Use Isolate version [-Wdeprecated-declarations]
    String::Utf8Value _str(in);
                      ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8.h:2991:5: note: 'Utf8Value' has been explicitly marked deprecated here
    V8_DEPRECATED("Use Isolate version",
    ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
../src/binding.cc:447:23: warning: 'Utf8Value' is deprecated: Use Isolate version [-Wdeprecated-declarations]
    String::Utf8Value _str(in);
                      ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8.h:2991:5: note: 'Utf8Value' has been explicitly marked deprecated here
    V8_DEPRECATED("Use Isolate version",
    ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
../src/binding.cc:521:26: warning: 'Uint32Value' is deprecated: Use maybe version [-Wdeprecated-declarations]
  size_t size = info[1]->Uint32Value();
                         ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8.h:2571:3: note: 'Uint32Value' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version", uint32_t Uint32Value() const);
  ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
../src/binding.cc:550:32: warning: 'Uint32Value' is deprecated: Use maybe version [-Wdeprecated-declarations]
  uint32_t numZeros = info[1]->Uint32Value();
                               ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8.h:2571:3: note: 'Uint32Value' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version", uint32_t Uint32Value() const);
  ^
/Users/jschofie/.node-gyp/11.9.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
../src/binding.cc:643:8: warning: 'ForceSet' is deprecated [-Wdeprecated-declarations]
  Nan::ForceSet(target, Nan::New<v8::String>("endianness").ToLocalChecked(), Nan::New<v8::String>(CheckEndianness()).ToLocalChecked(), static_cast<PropertyAttribute>(ReadOnly|DontDelete));
       ^
../../../../nan/nan_maybe_43_inl.h:130:1: note: 'ForceSet' has been explicitly marked deprecated here
NAN_DEPRECATED inline Maybe<bool> ForceSet(
^
../../../../nan/nan.h:103:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
../src/binding.cc:644:8: warning: 'ForceSet' is deprecated [-Wdeprecated-declarations]
  Nan::ForceSet(target, Nan::New<v8::String>("NULL").ToLocalChecked(), WrapNullPointer(), static_cast<PropertyAttribute>(ReadOnly|DontDelete));
       ^
../../../../nan/nan_maybe_43_inl.h:130:1: note: 'ForceSet' has been explicitly marked deprecated here
NAN_DEPRECATED inline Maybe<bool> ForceSet(
^
../../../../nan/nan.h:103:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
8 warnings generated.
  SOLINK_MODULE(target) Release/binding.node

> [email protected] install /Users/jschofie/Desktop/rust_projects/rust-in-other/node-ffi/node_modules/ref-napi
> node-gyp rebuild

  CC(target) Release/obj.target/nothing/node_modules/node-addon-api/src/nothing.o
  LIBTOOL-STATIC Release/nothing.a
Traceback (most recent call last):
  File "./gyp-mac-tool", line 611, in <module>
    sys.exit(main(sys.argv[1:]))
  File "./gyp-mac-tool", line 28, in main
    exit_code = executor.Dispatch(args)
  File "./gyp-mac-tool", line 43, in Dispatch
    return getattr(self, method)(*args[1:])
  File "./gyp-mac-tool", line 246, in ExecFilterLibtool
    if not libtool_re.match(line) and not libtool_re5.match(line):
TypeError: cannot use a string pattern on a bytes-like object
make: *** [Release/nothing.a] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/jschofie/.nvm/versions/node/v11.9.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:197:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:254:12)
gyp ERR! System Darwin 18.6.0
gyp ERR! command "/Users/jschofie/.nvm/versions/node/v11.9.0/bin/node" "/Users/jschofie/.nvm/versions/node/v11.9.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/jschofie/Desktop/rust_projects/rust-in-other/node-ffi/node_modules/ref-napi
gyp ERR! node -v v11.9.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jschofie/.npm/_logs/2019-05-30T15_04_42_471Z-debug.log```

Im very confused

Sorry if this isnt the place to ask

using API.DLL

myAPI api = new mynewApi()

api.doThing("string goes here")

Let just say that the above code was an api that worked

How would I turn that code into nodejs stuff using this NODEjs API

so I would be able to do something like this in JS:

function text(string) {
    return Buffer.from(`${text}\0`, "ucs2")
}

const DLLAPI = new mynewApi();
DLLAPI.doThing(text("This would work"))

There is a problem when i use [email protected]

rror: No native build was found for platform=win32 arch=x64 runtime=electron abi=73 uv=1 libc=glibc
at Function.load.path (webpack:///./node_modules/node-gyp-build/index.js?:56:9)
at load (webpack:///./node_modules/node-gyp-build/index.js?:21:30)
at eval (webpack:///./node_modules/ref-napi/lib/ref.js?:8:111)
at Object../node_modules/ref-napi/lib/ref.js (D:\code\electron\electron-vue-demo\dist_electron\index.js:1266:1)
at webpack_require (D:\code\electron\electron-vue-demo\dist_electron\index.js:20:30)
at eval (webpack:///./node_modules/ffi-napi/lib/ffi.js?:7:13)
at Object../node_modules/ffi-napi/lib/ffi.js (D:\code\electron\electron-vue-demo\dist_electron\index.js:226:1)
at webpack_require (D:\code\electron\electron-vue-demo\dist_electron\index.js:20:30)
at eval (webpack:///./src/background.js?:92:13)
at Module../src/background.js (D:\code\electron\electron-vue-demo\dist_electron\index.js:1571:1)
WARN Force killing Electron (process #8972)

Callbacks not working

When migrating a library from ffi over to ffi-napi it seems that callbacks aren't working: they cause a segmentation fault. Using ffi-napi 2.4.6

This is the relevant backtrace with gdb:

(gdb) bt
#0  0x00007ffff7f99bfb in ffi_closure_unix64_inner ()
   from /home/sorunome/repos/js-toxcore-c/node_modules/ffi-napi/build/Release/ffi_bindings.node
#1  0x00007ffff7f9a232 in ffi_closure_unix64 ()
   from /home/sorunome/repos/js-toxcore-c/node_modules/ffi-napi/build/Release/ffi_bindings.node
#2  0x00007ffff43fbb4c in tox_self_connection_status_handler (m=0x5555573f5bc0, connection_status=2, 
    user_data=0x7fffffffd020) at /home/sorunome/repos/c-toxcore/toxcore/tox.c:116  <-- This is where the library calls the callback

Async callback with Electron+Vue

Hello, I'm trying to use Async with a Buffer recieved, I get the correct answer but I can't access variables outside the callback function. In that case I'm trying to assing 'job' variable to 'res' variable value.
It seems that I can't access to another scope with 'this'. I tried 'bind(this)' too. Electron dev-tools crash and everything stops (DevTools was disconnected from the page...).
The C++ function returns 'char *'

getJobsTopaz () { for (let i = 0; i < this.getTotalJobs(); i++) { this.dllFunctions.GetJobIDVB6.async(i, function (err, res) { if (err) throw err this.jobs = res }) } }

Please add support for am64/aarch64

Building fails when libffi is built on 4.19.71 ... aarch64 GNU/Linux:
`
node-gyp rebuild:
...
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/home/steffen/workspace/ffi-napi/build'
CC(target) Release/obj.target/ffi/deps/libffi/src/prep_cif.o
CC(target) Release/obj.target/ffi/deps/libffi/src/types.o
CC(target) Release/obj.target/ffi/deps/libffi/src/raw_api.o
CC(target) Release/obj.target/ffi/deps/libffi/src/java_raw_api.o
CC(target) Release/obj.target/ffi/deps/libffi/src/closures.o
CC(target) Release/obj.target/ffi/deps/libffi/src/x86/ffi.o
../deps/libffi/src/x86/ffi.c: In function 'ffi_prep_args':
../deps/libffi/src/x86/ffi.c:62:31: error: 'FFI_TYPE_MS_STRUCT' undeclared (first use in this function); did you mean 'FFI_TYPE_STRUCT'?
|| ecif->cif->flags == FFI_TYPE_MS_STRUCT)

`

An in-range update of debug is breaking the build 🚨

Version 3.2.0 of debug was just published.

Branch Build failing 🚨
Dependency debug
Current Version 3.1.0
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

debug is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).
  • coverage/coveralls: First build on greenkeeper/debug-3.2.0 at 89.057% (Details).
  • continuous-integration/appveyor/branch: AppVeyor build succeeded (Details).

Release Notes 3.2.0

A long-awaited release to debug is available now: 3.2.0.

Due to the delay in release and the number of changes made (including bumping dependencies in order to mitigate vulnerabilities), it is highly recommended maintainers update to the latest package version and test thoroughly.


Minor Changes

Patches

Credits

Huge thanks to @DanielRuf, @EirikBirkeland, @KyleStay, @Qix-, @abenhamdine, @alexey-pelykh, @DiegoRBaquero, @febbraro, @kwolfy, and @TooTallNate for their help!

Commits

The new version differs by 25 commits.

There are 25 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Removing Objective-C support?

I just saw the commit removing objective-c support. Does this spell doom for nodobjc or is it just cleanup? See this issue where I rebuilt nodobjc using ffi-napi and it worked, but still had an old bug. So whatever got removed must not have been that important... :) Or, I didn't actually rebuild it properly and I'm just using old code by mistake.

unable to install the module failing at the build step

Unable to install node-ffi-napi, failing for the last couple of days. It is failing at the build step with the below error and it seem to be coming from node-addon-api module

/home/asif/work/mq/node_modules/node-addon-api/napi-inl.h: In constructor ‘Napi::CallbackScope::CallbackScope(napi_env, int)’:
/home/asif/work/mq/node_modules/node-addon-api/napi-inl.h:3412:57: error: class ‘Napi::CallbackScope’ does not have any field named ‘_scope’
napi_env env, napi_callback_scope scope) : _env(env), _scope(scope) {
^
/home/asif/work/mq/node_modules/node-addon-api/napi-inl.h: In constructor ‘Napi::CallbackScope::CallbackScope(napi_env, napi_async_context)’:
/home/asif/work/mq/node_modules/node-addon-api/napi-inl.h:3419:41: error: ‘_scope’ was not declared in this scope
_env, Object::New(env), context, &_scope);
^
/home/asif/work/mq/node_modules/node-addon-api/napi-inl.h:3419:47: error: ‘napi_open_callback_scope’ was not declared in this scope
_env, Object::New(env), context, &_scope);
^
/home/asif/work/mq/node_modules/node-addon-api/napi-inl.h: In destructor ‘virtual Napi::CallbackScope::~CallbackScope()’:
/home/asif/work/mq/node_modules/node-addon-api/napi-inl.h:3424:35: error: ‘_scope’ was not declared in this scope
napi_close_callback_scope(_env, _scope);
^
/home/asif/work/mq/node_modules/node-addon-api/napi-inl.h:3424:41: error: ‘napi_close_callback_scope’ was not declared in this scope
napi_close_callback_scope(_env, _scope);
^
/home/asif/work/mq/node_modules/node-addon-api/napi-inl.h: At global scope:
/home/asif/work/mq/node_modules/node-addon-api/napi-inl.h:3427:32: error: expected type-specifier before ‘napi_callback_scope’
inline CallbackScope::operator napi_callback_scope() const {
^
ffi_bindings.target.mk:107: recipe for target 'Release/obj.target/ffi_bindings/src/ffi.o' failed
make: *** [Release/obj.target/ffi_bindings/src/ffi.o] Error 1
make: Leaving directory '/home/asif/work/mq/node_modules/ffi-napi/build'

Callback related crash?

I'm attempting to port an app from node-ffi to node-ffi-napi, and it appears to be a little crashy. I've isolated and reproduced a crash which seems to be related to callbacks. A small repro can be found here https://gist.github.com/repl-chris/8bc15d8ba1a8e9a88a93f7c791a1fa46 - it crashes within a few seconds using node-ffi-napi, and runs perfectly fine using node-ffi...I've reproduced it on windows 10 and windows server 2008 using node 8.9. I was thinking perhaps the callback was getting GC'd but even keeping a reference to it on global does not help. If I'm doing something wrong to cause this crash please let me know.

Segmentation fault in node 13

Requiring ffi-napi module results in a segmentation fault:

$ node -e "var ffi = require('ffi-napi')"
zsh: segmentation fault (core dumped)  node -e "var ffi = require('ffi-napi')"

Tested with node version v13.3.0.

Types

I wasn't clear in docs but, if I have the follow situation :
In my interface I have a parameter type Byte,Can I declare as a int ??

Example

[DllImport(DLLNAME, CallingConvention = CallingConvention.StdCall)]
        public static extern int OpenNetPort(int Port,
                                             string IPaddr,
                                             byte ComAddr,
                                             ref int PortHandle);
var PortHandle = ref.types.int 
var PortHandlePtr = ref.refType(PortHandle);

var UHFReader288MP = ffi.Library('UHFReader288MP', {
    "OpenNetPort": ['int', ['int', 'string', 'int', PortHandlePtr]],
});

Async calls do not work in Electron on Windows

As discovered in this issue with tdl, asynchronous calls do not work properly in Electron on Windows and result in a libuv-related error window:

image

Minimal example courtesy of Bannerets:

  1. Create an empty Node.js project.
  2. Install ffi-napi, ref-napi, electron, and electron-rebuild.
  3. Run npx electron-rebuild to retarget the native library bindings to Electron.
  4. Create index.js containing this code:
const ffi = require('ffi-napi');

console.log(0);

const kernel32 = ffi.Library('kernel32', {
  Sleep: ['void', ['int32']]
});

console.log(1);

kernel32.Sleep.async(3000, err => console.log('err', err));

console.log(2);
  1. Run npx electron ..
  2. Console prints 0 and 1, but never reaches 2 and displays this pop-up error window instead.

Versions:

  • Windows 10
  • Electron 3.0.6 (Node 10.2.0)
  • electron-rebuild 1.8.2
  • ffi-napi 2.4.3
  • ref-napi 1.4.0

aarch64 binary release

Hi Team,

The aarch64 architecture is already supported by node-ffi-napi, I would like to know what is required to be done in order to get aarch64 prebuilt binary release.

Please share your thoughts on this and let me know if anything could be done from my end to achieve this.

Doesn't work with create-react-app

Steps:

  1. npm i -g create-react-app
  2. create-react-app cra-ffi-test
  3. cd cra-ffi-test
  4. yarn add ffi-napi
  5. add import ffi from 'ffi-napi' to App.js
  6. yarn start

output snippet:

TypeError: Error.captureStackTrace is not a function
getFileName
E:/Code/Sites/Node/cra-ffi-test/node_modules/bindings/bindings.js:129

  126 | }; // run the 'prepareStackTrace' function above
  127 | 
  128 | 
> 129 | Error.captureStackTrace(dummy);
      | ^  130 | dummy.stack; // cleanup
  131 | 
  132 | Error.prepareStackTrace = origPST;

bindings
E:/Code/Sites/Node/cra-ffi-test/node_modules/bindings/bindings.js:55

  52 | }); // Get the module root
  53 | 
  54 | if (!opts.module_root) {
> 55 |   opts.module_root = exports.getRoot(exports.getFileName());
     | ^  56 | } // Ensure the given bindings name ends with .node
  57 | 
  58 | 

Crash during calling user32.EnumWindows()

system

  • AMD 2700X, 32G DDR4
  • win7 64bit
  • nodejs v11.3.0 64bit, v10.14.1 32bit

Code

  "dependencies": {
    "ffi-napi": "^2.4.4"
  }
// start calc.exe

const ffi = require('ffi-napi')

const user32 = ffi.Library( 'user32.dll', {
  EnumWindows: ['int', ['pointer', 'int'] ],
  GetWindowTextW: ['int', ['pointer', 'pointer', 'int'] ],
})

const enumWindowsProc = ffi.Callback(
  'int',
  ['pointer', 'int'],
  (hWnd, lParam) => { // stop loop if return false
    const buf = Buffer.alloc(254)
    const len = user32.GetWindowTextW(hWnd, buf, 254)

    if (len) {
      const name = buf.toString('ucs2')

      if (name.indexOf('Calculator') === 0) {
        console.log('got')
        return false
      }
    }

    return true
  },
)
// process.on('exit', () => {
//   enumWindowsProc
// })

for (let i = 0; i < 10; i++) {
  console.log('start---', i)
  user32.EnumWindows(enumWindowsProc, i)
}
console.log('end')

expected:

start--- 0
got
start--- 1
got
start--- 2
got
start--- 3
got
start--- 4
got
start--- 5
got
start--- 6
got
start--- 7
got
start--- 8
got
start--- 9
got
end

real:

start--- 0

debug:

It works with node-ffi

  "dependencies": {
    "ffi": "git+https://github.com/node-ffi/node-ffi.git"
  }
const ffi = require('ffi')

With this test https://github.com/waitingsong/node-win32-api/blob/master/test/70_user32.test.ts , the error like this:

npm ERR! code ELIFECYCLE
npm ERR! errno 3221225725
npm ERR! [email protected] test: `mocha --opts test/mocha.opts`
npm ERR! Exit status 3221225725
....

[HELP] which thread does node-ffi-napi itself run in ?

scenario:
I have a JS function A, it invokes function B in my C library via node-ffi-napi.

I know func A runs in Node.js' main thread, but which thread does node-ffi-napi itself run in ? and what about function B in my C library?

if i try to invoke win32 api GetCurrentThreadId via node-ffi-napi, can i get thread id of Node.js' main thread?

@addaleax whould you please help me out, thanks !

An in-range update of get-uv-event-loop-napi-h is breaking the build 🚨

The dependency get-uv-event-loop-napi-h was updated from 1.0.5 to 1.0.6.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

get-uv-event-loop-napi-h is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build passed (Details).
  • coverage/coveralls: First build on greenkeeper/get-uv-event-loop-napi-h-1.0.6 at 89.057% (Details).
  • continuous-integration/appveyor/branch: AppVeyor build failed (Details).

Commits

The new version differs by 2 commits.

  • 46152de v1.0.6
  • 0106345 Fix paths-with-spaces handling for Windows builds

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of get-uv-event-loop-napi-h is breaking the build 🚨

The dependency get-uv-event-loop-napi-h was updated from 1.0.2 to 1.0.4.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

get-uv-event-loop-napi-h is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/appveyor/branch: Waiting for AppVeyor build to complete (Details).
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 4 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

fficonfig.h cannot be found when running node-gyp rebuild on OpenBSD

When I try to run $ node-gyp rebuild, this happens:

bastille% node-gyp rebuild
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | openbsd | x64
gyp info spawn /usr/local/bin/python2
gyp info spawn args [ '/usr/local/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/home/morfent/Documents/perl6/nqp/node-ffi-napi/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/home/morfent/.node-gyp/10.15.0/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/home/morfent/.node-gyp/10.15.0',
gyp info spawn args   '-Dnode_gyp_dir=/usr/local/lib/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/home/morfent/.node-gyp/10.15.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/home/morfent/Documents/perl6/nqp/node-ffi-napi',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn gmake
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
gmake: Entering directory '/home/morfent/Documents/perl6/nqp/node-ffi-napi/build'
  CC(target) Release/obj.target/ffi/deps/libffi/src/prep_cif.o
In file included from ../deps/libffi/src/prep_cif.c:27:
../deps/libffi/include/ffi_common.h:17:10: fatal error: 'fficonfig.h' file not found
#include <fficonfig.h>
         ^~~~~~~~~~~~~
1 error generated.
gmake: *** [deps/libffi/ffi.target.mk:121: Release/obj.target/ffi/deps/libffi/src/prep_cif.o] Error 1
gmake: Leaving directory '/home/morfent/Documents/perl6/nqp/node-ffi-napi/build'
gyp ERR! build error 
gyp ERR! stack Error: `gmake` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System OpenBSD 6.4
gyp ERR! command "/usr/local/bin/node" "/usr/local/bin/node-gyp" "rebuild"
gyp ERR! cwd /home/morfent/Documents/perl6/nqp/node-ffi-napi
gyp ERR! node -v v10.15.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

I looked through some of the gyp files required for installing and found that the headers for OpenBSD in config/ don't exist. I'll build them and make a pullreq

passing a callback to c app

I have a dll that has a function CIDR_RegisterEvent that gets a function pointer and a mask int, the dll is a bridge for a device and it calls the function when a new event is sent from device.
I use the following code to connect to function.

var ffi = require('ffi-napi')
var ref = require('ref')
var stringPtr = ref.refType(ref.types.CString);
var int = ref.types.int;
var libprime = ffi.Library('POS_CIDR.dll', {
  'CIDR_Info': [stringPtr, []],
  'CIDR_RegisterEvent': ['int', ['void *', ref.types.int32]],
});
c = ffi.Callback('void', ['int', 'string'],
  function(id, str) {
    console.log("id: ", id);
    console.log("name: ", str);
  });
libprime.CIDR_RegisterEvent(c, 5);
setInterval(function() {
  console.log("*");
}, 1000);
process.on('exit', function() {
  c;
});

When I run the code my device led turns on so I know it connects but y callback function never runs.
Can anyone detect the problem in my code?
I use the setInterval function the make the app run forever.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.