Skip to content

Conversation

dagitses
Copy link
Collaborator

suppress -Wcast-function-type-strict when casting to PyCFunction

Summary:
These casts are a necessary evil due to the design of Python. Python
ultimately casts it back to the original type based on the flags
specified in the PyMethodDef.

Nevertheless, the new Clang flag -Wcast-function-type-strict breaks
with this.

While here, convert the cast to a reinterpret_cast.

Test Plan: Should be a no-op. Rely on CI.

@pytorch-bot
Copy link

pytorch-bot bot commented Apr 26, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/100068

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit c680b75:
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@dagitses dagitses changed the title suppress -Wcast-function-type-strict when casting to PyCFunction suppress -Wcast-function-type-strict when casting to PyCFunction Apr 26, 2023
Summary:
These casts are a necessary evil due to the design of Python. Python
ultimately casts it back to the original type based on the flags
specified in the `PyMethodDef`.

Nevertheless, the new Clang flag `-Wcast-function-type-strict` breaks
with this.

While here, convert the cast to a `reinterpret_cast`.

Test Plan: Should be a no-op. Rely on CI.
@dagitses dagitses changed the title suppress -Wcast-function-type-strict when casting to PyCFunction suppress -Wcast-function-type-strict when casting to PyCFunction Apr 26, 2023
@dagitses dagitses added module: build warnings Related to warnings during build process ciflow/trunk Trigger trunk jobs on your pull request labels Apr 26, 2023
@dagitses dagitses marked this pull request as ready for review April 26, 2023 09:10
@dagitses dagitses requested a review from malfet April 26, 2023 09:10
@Skylion007 Skylion007 added the topic: not user facing topic category label Apr 26, 2023
@dagitses
Copy link
Collaborator Author

@pytorchbot merge

return (PyCFunction)(void (*)(void))func;
C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED("-Wcast-function-type")
C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED("-Wcast-function-type-strict")
return reinterpret_cast<PyCFunction>(func);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This cannot be a static_cast right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's correct. The pointer types are unrelated and neither is void*.

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@dagitses dagitses deleted the pr100068 branch April 26, 2023 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged merging module: build warnings Related to warnings during build process open source topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants