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

Box arguments taking into consideration deep pointers #34

Merged
merged 15 commits into from
Oct 2, 2024

Conversation

vixalien
Copy link
Collaborator

@vixalien vixalien commented Jun 14, 2024

In GI, some values are nested in pointers, while others are not.

Direct values (no pointers)

For example, given a function like the following:

gdouble get_double() {}

To unbox the value above, you will just need to do dataView.getFloat64().

pointers

This is usually common in outArgs

void get_double(gdouble *out) {}

To unbox the argument above, we need to get the value pointed to, and then finally get the value.

const pointer = cast_u64_ptr(dataView.getBigUint64());
const pointed_to = deref_buf(pointer, 8);
pointed_to.getFloat64();

Doubly pointed to values

void get_double(gdouble **out) {}

While extremely rare, it is possible that values are contained in a pointer to a pointer. To check for these values, we use GITypeInfo.is_pointer. Here is an example of this usage: https://gitlab.gnome.org/GNOME/gobject-introspection/-/blob/main/tests/scanner/regress.c?ref_type=heads#L647

Because out (and inout) arguments are already pointers, if such an argument has is_pointer() set to true, it effectively means it's a pointer to a pointer.

Note that the types of GI_DIRECTION_OUT and GI_DIRECTION_INOUT parameters will only be pointers if the underlying type being transferred is a pointer (i.e. only if the type of the C function’s formal parameter is a pointer to a pointer).

To unbox these values, we need to double get the value, as implemented in this PR with a new value called nPointers.

const pointer = cast_u64_ptr(dataView.getBigUint64());
const pointed_to = deref_buf(pointer_view, 8);

const pointer2 = cast_u64_buf(new ExtendedDataView(pointed_to).getBigUint64());
const pointed_to2 = deref_buf(pointer2, 8);

pointed_to2.getFloat64();

I've also added a GStreamer example, as that should be interesting...

@vixalien vixalien force-pushed the wip/vixalien/pointer-boxing branch from cc13bed to 3a97c4c Compare June 16, 2024 18:17
@vixalien
Copy link
Collaborator Author

I've also added various array tests for strings like strings, GTypes, etc...

I think this should be reviewed so that I can start working on the next batch of tests

@ahgilak
Copy link
Owner

ahgilak commented Jun 21, 2024

running gstreamer example results in segmentation fault

@vixalien
Copy link
Collaborator Author

you're right. this is due to GStreamer's insistence on passing everything as pointers. working on it

@vixalien
Copy link
Collaborator Author

Hello. I haven't been able to diagnose what's wrong with GStreamer and I would suggest we merge this as-is (probably removing the gstreamer code) as other parts work.

This would allow us to iterate on other parts faster.

@vixalien
Copy link
Collaborator Author

ping

@ahgilak
Copy link
Owner

ahgilak commented Aug 20, 2024

so is this ready to merge now?

@vixalien
Copy link
Collaborator Author

Yes, I guess. The GStreamer demo will still be (intentionally) broken though.

@ahgilak
Copy link
Owner

ahgilak commented Sep 24, 2024

hello @vixalien

since I don't have enough time to maintain this project alone, and you did a great job with your contributions, I wanted to add you as a collaborator so you could merge and maintain codes. are you okay with that?

@vixalien
Copy link
Collaborator Author

Hello. no worries. Do you have a matrix account or other chat so that we can communicate more easily?

@ahgilak
Copy link
Owner

ahgilak commented Sep 30, 2024

I'm not active on matrix. you can reach me via email [email protected] or telegram ahgilak

@ahgilak ahgilak merged commit 8ab0cdc into ahgilak:main Oct 2, 2024
1 check passed
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.

2 participants