| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Review requested:
|
Sorry, something went wrong.
|
We discussed this on today's Node API meeting. This makes sense to me. Does anyone else on the team have any issues / concerns? We may need to look at the node-addon-api wrapper as well, but since this is an inline header it is not particularly needed for the ABI stability guarantees that Node API has. |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM. From the discussion in the last Node-api team meeting my understaning is that does not change anything since CDECL was already the default, but it does help my making it explicit.
Sorry, something went wrong.
Sorry, something went wrong.
Sorry, something went wrong.
PR-URL: #42780 Reviewed-By: Michael Dawson <midawson@redhat.com>
PR-URL: #42780 Reviewed-By: Michael Dawson <midawson@redhat.com>
PR-URL: #42780 Reviewed-By: Michael Dawson <midawson@redhat.com>
PR-URL: nodejs/node#42780 Reviewed-By: Michael Dawson <midawson@redhat.com>
| Back | FazBrowse Home | New Git URL |
The issue
The Node-API is a quite generic ABI-safe API that can be used as JavaScript engine ABI-safe API outside of Node.JS project.
The issue is that currently it does not specify calling conventions which is critical if Windows DLLs compiled with different default calling conventions. It is not important for x64 or non-Windows platforms because they use one predefined calling convention, but for Windows x86 applications there are multiple calling conventions, and their mismatch causes a runtime crash.
E.g. I had previously added __cdecl to v8jsi.dll copy of js_native_api.h, but we still saw crashes in Windows x86 because __cdecl was not added to function pointers in js_native_api_types.h. The issue is being addressed by microsoft/v8-jsi#122.
This example shows how important the calling conventions are for Window x86 platform.
The solution
In this PR we are adding __cdecl to all functions and function pointers that target Win32 platform.
To do that we add a new macro NAPI_CDECL. It is expanded to __cdecl for Win32 platforms and to nothing for other platforms.
Discussion
This PR sets __cdecl as the calling conventions because it is the default in C/C++ compilers.
It would be ideal to use __stdcall calling conventions to match Windows API because it produces more compact code on calling side, but my concern is that such change may affect existing code. Though, if Node.JS is not shipped for x86, then it may be still safe to use __stdcall instead of __cdecl.