Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misleading description in doc about napi_get_typedarray_info #244

Closed
yw662 opened this issue Apr 2, 2018 · 1 comment
Closed

misleading description in doc about napi_get_typedarray_info #244

yw662 opened this issue Apr 2, 2018 · 1 comment

Comments

@yw662
Copy link

yw662 commented Apr 2, 2018

In https://nodejs.org/dist/latest-v9.x/docs/api/n-api.html#n_api_napi_typedarray_type

[out] data: The data buffer underlying the typed array.
[out] byte_offset: The byte offset within the data buffer from which to start projecting the TypedArray.

It seems that the data is started from &data[byte_offset],

but actually in node_api.cc,

if (data != nullptr) {
    *data = static_cast<uint8_t*>(buffer->GetContents().Data()) +
            array->ByteOffset();
}

if (byte_offset != nullptr) {
    *byte_offset = array->ByteOffset();
}

So, the doc should clarify that the out arg data actually points to &data[byte_offset].

@mhdawson
Copy link
Member

mhdawson commented May 15, 2018

Thanks for catching this. PR to fix nodejs/node#20747.

mhdawson added a commit to mhdawson/io.js that referenced this issue May 15, 2018
The data pointer returned for the typedarray has
already been adjusted by the offset so it does not
point to the start of the buffer, instead id points
to the start of the first element.

I think we probably would have liked it to point to the
start of the buffer, but we can't change as that would be
a breaking change.

Update the doc to match the implementation.

Fixes: nodejs/node-addon-api#244
MylesBorins pushed a commit to nodejs/node that referenced this issue May 29, 2018
The data pointer returned for the typedarray has
already been adjusted by the offset so it does not
point to the start of the buffer, instead id points
to the start of the first element.

I think we probably would have liked it to point to the
start of the buffer, but we can't change as that would be
a breaking change.

Update the doc to match the implementation.

PR-URL: #20747
Fixes: nodejs/node-addon-api#244
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants