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-104922: Make PY_SSIZE_T_CLEAN not mandatory #104923

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Make PY_SSIZE_T_CLEAN not mandatory.
  • Loading branch information
methane committed May 25, 2023
commit 80eefbf1a7cfa1916de88f055357fc5441d3174f
6 changes: 2 additions & 4 deletions Include/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,8 @@ extern "C" {
This function always succeeds. */


#ifdef PY_SSIZE_T_CLEAN
# define PyObject_CallFunction _PyObject_CallFunction_SizeT
# define PyObject_CallMethod _PyObject_CallMethod_SizeT
#endif
#define PyObject_CallFunction _PyObject_CallFunction_SizeT
#define PyObject_CallMethod _PyObject_CallMethod_SizeT


#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
Expand Down
4 changes: 1 addition & 3 deletions Include/cpython/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

/* === Object Protocol ================================================== */

#ifdef PY_SSIZE_T_CLEAN
# define _PyObject_CallMethodId _PyObject_CallMethodId_SizeT
#endif
#define _PyObject_CallMethodId _PyObject_CallMethodId_SizeT

Copy link
Member Author

@methane methane May 25, 2023

Choose a reason for hiding this comment

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

These are not a part of stable ABI.
_PyObject_CallMethodId_SizeT is removed and _PyObject_CallMethodId is ssize_t version.

/* Convert keyword arguments from the FASTCALL (stack: C array, kwnames: tuple)
format to a Python dictionary ("kwargs" dict).
Expand Down
16 changes: 2 additions & 14 deletions Include/cpython/modsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@
# error "this header file must not be included directly"
#endif

/* If PY_SSIZE_T_CLEAN is defined, each functions treats #-specifier
to mean Py_ssize_t */
#ifdef PY_SSIZE_T_CLEAN
/* Each functions treats #-specifier to mean Py_ssize_t
* regardless PY_SSIZE_T_CLEAN */
#define _Py_VaBuildStack _Py_VaBuildStack_SizeT
#else
PyAPI_FUNC(PyObject *) _Py_VaBuildValue_SizeT(const char *, va_list);
PyAPI_FUNC(PyObject **) _Py_VaBuildStack_SizeT(
PyObject **small_stack,
Py_ssize_t small_stack_len,
const char *format,
va_list va,
Py_ssize_t *p_nargs);
#endif
Copy link
Member Author

@methane methane May 25, 2023

Choose a reason for hiding this comment

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

Both of _Py_VaBuildStack and _Py_VaBuildStack_SizeT are remained, without macro alias.


PyAPI_FUNC(int) _PyArg_UnpackStack(
PyObject *const *args,
Expand Down Expand Up @@ -63,12 +53,10 @@ typedef struct _PyArg_Parser {
struct _PyArg_Parser *next;
} _PyArg_Parser;

#ifdef PY_SSIZE_T_CLEAN
#define _PyArg_ParseTupleAndKeywordsFast _PyArg_ParseTupleAndKeywordsFast_SizeT
#define _PyArg_ParseStack _PyArg_ParseStack_SizeT
#define _PyArg_ParseStackAndKeywords _PyArg_ParseStackAndKeywords_SizeT
#define _PyArg_VaParseTupleAndKeywordsFast _PyArg_VaParseTupleAndKeywordsFast_SizeT
#endif

PyAPI_FUNC(int) _PyArg_ParseTupleAndKeywordsFast(PyObject *, PyObject *,
struct _PyArg_Parser *, ...);
Expand Down
9 changes: 4 additions & 5 deletions Include/modsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@ extern "C" {

#include <stdarg.h> // va_list

/* If PY_SSIZE_T_CLEAN is defined, each functions treats #-specifier
to mean Py_ssize_t */
#ifdef PY_SSIZE_T_CLEAN
/* Since Python 3.13, each functions treats #-specifier to mean Py_ssize_t
* regardless PY_SSIZE_T_CLEAN is defined,
*/
#define PyArg_Parse _PyArg_Parse_SizeT
#define PyArg_ParseTuple _PyArg_ParseTuple_SizeT
#define PyArg_ParseTupleAndKeywords _PyArg_ParseTupleAndKeywords_SizeT
#define PyArg_VaParse _PyArg_VaParse_SizeT
#define PyArg_VaParseTupleAndKeywords _PyArg_VaParseTupleAndKeywords_SizeT
#define Py_BuildValue _Py_BuildValue_SizeT
#define Py_VaBuildValue _Py_VaBuildValue_SizeT
#endif

/* Due to a glitch in 3.2, the _SizeT versions weren't exported from the DLL. */
#if !defined(PY_SSIZE_T_CLEAN) || !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
PyAPI_FUNC(int) PyArg_Parse(PyObject *, const char *, ...);
PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...);
PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
``PY_SSIZE_T_CLEAN`` is no longer required to use '#' specifier in APIs like
:c:func:`PyArg_ParseTuple` and :c:func:`Py_BuildValue`.
6 changes: 5 additions & 1 deletion Python/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,11 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
char *msgbuf, size_t bufsize, freelist_t *freelist)
{
#define RETURN_ERR_OCCURRED return msgbuf
/* For # codes */
// For # codes
// Even though Python 3.13 uses ssize_t ragardless PY_SSIZE_T_CLEAN,
// extension compiled with Python ~3.9 may still use int version API.
// Remove this check after we drop supporting extension module built with
// Python ~3.9.
#define REQUIRE_PY_SSIZE_T_CLEAN \
if (!(flags & FLAG_SIZE_T)) { \
PyErr_SetString(PyExc_SystemError, \
Expand Down
4 changes: 4 additions & 0 deletions Python/modsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ do_mktuple(const char **p_format, va_list *p_va, char endchar, Py_ssize_t n, int
static PyObject *
do_mkvalue(const char **p_format, va_list *p_va, int flags)
{
// Even though Python 3.13 uses ssize_t ragardless PY_SSIZE_T_CLEAN,
// extension compiled with Python ~3.9 may still use int version API.
// Remove this check after we drop supporting extension module built with
// Python ~3.9.
#define ERROR_NEED_PY_SSIZE_T_CLEAN \
{ \
PyErr_SetString(PyExc_SystemError, \
Expand Down