-
Notifications
You must be signed in to change notification settings - Fork 2
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
Handle Array Arguments Better #21
base: main
Are you sure you want to change the base?
Conversation
@@ -24,15 +24,19 @@ export function initArgument(type) { | |||
g.base_info.unref(info); | |||
return result; | |||
} | |||
default: { | |||
return cast_ptr_u64(cast_buf_ptr(new Uint8Array(1))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I believe all arguments should be initialised to an empty pointer (GIArgInfo
)
This comment was marked as duplicate.
This comment was marked as duplicate.
Sorry, something went wrong.
@@ -24,15 +24,19 @@ export function initArgument(type) { | |||
g.base_info.unref(info); | |||
return result; | |||
} | |||
default: { | |||
return cast_ptr_u64(cast_buf_ptr(new Uint8Array(1))); |
This comment was marked as duplicate.
This comment was marked as duplicate.
Sorry, something went wrong.
Here's some test code for this:
Although currently, it seems |
except arguments of course
and don't return the length argument. It's just noise since you can already get the length of an array using JS's .length and is ommitted in GJS as well. the code doesn't read too well though
ensures that the return argument's length can be inferred
For example, `GLib.Bytes.getData`. This needs to be investigated
Hello again. This PR is currently a draft because while it does not depend on #17, the code there needs to be merged before this one because by doing so, the code in this PR will be vastly simplified.
This PR does 3 main things:
1. Unbox C Arrays into TypedArrays (
Uint8Array
,Uint16Array
etc..)This is similar to GJS behaviour and differs from the current behaviour where each element would be unboxed into an argument. This doesn't work for stuff like
GLib.file_get_contents
, which returns an array, but the array is of random data. This PR would, for example, produce aUint8Array
instead of an array of numbers.2. Utilise the lengthArg to unboxArrays
Functions that return an array usually have a length parameter. For the
GLib.file_get_contents
case, that parameter is calledlength
. The bindings now automatically infer the array's length from the related parameter.3. Omit the length parameter from being returned.
In the case of the above function, since
GLib.file_get_contents
returns an array, thelength
parameter is no longer required as we can infer that fromUint8Array.length
and adds to the noise. This behaviour is what GJS does, too.TODO in a separate PR: Handle different arrays based on the
GIArrayType
. Currently, deno_gi only handles C arrays, but there are other types of arrays namely:GArray
,GPtrArray
andGByteArray
. Adding support for them should be pretty straightforward. Maybe an issue needs to be filed to keep track of this.