godot icon indicating copy to clipboard operation
godot copied to clipboard

Make Vector<T>::duplicate() const

Open aaronfranke opened this issue 2 years ago • 6 comments

I tried to duplicate a const PackedStringArray and I noticed that it was impossible, but it should be possible.

aaronfranke avatar Jul 07 '23 04:07 aaronfranke

Needs an update to the extension API validation

Also, do we need to add a 4.1 one as well now that we have released it, along with 4.0

AThousandShips avatar Jul 07 '23 08:07 AThousandShips

@godotengine/gdextension Does this technically break compat for extensions?

akien-mga avatar Jul 07 '23 09:07 akien-mga

If the method's hash changed, then I guess it breaks compat. Otherwise, a GDExtension that was built for 4.1 making use of ClassDB::get_method_with_compatibility passing the old hash will not be able to find the method in 4.2.

To avoid breaking compat, you would need to add a compat method (see https://github.com/godotengine/godot/pull/76577).

raulsntos avatar Jul 07 '23 15:07 raulsntos

Does this technically break compat for extensions?

Yes, I think @raulsntos is correct.

I guess it's time to start testing out this compatibility system for real?

dsnopek avatar Jul 07 '23 18:07 dsnopek

What is the correct way to add compatibility methods? Is there an example I can follow?

aaronfranke avatar Sep 04 '23 05:09 aaronfranke

Hm, digging into this one deeper, I don't think we currently have a way to provide compatibility methods on Variant types.

gdextension_variant_get_ptr_builtin_method() in gdextension_interface.cpp looks up the method by the name, recalculates its hash, and simply compares that with the value provided. We'll need to add something to variant_call.cpp to store, register and call compatibility methods, similar to the mechanism we already have in ClassDB.

dsnopek avatar Sep 07 '23 21:09 dsnopek

Since there still isn't a way to register compatibility methods, I updated this PR to instead keep the bindings equivalent to the same method as before, while the version internal to the C++ code is now const. There are #ifndef DISABLE_DEPRECATED checks to ensure that the compat method is removed when building with deprecated disabled.

aaronfranke avatar Aug 19 '25 15:08 aaronfranke

Since there still isn't a way to register compatibility methods, I updated this PR to instead keep the bindings equivalent to the same method as before, while the version internal to the C++ code is now const.

So, essentially, this makes it const within Godot, but still non-const as exposed to GDExtension?

dsnopek avatar Sep 17 '25 14:09 dsnopek

I just posted PR https://github.com/godotengine/godot/pull/112290 which finally adds a system for builtin method compatibility.

In order to test in, I've included (in the 2nd commit) the same core change as this PR (and listed @aaronfranke as a co-author)

dsnopek avatar Nov 01 '25 19:11 dsnopek

Implemented via #112290

Repiteo avatar Nov 05 '25 01:11 Repiteo