ahgilak / deno_gi

Deno port of Gnome libraries (such as Gtk).
https://deno.land/x/deno_gi
33 stars 2 forks source link

Get Arguments Directly From Pointers #17

Closed vixalien closed 11 months ago

vixalien commented 11 months ago

I lacked a better title for this PR :^(

This PR is significant because it implements passing around arguments in their raw pointer form instead of allocating new ArrayBuffers.

This is done by creating a BigUint64Array, passed as an argument to FFI functions (gi_(function|method|callback)_invoke). The FFI functions directly manipulate and set the pointers as indices of the BigUint64Array, and we can get the assigned pointers directly from the BigUint64Array. Here's some pseudocode to explain this:

const array = BigUint64Array(outArgDetails.length);

// the array is initially empty
console.log(array) // [0,0,0,0,....]

// invoke the function with the array as outArgs
g.function_info.invoke(
  function_name,
  //...
  outArgs,
  // ....
);

// now the array has been modified to have pointers
console.log(array) // [28933n, 329839n, 23893495834n, ...]

// now we can use the pointers directly (in the case of numbers, the values are not pointers but the numbers themselves directly

Thanks for taking a look at this.

I also created a new file, examples/bytes.ts, a temporary file to test things out since deno_gi doesn't have actual tests at the moment (I'm working on it...). You can delete this before merging. Thanks!

vixalien commented 11 months ago

Maybe it's time to review this next?

ahgilak commented 11 months ago

Sorry it's taking so long, I'm a bit busy these days. I'll review this by the end of the week.

vixalien commented 11 months ago

Sorry it's taking so long, I'm a bit busy these days. I'll review this by the end of the week.

Hey! No worries. Take your time, and you don't have to review these ASAP. I just create a PR for every thing I change so the changes don't get lost. Please don't feel pressured to review this and take your time!

vixalien commented 11 months ago

I've rebased the code and removed the bytes.ts file. I plan to reintroduce plausible tests later.