Skip to content

Add structmember.h constants #126

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

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
Changelog
=========

* 2024-12-16: Add ``structmember.h`` constants:

* ``Py_T_BOOL``
* ``Py_T_BYTE``
* ``Py_T_CHAR``
* ``Py_T_DOUBLE``
* ``Py_T_FLOAT``
* ``Py_T_INT``
* ``Py_T_LONGLONG``
* ``Py_T_LONG``
* ``Py_T_OBJECT_EX``
* ``Py_T_PYSSIZET``
* ``Py_T_SHORT``
* ``Py_T_STRING_INPLACE``
* ``Py_T_STRING``
* ``Py_T_UBYTE``
* ``Py_T_UINT``
* ``Py_T_ULONGLONG``
* ``Py_T_ULONG``
* ``Py_T_USHORT``
* ``_Py_T_NONE``
* ``_Py_T_OBJECT``
* ``Py_AUDIT_READ``
* ``Py_READONLY``
* ``_Py_WRITE_RESTRICTED``

* 2024-12-13: Add functions and structs:

* ``PyLongLayout``
Expand Down
34 changes: 34 additions & 0 deletions pythoncapi_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ extern "C" {
#if PY_VERSION_HEX < 0x030b00B4 && !defined(PYPY_VERSION)
# include "frameobject.h" // PyFrameObject, PyFrame_GetBack()
#endif
#if PY_VERSION_HEX < 0x030C00A3
# include <structmember.h> // T_SHORT, READONLY
#endif


#ifndef _Py_CAST
Expand Down Expand Up @@ -1899,6 +1902,37 @@ PyLongWriter_Finish(PyLongWriter *writer)
#endif


#if PY_VERSION_HEX < 0x030C00A3
# define Py_T_SHORT T_SHORT
# define Py_T_INT T_INT
# define Py_T_LONG T_LONG
# define Py_T_FLOAT T_FLOAT
# define Py_T_DOUBLE T_DOUBLE
# define Py_T_STRING T_STRING
# define _Py_T_OBJECT T_OBJECT
# define Py_T_CHAR T_CHAR
# define Py_T_BYTE T_BYTE
# define Py_T_UBYTE T_UBYTE
# define Py_T_USHORT T_USHORT
# define Py_T_UINT T_UINT
# define Py_T_ULONG T_ULONG
# define Py_T_STRING_INPLACE T_STRING_INPLACE
# define Py_T_BOOL T_BOOL
# define Py_T_OBJECT_EX T_OBJECT_EX
# define Py_T_LONGLONG T_LONGLONG
# define Py_T_ULONGLONG T_ULONGLONG
# define Py_T_PYSSIZET T_PYSSIZET

# if PY_VERSION_HEX >= 0x03000000 && !defined(PYPY_VERSION)
# define _Py_T_NONE T_NONE
# endif

# define Py_READONLY READONLY
# define Py_AUDIT_READ READ_RESTRICTED
# define _Py_WRITE_RESTRICTED PY_WRITE_RESTRICTED
#endif


#ifdef __cplusplus
}
#endif
Expand Down
35 changes: 35 additions & 0 deletions tests/test_pythoncapi_compat_cext.c
Original file line number Diff line number Diff line change
Expand Up @@ -2063,6 +2063,40 @@ test_long_stdint(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
}


static PyObject *
test_structmember(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
{
assert(Py_T_SHORT >= 0);
assert(Py_T_INT >= 0);
assert(Py_T_LONG >= 0);
assert(Py_T_FLOAT >= 0);
assert(Py_T_DOUBLE >= 0);
assert(Py_T_STRING >= 0);
assert(_Py_T_OBJECT >= 0);
assert(Py_T_CHAR >= 0);
assert(Py_T_BYTE >= 0);
assert(Py_T_UBYTE >= 0);
assert(Py_T_USHORT >= 0);
assert(Py_T_UINT >= 0);
assert(Py_T_ULONG >= 0);
assert(Py_T_STRING_INPLACE >= 0);
assert(Py_T_BOOL >= 0);
assert(Py_T_OBJECT_EX >= 0);
assert(Py_T_LONGLONG >= 0);
assert(Py_T_ULONGLONG >= 0);
assert(Py_T_PYSSIZET >= 0);
#if PY_VERSION_HEX >= 0x03000000 && !defined(PYPY_VERSION)
assert(_Py_T_NONE >= 0);
#endif

assert(Py_READONLY >= 0);
assert(Py_AUDIT_READ >= 0);
assert(_Py_WRITE_RESTRICTED >= 0);

Py_RETURN_NONE;
}


static struct PyMethodDef methods[] = {
{"test_object", test_object, METH_NOARGS, _Py_NULL},
{"test_py_is", test_py_is, METH_NOARGS, _Py_NULL},
Expand Down Expand Up @@ -2109,6 +2143,7 @@ static struct PyMethodDef methods[] = {
{"test_bytes", test_bytes, METH_NOARGS, _Py_NULL},
{"test_iter", test_iter, METH_NOARGS, _Py_NULL},
{"test_long_stdint", test_long_stdint, METH_NOARGS, _Py_NULL},
{"test_structmember", test_structmember, METH_NOARGS, _Py_NULL},
{_Py_NULL, _Py_NULL, 0, _Py_NULL}
};

Expand Down
Loading