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

Some code deduplication for plPythonSDLModifier. #1465

Merged
merged 2 commits into from
Aug 16, 2023

Conversation

Hoikas
Copy link
Member

@Hoikas Hoikas commented Aug 15, 2023

No description provided.

if (!hintstring.empty())
var->GetNotificationInfo().SetHintString(hintstring);
return true;
} else if (PyLong_Check(pyVar)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

:trollface:

Copy link
Member

Choose a reason for hiding this comment

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

Presumably one of those used to be a PyInt_*... I hope >.>

@Hoikas Hoikas force-pushed the pysdl_code_dedupe branch 2 times, most recently from 0fe4d52 to 4456bc3 Compare August 15, 2023 00:42
@Hoikas Hoikas marked this pull request as draft August 15, 2023 00:56
@Hoikas
Copy link
Member Author

Hoikas commented Aug 15, 2023

Converting to draft because gcc.

}
return std::nullopt;
} else {
static_assert(false, "Unhandled C++ type conversion for Python number");
Copy link
Member

Choose a reason for hiding this comment

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

This is not a dependent expression, and therefore is ill-formed even if the function is never called with the else condition ("no diagnostic required" means that MSVC is allowed to ignore it even though it's invalid, but GCC and Clang do emit a diagnostic)... Some options:

  1. Leave the base template unimplemented and implement the two (well, three) cases as specializations instead
  2. Redefine the static_assert to use a dependent condition (something like static_assert(sizeof(T) != sizeof(T), ...)). Although this is technically still ill-formed, GCC and clang might be happier.
  3. Move the static_assert outside of the if constexpr block, testing all possible types, and then leave something like a std::unreachable() in the else condition (less DRY).

return PyLong_AsLong(pyLong.Get());
}
return std::nullopt;
} else if constexpr (std::disjunction_v<std::is_same<T, float>, std::is_same<T, double>>) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm fairly certain you can just

Suggested change
} else if constexpr (std::disjunction_v<std::is_same<T, float>, std::is_same<T, double>>) {
} else if constexpr (std::is_same_v<T, float> || std::is_same_v<T, double>) {

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that worked with MSVC... I just wasn't sure why gcc and clang were exploding, but you've clarified that nicely :)

if (!hintstring.empty())
var->GetNotificationInfo().SetHintString(hintstring);
return true;
} else if (PyLong_Check(pyVar)) {
Copy link
Member

Choose a reason for hiding this comment

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

Presumably one of those used to be a PyInt_*... I hope >.>

@Hoikas Hoikas force-pushed the pysdl_code_dedupe branch 2 times, most recently from ff60840 to 5803d54 Compare August 15, 2023 22:46
@Hoikas Hoikas marked this pull request as ready for review August 15, 2023 23:42
There were two branches of the if statement for converting Python longs
to C++ longs. Debunk that foolishness. Also, we now accept any object
that implements the number protocol instead of just longs and floats.
These could even be Python objects that implement the `__int__()` and
`__float__()` dunder methods.
@Hoikas
Copy link
Member Author

Hoikas commented Aug 15, 2023

The most recent push removes an unneeded type_traits include.

@Hoikas Hoikas merged commit d863078 into H-uru:master Aug 16, 2023
14 checks passed
@Hoikas Hoikas deleted the pysdl_code_dedupe branch August 16, 2023 01:15
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.

2 participants