src: handle no support for external buffers#1273
src: handle no support for external buffers#1273legendecas wants to merge 1 commit intonodejs:mainfrom
Conversation
|
Thank you for adding this feature. It looks like the approach in this PR can (conditionally) remove the presence of |
|
@lovell it is intentional and |
| ### NewOrCopy | ||
|
|
||
| Wraps the provided external data into a new `Napi::Buffer` object. When the | ||
| [external buffer][] is not supported, allocates a new `Napi::Buffer` object and |
There was a problem hiding this comment.
| [external buffer][] is not supported, allocates a new `Napi::Buffer` object and | |
| [external buffer][] is not supported by the underlying runtime, allocates a new `Napi::Buffer` object and |
mhdawson
left a comment
There was a problem hiding this comment.
LGTM other than the suggested wording change to the docs
|
@legendecas looks like compilation failed on windows: buffer.cc
D:\a\node-addon-api\node-addon-api\napi-inl.h(2504,17): error C2065: 'napi_no_external_buffers_allowed': undeclared identifier [D:\a\node-addon-api\node-addon-api\test\build\binding_noexcept_maybe.vcxproj]
D:\a\node-addon-api\node-addon-api\napi-inl.h(2500): message : while compiling class template member function 'Napi::Buffer<uint16_t> Napi::Buffer<uint16_t>::NewOrCopy(napi_env,T *,size_t)' [D:\a\node-addon-api\node-addon-api\test\build\binding_noexcept_maybe.vcxproj]
with
[
T=uint16_t
]
D:\a\node-addon-api\node-addon-api\test\buffer.cc(153): message : see reference to function template instantiation 'Napi::Buffer<uint16_t> Napi::Buffer<uint16_t>::NewOrCopy(napi_env,T *,size_t)' being compiled [D:\a\node-addon-api\node-addon-api\test\build\binding_noexcept_maybe.vcxproj]
with
[
T=uint16_t
]
D:\a\node-addon-api\node-addon-api\test\buffer.cc(29): message : see reference to class template instantiation 'Napi::Buffer<uint16_t>' being compiled [D:\a\node-addon-api\node-addon-api\test\build\binding_noexcept_maybe.vcxproj]
D:\a\node-addon-api\node-addon-api\napi-inl.h(2529,17): error C2065: 'napi_no_external_buffers_allowed': undeclared identifier [D:\a\node-addon-api\node-addon-api\test\build\binding_noexcept_maybe.vcxproj]
D:\a\node-addon-api\node-addon-api\test\buffer.cc(180): message : see reference to function template instantiation 'Napi::Buffer<uint16_t> Napi::Buffer<uint16_t>::NewOrCopy<`anonymous-namespace'::CreateOrCopyExternalBufferWithFinalize::<lambda_ed832a77ce45243ca6d5fe088f290640>>(napi_env,T *,size_t,Finalizer)' being compiled [D:\a\node-addon-api\node-addon-api\test\build\binding_noexcept_maybe.vcxproj]
with
[
T=uint16_t,
Finalizer=`anonymous-namespace'::CreateOrCopyExternalBufferWithFinali |
|
It looks like when When Ideally I would like to be able to use |
|
@Julusian thanks for the suggestion! I'll update the PR to include a test to verify |
204c751 to
67beb3e
Compare
|
Seems like the test |
|
|
||
| template <typename T> | ||
| template <typename Finalizer, typename Hint> | ||
| inline Buffer<T> Buffer<T>::NewOrCopy(napi_env env, |
There was a problem hiding this comment.
I assume its the templates that prevent us from having one function with all the parameters and the others calling that one with dummy/null parameters, right?
There was a problem hiding this comment.
Not really. When the template parameter Hint is set, the Finalizer must accept a third parameter Hint too. However, we allow Finalizer to be like void operator()(Env env, T* data). So we have to distinguish if Hint is present.
mhdawson
left a comment
There was a problem hiding this comment.
LGTM on updated version with one question
|
@mhdawson is this still looking good to you with the replied question? If so, I think we've discussed about the failure of |
PR-URL: #1273 Reviewed-By: Michael Dawson <midawson@redhat.com
|
@legendecas LGTM |
PR-URL: nodejs/node-addon-api#1273 Reviewed-By: Michael Dawson <midawson@redhat.com
Fixes #1257.
NODE_API_NO_EXTERNAL_BUFFERS_ALLOWEDintroduced in node-api: handle no support for external buffers node#45181 is defined, hides the methods that can create external buffers.Napi::Buffer::NewOrCopyto create buffer from external buffers that are compatible with runtimes like electron conveniently.