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

gh-117549: Match declaration order for _Py_BackoffCounter initializer #117551

Merged
merged 1 commit into from
Apr 4, 2024

Conversation

mdboom
Copy link
Contributor

@mdboom mdboom commented Apr 4, 2024

This is to fix the build for Scipy, which includes this header from C++ code which seems to really care about such things.

To be clear, I didn't confirm that this fixes the Scipy build -- there are a bunch of other patches required to its build system to even compile with Python 3.13 and I'm not sure it's worth the effort there.

But this warning seems legitimate and the fix is harmless. It's possible there are other errors in Scipy behind it, but this is the only struct initializer added in #117144.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

LGTM. Let's wait for @tacaswell to give us a thumbs up here before we merge.

@tacaswell
Copy link
Contributor

I can confirm that scipy compiles with cpython from this branch.

@gvanrossum
Copy link
Member

Thanks for your help! Merging now...

@gvanrossum gvanrossum merged commit b5e6091 into python:main Apr 4, 2024
38 checks passed
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
…alizer (python#117551)

Otherwise it might not compile with C++ (or certain C compilers/flags?).
@methane
Copy link
Member

methane commented Apr 20, 2024

Cython includes this file and g++ 9 and 10 (available on Ubuntu 22.04 LTS) doesn't compile this.

msgpack/msgpack-python#593 (comment)

// foo.cpp
#define Py_BUILD_CORE 1
#include <Python.h>

#include "frameobject.h"
#include "internal/pycore_frame.h"

int main() {}
// g++-10 -std=c++17 -I include/python3.13 foo.cpp

I confirmed Using temporary variable fix it.

    _Py_BackoffCounter c;
    c.backoff = backoff;
    c.value = value;
    return c;

But I am not sure we should support g++ 9/10 in Python 3.13.

@gvanrossum
Copy link
Member

I am despairing. We make all these efforts to indicate things are internal and they are still included in half the packages in the world. :-(

@methane
Copy link
Member

methane commented May 4, 2024

FYI, this caused compile error on MSVC too. Should we add /std:c++20 in cflags on msvc for better interoperability with cython&c++?
msgpack/msgpack-python#597

@gvanrossum
Copy link
Member

Wait— if it failed on MSVC how could the original code have passed CI?

@methane
Copy link
Member

methane commented May 4, 2024

Because we don't test C++.
This is problem only when using C++ with Cython.

@methane
Copy link
Member

methane commented May 4, 2024

/std:c++20 didn't help me. I need to stop using C++ or Cython.

  C:\hostedtoolcache\windows\Python\3.13.0-alpha.6\x64\include\internal\pycore_backoff.h(47): error C4576: a parenthesized type followed by an initializer list is a non-standard explicit type conversion syntax
  C:\hostedtoolcache\windows\Python\3.13.0-alpha.6\x64\include\internal\pycore_backoff.h(53): error C4576: a parenthesized type followed by an initializer list is a non-standard explicit type conversion syntax

@gvanrossum
Copy link
Member

So let’s fix it. Do you have time for a PR?

@gvanrossum
Copy link
Member

That should be fixed now.

@methane
Copy link
Member

methane commented May 7, 2024

thank you.

@methane
Copy link
Member

methane commented May 7, 2024

By the way, Cython uses this only for building custom traceback object.
We hided f_lineno in PyFrameObject so Cython includes pycore_frame.h.

Adding _PyFrame_SetLineno() in Include/cpython/frameobject.h makes it possible to Cython remove this include.

https://github.com/cython/cython/blob/45db483cbe128c29a1e9ffe9f5a4db12cf77cddd/Cython/Utility/Exceptions.c#L1007C1-L1007C52
https://github.com/cython/cython/blob/45db483cbe128c29a1e9ffe9f5a4db12cf77cddd/Cython/Utility/ModuleSetupCode.c#L839

@gvanrossum
Copy link
Member

Adding _PyFrame_SetLineno() in Include/cpython/frameobject.h makes it possible to Cython remove this include.

So IIUC you are proposing to add a new public API to set the f_lineno attribute in a frame object? It's too bad that today is the 3.13 beta 1 feature freeze, so this will have to go into 3.14. Can you open a new issue and PR so we won't forget?

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.

4 participants