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

BREAKING(ext/ffi): Remove Deno.UnsafePointer indirection #14915

Merged
merged 4 commits into from Jun 20, 2022

Conversation

littledivy
Copy link
Member

@littledivy littledivy commented Jun 20, 2022

This commits removes the Deno.UnsafePointer
wrapper around FFI pointers. A pointer is now
represented as a bigint primitive.

There still exist the Deno.UnsafePointer.of
API to get pointer value for a TypedArray and
Deno.UnsafeCallback.

const ptr = Deno.UnsafePointer.of(buf);

This commit also removes the extra processing for
FFI parameters. Hence, Deno.UnsafeCallback must be
passed as a pointer.

} else {
throw new TypeError(`Invalid FFI argument type '${type}'`);
static of(value) {
if (ObjectPrototypeIsPrototypeOf(UnsafeCallbackPrototype, value)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supporting UnsafeCallbacks for UnsafePointer.of seems unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will get rid of the UnsafePointer class completely. I was thinking that we could turn this into a more common interface until it's removed.

ext/ffi/00_ffi.js Outdated Show resolved Hide resolved
@aapoalas
Copy link
Collaborator

LGTM. Did you check performance improvement?

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please update the manual before landing the PR

@aapoalas
Copy link
Collaborator

Oh yeah, one thing to note publicly in the PR on this implementation is that after this there will be no difference in typing for:

  • uint64
  • int64
  • usize
  • isize
  • pointer
  • function
    with the exception that pointer allows for TypedArrays in addition to bigints, and that number type arguments also allow for plain numbers instead of only bigints.

So, a lot of the possible benefits of types are lost, unfortunately.

@littledivy
Copy link
Member Author

yeah, I think the most notable will be for callbacks. 64bit numeric types + pointers are bigint in JS.

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.

None yet

3 participants