Skip to content

Commit 80eefbf

Browse files
committed
Make PY_SSIZE_T_CLEAN not mandatory.
1 parent 5b26c21 commit 80eefbf

File tree

7 files changed

+20
-27
lines changed

7 files changed

+20
-27
lines changed

Include/abstract.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,8 @@ extern "C" {
135135
This function always succeeds. */
136136

137137

138-
#ifdef PY_SSIZE_T_CLEAN
139-
# define PyObject_CallFunction _PyObject_CallFunction_SizeT
140-
# define PyObject_CallMethod _PyObject_CallMethod_SizeT
141-
#endif
138+
#define PyObject_CallFunction _PyObject_CallFunction_SizeT
139+
#define PyObject_CallMethod _PyObject_CallMethod_SizeT
142140

143141

144142
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000

Include/cpython/abstract.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
/* === Object Protocol ================================================== */
66

7-
#ifdef PY_SSIZE_T_CLEAN
8-
# define _PyObject_CallMethodId _PyObject_CallMethodId_SizeT
9-
#endif
7+
#define _PyObject_CallMethodId _PyObject_CallMethodId_SizeT
108

119
/* Convert keyword arguments from the FASTCALL (stack: C array, kwnames: tuple)
1210
format to a Python dictionary ("kwargs" dict).

Include/cpython/modsupport.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,9 @@
22
# error "this header file must not be included directly"
33
#endif
44

5-
/* If PY_SSIZE_T_CLEAN is defined, each functions treats #-specifier
6-
to mean Py_ssize_t */
7-
#ifdef PY_SSIZE_T_CLEAN
5+
/* Each functions treats #-specifier to mean Py_ssize_t
6+
* regardless PY_SSIZE_T_CLEAN */
87
#define _Py_VaBuildStack _Py_VaBuildStack_SizeT
9-
#else
10-
PyAPI_FUNC(PyObject *) _Py_VaBuildValue_SizeT(const char *, va_list);
11-
PyAPI_FUNC(PyObject **) _Py_VaBuildStack_SizeT(
12-
PyObject **small_stack,
13-
Py_ssize_t small_stack_len,
14-
const char *format,
15-
va_list va,
16-
Py_ssize_t *p_nargs);
17-
#endif
188

199
PyAPI_FUNC(int) _PyArg_UnpackStack(
2010
PyObject *const *args,
@@ -63,12 +53,10 @@ typedef struct _PyArg_Parser {
6353
struct _PyArg_Parser *next;
6454
} _PyArg_Parser;
6555

66-
#ifdef PY_SSIZE_T_CLEAN
6756
#define _PyArg_ParseTupleAndKeywordsFast _PyArg_ParseTupleAndKeywordsFast_SizeT
6857
#define _PyArg_ParseStack _PyArg_ParseStack_SizeT
6958
#define _PyArg_ParseStackAndKeywords _PyArg_ParseStackAndKeywords_SizeT
7059
#define _PyArg_VaParseTupleAndKeywordsFast _PyArg_VaParseTupleAndKeywordsFast_SizeT
71-
#endif
7260

7361
PyAPI_FUNC(int) _PyArg_ParseTupleAndKeywordsFast(PyObject *, PyObject *,
7462
struct _PyArg_Parser *, ...);

Include/modsupport.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@ extern "C" {
99

1010
#include <stdarg.h> // va_list
1111

12-
/* If PY_SSIZE_T_CLEAN is defined, each functions treats #-specifier
13-
to mean Py_ssize_t */
14-
#ifdef PY_SSIZE_T_CLEAN
12+
/* Since Python 3.13, each functions treats #-specifier to mean Py_ssize_t
13+
* regardless PY_SSIZE_T_CLEAN is defined,
14+
*/
1515
#define PyArg_Parse _PyArg_Parse_SizeT
1616
#define PyArg_ParseTuple _PyArg_ParseTuple_SizeT
1717
#define PyArg_ParseTupleAndKeywords _PyArg_ParseTupleAndKeywords_SizeT
1818
#define PyArg_VaParse _PyArg_VaParse_SizeT
1919
#define PyArg_VaParseTupleAndKeywords _PyArg_VaParseTupleAndKeywords_SizeT
2020
#define Py_BuildValue _Py_BuildValue_SizeT
2121
#define Py_VaBuildValue _Py_VaBuildValue_SizeT
22-
#endif
2322

2423
/* Due to a glitch in 3.2, the _SizeT versions weren't exported from the DLL. */
25-
#if !defined(PY_SSIZE_T_CLEAN) || !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
24+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
2625
PyAPI_FUNC(int) PyArg_Parse(PyObject *, const char *, ...);
2726
PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...);
2827
PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``PY_SSIZE_T_CLEAN`` is no longer required to use '#' specifier in APIs like
2+
:c:func:`PyArg_ParseTuple` and :c:func:`Py_BuildValue`.

Python/getargs.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,11 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
657657
char *msgbuf, size_t bufsize, freelist_t *freelist)
658658
{
659659
#define RETURN_ERR_OCCURRED return msgbuf
660-
/* For # codes */
660+
// For # codes
661+
// Even though Python 3.13 uses ssize_t ragardless PY_SSIZE_T_CLEAN,
662+
// extension compiled with Python ~3.9 may still use int version API.
663+
// Remove this check after we drop supporting extension module built with
664+
// Python ~3.9.
661665
#define REQUIRE_PY_SSIZE_T_CLEAN \
662666
if (!(flags & FLAG_SIZE_T)) { \
663667
PyErr_SetString(PyExc_SystemError, \

Python/modsupport.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ do_mktuple(const char **p_format, va_list *p_va, char endchar, Py_ssize_t n, int
277277
static PyObject *
278278
do_mkvalue(const char **p_format, va_list *p_va, int flags)
279279
{
280+
// Even though Python 3.13 uses ssize_t ragardless PY_SSIZE_T_CLEAN,
281+
// extension compiled with Python ~3.9 may still use int version API.
282+
// Remove this check after we drop supporting extension module built with
283+
// Python ~3.9.
280284
#define ERROR_NEED_PY_SSIZE_T_CLEAN \
281285
{ \
282286
PyErr_SetString(PyExc_SystemError, \

0 commit comments

Comments
 (0)