-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Use C++17 style static variable syntax #82127
base: master
Are you sure you want to change the base?
Conversation
Which is it really something to consider? The code is built for SCons |
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.
The conversation of whether to make this change is still open, but my 2 cents is that this change is fine. I was the one who made that variable, and I apparently need to brush up on my modern C++ syntax 😅. If accepted, please cherry-pick the changes to 3.x, as the same variable exists there as well.
EDIT: Knowing now that there are other cases like this, for consistency, the PR should change the other cases as well. Then, a discussion will need to be had on the necessity of such a change.
There's many cases like this, for example in |
I wonder if his linker error crops up for the other cases as well. :/ |
If this should be done I think it should be done properly |
I think I agree. I was hastily under the impression that our code style involved using the newer syntax. If there are equivalent cases to this one, they all should be changed to be inline in this PR. |
|
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.
I'd like to see all cases similar to this one changed to be inline, for consistency.
We also should continue discussing the necessity of such a change.
I think changing this would be fine if we can show there are no adverse effects. But we should remain consistent and use that style everywhere if we do make that change.
I think the linker error would be a sign of the buildsystem not having properly rebuilt all the objects that need to be rebuilt. Rebuilding from scratch might solve it. I don't see why the current syntax wouldn't work, and it's indeed used in several other places. This specific one was added in #81844 merged recently. |
7236b43
to
28b5b47
Compare
I fixed the ones I could find with grepping. There were quite lot more of them than one would have expected. This change is useful just on its own, because shows the default value in the header file rather than you having to go look it up in the corresponding cpp file.
No, that is not it. It is a complicated way in which compiler settings work with PIE in a way that I don't properly understand myself. |
28b5b47
to
b898a6c
Compare
On one hand yes, on another no, as it now makes changing the value affect the inheritance chain |
You're using spaces for indentation everywhere, you need to use tabs |
b898a6c
to
d3eec71
Compare
core/debugger/script_debugger.h
Outdated
static thread_local int depth; | ||
static thread_local ScriptLanguage *break_lang; | ||
static thread_local Vector<StackInfo> error_stack_info; | ||
static inline thread_local int lines_left = 0; |
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.
static inline thread_local int lines_left = 0; | |
static inline thread_local int lines_left = -1; |
Make sure you copy the values correctly, there are other cases
d3eec71
to
db383e3
Compare
db383e3
to
d01835a
Compare
Still not complete, several of the touched files still have entries left in the previous style |
@@ -249,7 +249,7 @@ class OS : public Object { | |||
class Geometry2D : public Object { | |||
GDCLASS(Geometry2D, Object); | |||
|
|||
static Geometry2D *singleton; | |||
static inline Geometry2D *singleton; |
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.
Several missed here
static void _bind_methods(); | ||
|
||
PackedStringArray _get_local_addresses() const; | ||
TypedArray<Dictionary> _get_local_interfaces() const; | ||
|
||
static IP *(*_create)(); | ||
static inline IP *(*_create)(); |
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.
Missed
@@ -38,10 +38,10 @@ class PacketPeerDTLS : public PacketPeer { | |||
GDCLASS(PacketPeerDTLS, PacketPeer); | |||
|
|||
protected: | |||
static PacketPeerDTLS *(*_create)(); | |||
static inline PacketPeerDTLS *(*_create)(); |
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.
Missed
HashSet<CharString> enabled_instance_extension_names; | ||
|
||
static bool device_extensions_initialized; | ||
static HashMap<CharString, bool> requested_device_extensions; | ||
static inline bool device_extensions_initialized; |
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.
Missed
@@ -95,7 +95,7 @@ class EditorVCSInterface : public Object { | |||
}; | |||
|
|||
protected: | |||
static EditorVCSInterface *singleton; | |||
static inline EditorVCSInterface *singleton; |
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.
Missed
@@ -81,7 +81,7 @@ class AudioStreamImportSettings : public ConfirmationDialog { | |||
|
|||
void _audio_changed(); | |||
|
|||
static AudioStreamImportSettings *singleton; | |||
static inline AudioStreamImportSettings *singleton; |
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.
Missed
@@ -50,7 +50,7 @@ class NodeDock : public VBoxContainer { | |||
Node *last_valid_node = nullptr; | |||
|
|||
private: | |||
static NodeDock *singleton; | |||
static inline NodeDock *singleton; | |||
|
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.
Missed
@@ -49,8 +49,6 @@ | |||
|
|||
const String ProjectSettings::PROJECT_DATA_DIR_NAME_SUFFIX = "godot"; | |||
|
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.
Left out
@@ -72,8 +72,6 @@ static const char *_joy_axes[(size_t)JoyAxis::SDL_MAX] = { | |||
"righttrigger", | |||
}; | |||
|
|||
Input *Input::singleton = nullptr; | |||
|
|||
void (*Input::set_mouse_mode_func)(Input::MouseMode) = nullptr; | |||
Input::MouseMode (*Input::get_mouse_mode_func)() = nullptr; | |||
void (*Input::warp_mouse_func)(const Vector2 &p_position) = nullptr; |
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.
Left out
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.
Unable to go through all cases at the moment but needs a through check, also there's been some questions before I believe about the thread_local
variables causing weirdness on some platforms so needs to be looked into
I don't see the direct value in changing the codebase when it works for the current build system, Godot currently only offers SCons and there's no solid plans to change it at the moment or offer alternatives, and this change risks introducing issues that can be hard to foresee
Edit: I also am not convinced that this is a code issue but that what ever other build system that has been set up doesn't match the options set up for SCons
This took so long that at some point I got fed up. I'll fix the rest only after there is a decision to actually merge this. I don't want to waste hours of my time on something that might be rejected outright. |
Understandable, but the change would need to be verified to actually work correctly so it's a bit complicated that way Edit: I.e. it might end up not working out even after a decision to try it |
There are comments in this thread that this should not be merged even if it works, because the old one is good enough. First a decision needs to be made that this will be merged if it works. Until that is decided, putting more effort into this is pointless. |
I still don't understand how the original code would break compilation. There's a lot of misunderstanding around buildsystems when treating them as black boxes, when at the end of the day all they do is call the compiler for each file with a list of options. What option are you using in your Meson PR that differs from the SCons setup? I'm not against modernizing usage (and indeed be careful around thread local stuff, that's touchy), but I need to know what we're fixing. |
Without this change linking fails with this:
Guessing this has something to do with how the toolchain wants to make some things position independent by default but not others. |
The toolchain here should be GCC (or Clang) and GNU ld (or ldd), it shouldn't depend whether it's called by SCons or Meson/Ninja. So what I need to know is what you're configuring differently in Meson/Ninja that exposes this issue, so we can assess whether it's an actual bug in Godot or not. So far to me this exposes a bug in the Meson/Ninja config which either removes or adds an option that Godot isn't meant to be compiled with. If meson can generate a compilation database, it would be useful to compare with the one generated by SCons (with |
I agree, you just should change Meson compiler options. It's not a Meson or source code issue, just Meson configuration. |
The reason for the original failure turned out to be a bad |
This is the recommended way to do this since C++17. It also fixes a puzzling linker error if building with something other than SCons.