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

Add compatibility to Py_T_* #125

Closed
rruuaanng opened this issue Dec 16, 2024 · 9 comments
Closed

Add compatibility to Py_T_* #125

rruuaanng opened this issue Dec 16, 2024 · 9 comments

Comments

@rruuaanng
Copy link

rruuaanng commented Dec 16, 2024

Hello Python team, I believe we have met countless times in the main repository.

When I port libfdt to Python, I noticed the Py_T_* series of macros, which are only available after version 3.12. Prior to this, the T_* series was used. Can we add compatibility for these basic constants in a compatibility layer, so they are always defined as Py_T_* in supported versions?

If they are defined elsewhere, please point out my mistakes. Thank you, everyone :)

From my repo


#if PY_VERSION_HEX >= 0x03120000
# include <descrobject.h>
#endif

#if PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x03120000
# include <structmember.h>
/** member type */
# ifndef Py_T_UINT
#  define Py_T_UINT T_UINT
# endif
# ifndef Py_T_INT
#  define Py_T_INT T_INT
# endif
/** flags */
# ifndef Py_READONLY
#  define Py_READONLY READONLY
# endif
#endif

(If the request is granted, I hope to complete this historic moment.)

@vstinner
Copy link
Member

#if PY_VERSION_HEX >= 0x03090000

Why do you test for Python 3.9?

#ifndef Py_T_UINT

The PY_VERSION_HEX < 0x03120000 test should be enough, no? Why repeating the check for each macro?

@rruuaanng
Copy link
Author

rruuaanng commented Dec 16, 2024

Why do you test for Python 3.9?

I didn't really investigate which version they came from. Maybe I'll look for them later.

The PY_VERSION_HEX < 0x03120000 test should be enough, no? Why repeating the check for each macro?

Right. But I don't know what happened, sometimes it appears to be redefined.

For this issue, WDYT?

Edit

e.g.

E:\code\github\pydt\pydt\_pydt\pydt.h(15): warning C4005: "Py_T_UINT": macro redefinition
E:\Anaconda3\include\descrobject.h(66): note: see previous definition of "Py_T_UINT"
E:\code\github\pydt\pydt\_pydt\pydt.h(18): warning C4005: "Py_T_INT": macro redefinition
E:\Anaconda3\include\descrobject.h(54): note: see previous definition of "Py_T_INT"
E:\code\github\pydt\pydt\_pydt\pydt.h(22): warning C4005: "Py_READONLY": macro redefinition
E:\Anaconda3\include\descrobject.h(83): note: see previous definition of "Py_READONLY"

my change

#if PY_VERSION_HEX < 0x03120000
# include <structmember.h>
/** member type */
#  define Py_T_UINT T_UINT
#  define Py_T_INT T_INT
/** flags */
#  define Py_READONLY READONLY
#endif

@rruuaanng
Copy link
Author

But it is redefined on the premise that I change my current python version. But I hope it can be built successfully in most versions.
(I used 3.9, but not, I use 3.12)

@vstinner
Copy link
Member

Right. But I don't know what happened, sometimes it appears to be redefined.

On which Python version?

@rruuaanng
Copy link
Author

My current version it is Python 3.12.7, Maybe it can be other(e.g. 3.9 the first time this error occurred, I abandoned it.)? I don't know :(

@vstinner
Copy link
Member

#if PY_VERSION_HEX >= 0x03120000
# include <descrobject.h>
#endif

I don't see the purpose of this code.

@vstinner
Copy link
Member

I wrote #126 to add these constants. Can you test my PR?

@rruuaanng
Copy link
Author

I tested it and left a comment in your PR and the issue seems to be ok to be marked as resolved, but I need to wait for it to be merged into main.

@vstinner
Copy link
Member

Fixed by 7eb512b.

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

No branches or pull requests

2 participants