Skip to content

n-api: Add optional length to functions accepting const char *  #15108

Closed
@digitalinfinity

Description

@digitalinfinity
  • Version: 8
  • Platform: all
  • Subsystem: n-api

Migrating nodejs/abi-stable-node#254 opened by @RReverser to this repo for better visibility:

As discussed in the last meeting, zero-terminated const char*, while popular in C land, might be problematic for consumers in other languages having different string representation (for example, Rust with non-zero-terminated string slices represented as data + length).

Some N-API functions already accept optional length that, when set to -1, would mean a length calculated from zero-terminated string and explicit byte length otherwise.

It's worth to go through a list of functions that accept const char* and add length parameter where it's missing, especially for functions that don't provide variants with napi_value as a string, namely:

  • napi_create_function
  • napi_define_class
  • napi_module_register -> napi_module struct

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.node-apiIssues and PRs related to the Node-API.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions