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

Use C++17 style static variable syntax #82127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jpakkane
Copy link

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.

@AThousandShips
Copy link
Member

if building with something other than SCons.

Which is it really something to consider? The code is built for SCons

Copy link
Contributor

@ryanabx ryanabx left a 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.

@adamscott adamscott added cherrypick:3.x Considered for cherry-picking into a future 3.x release cherrypick:4.0 cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release labels Sep 22, 2023
@AThousandShips
Copy link
Member

There's many cases like this, for example in ObjectDB

@ryanabx
Copy link
Contributor

ryanabx commented Sep 22, 2023

There's many cases like this, for example in ObjectDB

I wonder if his linker error crops up for the other cases as well. :/

@AThousandShips
Copy link
Member

If this should be done I think it should be done properly

@ryanabx
Copy link
Contributor

ryanabx commented Sep 22, 2023

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.

@AThousandShips
Copy link
Member

  1. can someone find any cases of non-constant static variables defined this way
  2. can someone confirm a need for this

Copy link
Contributor

@ryanabx ryanabx left a 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.

@akien-mga
Copy link
Member

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.

@akien-mga akien-mga removed cherrypick:4.0 cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release labels Sep 22, 2023
@jpakkane jpakkane requested review from a team as code owners September 22, 2023 22:45
@jpakkane
Copy link
Author

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.

I think the linker error would be a sign of the buildsystem not having properly rebuilt all the objects that need to be rebuilt.

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.

@AThousandShips
Copy link
Member

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.

On one hand yes, on another no, as it now makes changing the value affect the inheritance chain

@AThousandShips
Copy link
Member

You're using spaces for indentation everywhere, you need to use tabs

@AThousandShips AThousandShips removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Sep 23, 2023
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;
Copy link
Member

@AThousandShips AThousandShips Sep 23, 2023

Choose a reason for hiding this comment

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

Suggested change
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

@AThousandShips
Copy link
Member

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;
Copy link
Member

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)();
Copy link
Member

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)();
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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;

Copy link
Member

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";

Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

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

Left out

Copy link
Member

@AThousandShips AThousandShips left a 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

@jpakkane
Copy link
Author

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.

@AThousandShips
Copy link
Member

AThousandShips commented Sep 23, 2023

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

@jpakkane
Copy link
Author

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.

@akien-mga
Copy link
Member

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.

@jpakkane
Copy link
Author

Without this change linking fails with this:

/usr/bin/ld: godot.p/main_main.cpp.o: warning: relocation against `_ZN22GDScriptLanguageServer13port_overrideE' in read-only section `.text'
/usr/bin/ld: godot.p/main_main.cpp.o: in function `Main::setup(char const*, int, char**, bool)':
/home/jpakkane/projects/build-godot-Desktop-debug/../godot/main/main.cpp:1534: undefined reference to `GDScriptLanguageServer::port_override'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Guessing this has something to do with how the toolchain wants to make some things position independent by default but not others.

@akien-mga
Copy link
Member

akien-mga commented Sep 27, 2023

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 scons compiledb=yes).

@stalkerg
Copy link

I agree, you just should change Meson compiler options. It's not a Meson or source code issue, just Meson configuration.

@jpakkane
Copy link
Author

The reason for the original failure turned out to be a bad #define setup. I have fixed that in my own branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants