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

Support transfer none return strings in callbacks #920

Merged
merged 1 commit into from
Aug 9, 2023

Conversation

badcel
Copy link
Member

@badcel badcel commented Aug 6, 2023

This is working as this only applies to callback return values of type string. As the ownership is not transferred this implies that the string should never be freed as it is generated by the callback.

  • I agree that my contribution may be licensed either under MIT or any version of LGPL license.

@badcel badcel force-pushed the support-transfer-none-return-strings-in-callbacks branch 3 times, most recently from adb0cc8 to 3f0f130 Compare August 7, 2023 20:35
@badcel badcel changed the title Use StringToPtrUtf8 for transfer none strings Support transfer none return strings in callbacks Aug 7, 2023
This introduces a new public class "ConstantString". This class can be used to keep a pointer to a string alive as long as the instance is alive.

In case of callbacks a returned string with transfer none should live forever. A user can create an instance of "ConstantString" and keep the instance around forever to keep the pointer alive forever.

This puts the burden of managing string memory which lives forever on the user side.

If the string would simply allocated by gir.core and never be freed there could be huge memory leaks if strings are allocated again and again and they would never be freed.
@badcel badcel force-pushed the support-transfer-none-return-strings-in-callbacks branch from 3f0f130 to 54e93a0 Compare August 9, 2023 19:07
@badcel badcel merged commit 2bf98ca into main Aug 9, 2023
@badcel badcel deleted the support-transfer-none-return-strings-in-callbacks branch August 9, 2023 19:19
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.

1 participant