Skip to content

Buffer data argument should be void*, not char* #135

Closed

Description

@kkoopa

As I mentioned in another issue, it is arguably a historical oversight that node::Buffer takes a char* as the data argument and not a void*. This leads to mandatory typecasting whenever something else than a char* is given to node::Buffer. Now is a good chance not to repeat the same mistake.

NODE_EXTERN napi_status napi_create_buffer(napi_env e,
                                           size_t size,
                                           void** data,
                                           napi_value* result);
NODE_EXTERN napi_status napi_create_external_buffer(napi_env e,
                                                    size_t size,
                                                    void* data,
                                                    napi_finalize finalize_cb,
                                                    napi_value* result);
NODE_EXTERN napi_status napi_create_buffer_copy(napi_env e,
                                                const void* data,
                                                size_t size,
                                                napi_value* result);
NODE_EXTERN napi_status napi_is_buffer(napi_env e, napi_value v, bool* result);
NODE_EXTERN napi_status napi_get_buffer_info(napi_env e,
                                             napi_value v,
                                             void** data,
                                             size_t* length);

Additionally, the C++ layer could use a class template parametrized on the type of data to ensure further type safety.

Activity

  1. boingoing commented on Mar 16, 2017

    @boingoing

    Resolved by #145

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions