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

Add ptr() / ptrw() to the arrays, add missing String methods, add missing CharString method implementations. #695

Merged
merged 1 commit into from
Feb 15, 2022

Conversation

bruvzg
Copy link
Member

@bruvzg bruvzg commented Feb 14, 2022

  • Adds ptr() / ptrw() to the arrays, and renames existing ptr to _native_ptr to avoid conflict.
  • Adds ptr() / ptrw(), parse_utf* and utf* methods to the String.
  • Adds missing implementations of length() and get_data() methods of Char*String.

@bruvzg bruvzg added enhancement This is an enhancement on the current functionality topic:gdextension This relates to the new Godot 4 extension implementation labels Feb 14, 2022
@bruvzg bruvzg added this to the 4.0 milestone Feb 14, 2022
@bruvzg bruvzg marked this pull request as ready for review February 14, 2022 07:09
@@ -246,7 +246,7 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
result.append(f"\tstatic constexpr size_t {snake_class_name}_SIZE = {size};")
result.append(f"\tuint8_t opaque[{snake_class_name}_SIZE] = {{}};")
result.append(
f"\t_FORCE_INLINE_ GDNativeTypePtr ptr() const {{ return const_cast<uint8_t (*)[{snake_class_name}_SIZE]>(&opaque); }}"
f"\t_FORCE_INLINE_ GDNativeTypePtr _native_ptr() const {{ return const_cast<uint8_t (*)[{snake_class_name}_SIZE]>(&opaque); }}"
Copy link
Member

@akien-mga akien-mga Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that here it seems to be private, while in all implementations it's public, is that intended/a problem?

And if it needs to be public, should it be renamed native_ptr()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has friend Variant to use it, and AFAIK it's not intended to be used outside Variant source. Moved it to the private int the hand-made headers for consistency.

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very knowledgeable about the godot-cpp implementations but these additions and fixes definitely make sense.

@bruvzg bruvzg force-pushed the ptrs_and_stuff branch 2 times, most recently from ef3c391 to c9de291 Compare February 14, 2022 20:53
@bruvzg
Copy link
Member Author

bruvzg commented Feb 14, 2022

Also, added move constructor / assignment operator to the Char*String, or something like this will result in double free:

CharString cs = text.utf8(); 
//do stuff with cs
cs = text2.utf8();
//do stuff with cs 

…dd missing `CharString` method implementations.
@akien-mga akien-mga merged commit 9bc489e into godotengine:master Feb 15, 2022
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is an enhancement on the current functionality topic:gdextension This relates to the new Godot 4 extension implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants