Skip to content

fix(napi): normalize empty view data pointers#56

Open
GrapeBaBa wants to merge 6 commits into
fix/napi-out-parameters-v2from
fix/napi-null-view-data
Open

fix(napi): normalize empty view data pointers#56
GrapeBaBa wants to merge 6 commits into
fix/napi-out-parameters-v2from
fix/napi-null-view-data

Conversation

@GrapeBaBa

@GrapeBaBa GrapeBaBa commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Motivation

Node-API permits ArrayBuffer, Buffer, TypedArray, and DataView data out parameters to be NULL or an arbitrary pointer when the reported length is zero. This commonly occurs for empty and detached values. The previous binding received those results into non-null [*]u8 storage, so a valid Node-API result could create a zero-length Zig slice whose pointer violates the slice type invariant. Normalizing this case at the binding boundary keeps the public slice API safe, while the TypedArray zero-length branch avoids applying element-alignment casts to an empty byte-slice sentinel.

Summary

  • represent Node-API void* data out parameters as nullable Zig pointers
  • normalize successful zero-length results to safe empty slices without changing public return types
  • skip TypedArray alignment casts when the element length is zero
  • cover shared null-plus-zero normalization in Zig and exercise empty and detached values through the example API

@GrapeBaBa
GrapeBaBa changed the base branch from fix/napi-out-parameters to fix/napi-out-parameters-v2 July 20, 2026 12:09
@GrapeBaBa
GrapeBaBa marked this pull request as ready for review July 20, 2026 14:26
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

Successfully merging this pull request may close these issues.

1 participant