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

bpo-37337: Fix a GCC 9 warning in Objects/descrobject.c #14814

Merged
merged 1 commit into from
Aug 14, 2019

Conversation

ZackerySpytz
Copy link
Contributor

@ZackerySpytz ZackerySpytz commented Jul 17, 2019

Commit b1263d5 causes GCC 9.1.0 to
give a warning in Objects/descrobject.c.

Objects/descrobject.c:1050:19: warning: cast between incompatible function types from ‘PyObject * (*)(mappingproxyobject *, PyObject * const*, Py_ssize_t)’ {aka ‘struct _object * (*)(struct <anonymous> *, struct _object * const*, long int)’} to ‘PyObject * (*)(PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *)’} [-Wcast-function-type]
 1050 |     {"get",       (PyCFunction)mappingproxy_get,        METH_FASTCALL,
      |                   ^

https://bugs.python.org/issue37337

Commit b1263d5 causes GCC 9.1.0 to
give a warning in Objects/descrobject.c.
@ZackerySpytz
Copy link
Contributor Author

@methane

@ZackerySpytz
Copy link
Contributor Author

Hi, @methane. Can you please merge this PR?

@methane
Copy link
Member

methane commented Aug 14, 2019

The cast seems too complex to just avoid the warning. But I'm not sure there is a better way.
When I have spare time, I'll try to find simpler ways to fix this. But I don't have spare time now.
That's why I don't merge this.

If you want to this merged, please provide all casts you tried and demonstrate this is the simplest way to fix the warning.

@jdemeyer
Copy link
Contributor

This is the standard way to avoid those warnings, there are many places in CPython with casts like that. It's also documented to do this: https://docs.python.org/3.8/extending/extending.html#keyword-parameters-for-extension-functions

@jdemeyer
Copy link
Contributor

jdemeyer commented Aug 14, 2019

See bpo-33012 for the discussion about those casts.

As far as I know, this is indeed the simplest way to cast between incompatible function pointers which does not generate warnings with GCC 9 and which does not rely on undefined behaviour and which is compatible with C++.

@methane
Copy link
Member

methane commented Aug 14, 2019

OK, thank you.

@methane methane merged commit 43d564c into python:master Aug 14, 2019
@miss-islington
Copy link
Contributor

Thanks @ZackerySpytz for the PR, and @methane for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @ZackerySpytz and @methane, I could not cleanly backport this to 3.8 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 43d564c18c97421f73025ac3132a194975c76bd6 3.8

lisroach pushed a commit to lisroach/cpython that referenced this pull request Sep 10, 2019
Commit b1263d5 causes GCC 9.1.0 to
give a warning in Objects/descrobject.c.
DinoV pushed a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
Commit b1263d5 causes GCC 9.1.0 to
give a warning in Objects/descrobject.c.
websurfer5 pushed a commit to websurfer5/cpython that referenced this pull request Jul 20, 2020
Commit b1263d5 causes GCC 9.1.0 to
give a warning in Objects/descrobject.c.
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