aapoalas / denonomicon

The Dark Arts of Deno Foreign Function Interface Programming
https://denonomicon.deno.dev/
MIT License
27 stars 0 forks source link

Deno.UnsafePointer.of Type mismatch #6

Closed dacevedo12 closed 2 years ago

dacevedo12 commented 2 years ago

Any ArrayBuffer or TypedArray (Uint8Array etc.) created in JavaScript can be passed as a pointer parameter to an FFI symbol. It is also possible to get the pointer integer value from a buffer using the Deno.UnsafePointer.of()

On Deno 1.25.0 I'm getting

Argument of type 'ArrayBuffer' is not assignable to parameter of type 'UnsafeCallback<UnsafeCallbackDefinition<readonly NativeType[], NativeResultType>> | TypedArray'.

Passing it directly doesn't work either

Type 'ArrayBuffer' is not assignable to type 'PointerValue'
aapoalas commented 2 years ago

This is an issue in the Deno's exposed types for these classes / methods, where it doesn't mention ArrayBuffer.

Also, PointerValue points to you using "pointer" as the parameter type declaration, and not "buffer". "pointer" expects pointer values, essentially a null or number or BigInt.