Skip to content

Commit 7eb512b

Browse files
authored
Add structmember.h constants (#126)
1 parent 61709bf commit 7eb512b

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

docs/changelog.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
11
Changelog
22
=========
33

4+
* 2024-12-16: Add ``structmember.h`` constants:
5+
6+
* ``Py_T_BOOL``
7+
* ``Py_T_BYTE``
8+
* ``Py_T_CHAR``
9+
* ``Py_T_DOUBLE``
10+
* ``Py_T_FLOAT``
11+
* ``Py_T_INT``
12+
* ``Py_T_LONGLONG``
13+
* ``Py_T_LONG``
14+
* ``Py_T_OBJECT_EX``
15+
* ``Py_T_PYSSIZET``
16+
* ``Py_T_SHORT``
17+
* ``Py_T_STRING_INPLACE``
18+
* ``Py_T_STRING``
19+
* ``Py_T_UBYTE``
20+
* ``Py_T_UINT``
21+
* ``Py_T_ULONGLONG``
22+
* ``Py_T_ULONG``
23+
* ``Py_T_USHORT``
24+
* ``_Py_T_NONE``
25+
* ``_Py_T_OBJECT``
26+
* ``Py_AUDIT_READ``
27+
* ``Py_READONLY``
28+
* ``_Py_WRITE_RESTRICTED``
29+
430
* 2024-12-13: Add functions and structs:
531

632
* ``PyLongLayout``

pythoncapi_compat.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ extern "C" {
2424
#if PY_VERSION_HEX < 0x030b00B4 && !defined(PYPY_VERSION)
2525
# include "frameobject.h" // PyFrameObject, PyFrame_GetBack()
2626
#endif
27+
#if PY_VERSION_HEX < 0x030C00A3
28+
# include <structmember.h> // T_SHORT, READONLY
29+
#endif
2730

2831

2932
#ifndef _Py_CAST
@@ -1899,6 +1902,37 @@ PyLongWriter_Finish(PyLongWriter *writer)
18991902
#endif
19001903

19011904

1905+
#if PY_VERSION_HEX < 0x030C00A3
1906+
# define Py_T_SHORT T_SHORT
1907+
# define Py_T_INT T_INT
1908+
# define Py_T_LONG T_LONG
1909+
# define Py_T_FLOAT T_FLOAT
1910+
# define Py_T_DOUBLE T_DOUBLE
1911+
# define Py_T_STRING T_STRING
1912+
# define _Py_T_OBJECT T_OBJECT
1913+
# define Py_T_CHAR T_CHAR
1914+
# define Py_T_BYTE T_BYTE
1915+
# define Py_T_UBYTE T_UBYTE
1916+
# define Py_T_USHORT T_USHORT
1917+
# define Py_T_UINT T_UINT
1918+
# define Py_T_ULONG T_ULONG
1919+
# define Py_T_STRING_INPLACE T_STRING_INPLACE
1920+
# define Py_T_BOOL T_BOOL
1921+
# define Py_T_OBJECT_EX T_OBJECT_EX
1922+
# define Py_T_LONGLONG T_LONGLONG
1923+
# define Py_T_ULONGLONG T_ULONGLONG
1924+
# define Py_T_PYSSIZET T_PYSSIZET
1925+
1926+
# if PY_VERSION_HEX >= 0x03000000 && !defined(PYPY_VERSION)
1927+
# define _Py_T_NONE T_NONE
1928+
# endif
1929+
1930+
# define Py_READONLY READONLY
1931+
# define Py_AUDIT_READ READ_RESTRICTED
1932+
# define _Py_WRITE_RESTRICTED PY_WRITE_RESTRICTED
1933+
#endif
1934+
1935+
19021936
#ifdef __cplusplus
19031937
}
19041938
#endif

tests/test_pythoncapi_compat_cext.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,6 +2063,40 @@ test_long_stdint(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
20632063
}
20642064

20652065

2066+
static PyObject *
2067+
test_structmember(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
2068+
{
2069+
assert(Py_T_SHORT >= 0);
2070+
assert(Py_T_INT >= 0);
2071+
assert(Py_T_LONG >= 0);
2072+
assert(Py_T_FLOAT >= 0);
2073+
assert(Py_T_DOUBLE >= 0);
2074+
assert(Py_T_STRING >= 0);
2075+
assert(_Py_T_OBJECT >= 0);
2076+
assert(Py_T_CHAR >= 0);
2077+
assert(Py_T_BYTE >= 0);
2078+
assert(Py_T_UBYTE >= 0);
2079+
assert(Py_T_USHORT >= 0);
2080+
assert(Py_T_UINT >= 0);
2081+
assert(Py_T_ULONG >= 0);
2082+
assert(Py_T_STRING_INPLACE >= 0);
2083+
assert(Py_T_BOOL >= 0);
2084+
assert(Py_T_OBJECT_EX >= 0);
2085+
assert(Py_T_LONGLONG >= 0);
2086+
assert(Py_T_ULONGLONG >= 0);
2087+
assert(Py_T_PYSSIZET >= 0);
2088+
#if PY_VERSION_HEX >= 0x03000000 && !defined(PYPY_VERSION)
2089+
assert(_Py_T_NONE >= 0);
2090+
#endif
2091+
2092+
assert(Py_READONLY >= 0);
2093+
assert(Py_AUDIT_READ >= 0);
2094+
assert(_Py_WRITE_RESTRICTED >= 0);
2095+
2096+
Py_RETURN_NONE;
2097+
}
2098+
2099+
20662100
static struct PyMethodDef methods[] = {
20672101
{"test_object", test_object, METH_NOARGS, _Py_NULL},
20682102
{"test_py_is", test_py_is, METH_NOARGS, _Py_NULL},
@@ -2109,6 +2143,7 @@ static struct PyMethodDef methods[] = {
21092143
{"test_bytes", test_bytes, METH_NOARGS, _Py_NULL},
21102144
{"test_iter", test_iter, METH_NOARGS, _Py_NULL},
21112145
{"test_long_stdint", test_long_stdint, METH_NOARGS, _Py_NULL},
2146+
{"test_structmember", test_structmember, METH_NOARGS, _Py_NULL},
21122147
{_Py_NULL, _Py_NULL, 0, _Py_NULL}
21132148
};
21142149

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy