Skip to content

Commit 699f348

Browse files
committed
Make PY_SSIZE_T_CLEAN always.
1 parent bd98b65 commit 699f348

File tree

10 files changed

+47
-300
lines changed

10 files changed

+47
-300
lines changed

Include/abstract.h

-15
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,6 @@ 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
142-
143-
144138
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
145139
/* Call a callable Python object without any arguments */
146140
PyAPI_FUNC(PyObject *) PyObject_CallNoArgs(PyObject *func);
@@ -195,15 +189,6 @@ PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *obj,
195189
const char *name,
196190
const char *format, ...);
197191

198-
PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable,
199-
const char *format,
200-
...);
201-
202-
PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *obj,
203-
const char *name,
204-
const char *format,
205-
...);
206-
207192
/* Call a callable Python object 'callable' with a variable number of C
208193
arguments. The C arguments are provided as PyObject* values, terminated
209194
by a NULL.

Include/cpython/abstract.h

-9
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

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

7-
#ifdef PY_SSIZE_T_CLEAN
8-
# define _PyObject_CallMethodId _PyObject_CallMethodId_SizeT
9-
#endif
10-
117
/* Convert keyword arguments from the FASTCALL (stack: C array, kwnames: tuple)
128
format to a Python dictionary ("kwargs" dict).
139
@@ -113,11 +109,6 @@ PyAPI_FUNC(PyObject *) _PyObject_CallMethodId(PyObject *obj,
113109
_Py_Identifier *name,
114110
const char *format, ...);
115111

116-
PyAPI_FUNC(PyObject *) _PyObject_CallMethodId_SizeT(PyObject *obj,
117-
_Py_Identifier *name,
118-
const char *format,
119-
...);
120-
121112
PyAPI_FUNC(PyObject *) _PyObject_CallMethodIdObjArgs(
122113
PyObject *obj,
123114
_Py_Identifier *name,

Include/cpython/modsupport.h

-21
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,6 @@
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
8-
#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
18-
195
PyAPI_FUNC(int) _PyArg_UnpackStack(
206
PyObject *const *args,
217
Py_ssize_t nargs,
@@ -63,13 +49,6 @@ typedef struct _PyArg_Parser {
6349
struct _PyArg_Parser *next;
6450
} _PyArg_Parser;
6551

66-
#ifdef PY_SSIZE_T_CLEAN
67-
#define _PyArg_ParseTupleAndKeywordsFast _PyArg_ParseTupleAndKeywordsFast_SizeT
68-
#define _PyArg_ParseStack _PyArg_ParseStack_SizeT
69-
#define _PyArg_ParseStackAndKeywords _PyArg_ParseStackAndKeywords_SizeT
70-
#define _PyArg_VaParseTupleAndKeywordsFast _PyArg_VaParseTupleAndKeywordsFast_SizeT
71-
#endif
72-
7352
PyAPI_FUNC(int) _PyArg_ParseTupleAndKeywordsFast(PyObject *, PyObject *,
7453
struct _PyArg_Parser *, ...);
7554
PyAPI_FUNC(int) _PyArg_ParseStack(

Include/modsupport.h

+1-16
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,17 @@ 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
15-
#define PyArg_Parse _PyArg_Parse_SizeT
16-
#define PyArg_ParseTuple _PyArg_ParseTuple_SizeT
17-
#define PyArg_ParseTupleAndKeywords _PyArg_ParseTupleAndKeywords_SizeT
18-
#define PyArg_VaParse _PyArg_VaParse_SizeT
19-
#define PyArg_VaParseTupleAndKeywords _PyArg_VaParseTupleAndKeywords_SizeT
20-
#define Py_BuildValue _Py_BuildValue_SizeT
21-
#define Py_VaBuildValue _Py_VaBuildValue_SizeT
22-
#endif
23-
24-
/* 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
2612
PyAPI_FUNC(int) PyArg_Parse(PyObject *, const char *, ...);
2713
PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...);
2814
PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
2915
const char *, char **, ...);
3016
PyAPI_FUNC(int) PyArg_VaParse(PyObject *, const char *, va_list);
3117
PyAPI_FUNC(int) PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *,
3218
const char *, char **, va_list);
33-
#endif
19+
3420
PyAPI_FUNC(int) PyArg_ValidateKeywordArguments(PyObject *);
3521
PyAPI_FUNC(int) PyArg_UnpackTuple(PyObject *, const char *, Py_ssize_t, Py_ssize_t, ...);
3622
PyAPI_FUNC(PyObject *) Py_BuildValue(const char *, ...);
37-
PyAPI_FUNC(PyObject *) _Py_BuildValue_SizeT(const char *, ...);
3823

3924

4025
PyAPI_FUNC(PyObject *) Py_VaBuildValue(const char *, va_list);

Lib/test/test_capi/test_getargs.py

-17
Original file line numberDiff line numberDiff line change
@@ -901,23 +901,6 @@ def test_s_hash(self):
901901
self.assertRaises(TypeError, getargs_s_hash, memoryview(b'memoryview'))
902902
self.assertRaises(TypeError, getargs_s_hash, None)
903903

904-
def test_s_hash_int(self):
905-
# "s#" without PY_SSIZE_T_CLEAN defined.
906-
from _testcapi import getargs_s_hash_int
907-
from _testcapi import getargs_s_hash_int2
908-
buf = bytearray([1, 2])
909-
self.assertRaises(SystemError, getargs_s_hash_int, buf, "abc")
910-
self.assertRaises(SystemError, getargs_s_hash_int, buf, x=42)
911-
self.assertRaises(SystemError, getargs_s_hash_int, buf, x="abc")
912-
self.assertRaises(SystemError, getargs_s_hash_int2, buf, ("abc",))
913-
self.assertRaises(SystemError, getargs_s_hash_int2, buf, x=42)
914-
self.assertRaises(SystemError, getargs_s_hash_int2, buf, x="abc")
915-
buf.append(3) # still mutable -- not locked by a buffer export
916-
# getargs_s_hash_int(buf) may not raise SystemError because skipitem()
917-
# is not called. But it is an implementation detail.
918-
# getargs_s_hash_int(buf)
919-
# getargs_s_hash_int2(buf)
920-
921904
def test_z(self):
922905
from _testcapi import getargs_z
923906
self.assertEqual(getargs_z('abc\xe9'), b'abc\xc3\xa9')

Modules/_testcapi/getargs.c

-40
Original file line numberDiff line numberDiff line change
@@ -816,44 +816,6 @@ test_s_code(PyObject *self, PyObject *Py_UNUSED(ignored))
816816
Py_RETURN_NONE;
817817
}
818818

819-
#undef PyArg_ParseTupleAndKeywords
820-
PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
821-
const char *, char **, ...);
822-
823-
static PyObject *
824-
getargs_s_hash_int(PyObject *self, PyObject *args, PyObject *kwargs)
825-
{
826-
static char *keywords[] = {"", "", "x", NULL};
827-
Py_buffer buf = {NULL};
828-
const char *s;
829-
int len;
830-
int i = 0;
831-
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "w*|s#i", keywords,
832-
&buf, &s, &len, &i))
833-
{
834-
return NULL;
835-
}
836-
PyBuffer_Release(&buf);
837-
Py_RETURN_NONE;
838-
}
839-
840-
static PyObject *
841-
getargs_s_hash_int2(PyObject *self, PyObject *args, PyObject *kwargs)
842-
{
843-
static char *keywords[] = {"", "", "x", NULL};
844-
Py_buffer buf = {NULL};
845-
const char *s;
846-
int len;
847-
int i = 0;
848-
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "w*|(s#)i", keywords,
849-
&buf, &s, &len, &i))
850-
{
851-
return NULL;
852-
}
853-
PyBuffer_Release(&buf);
854-
Py_RETURN_NONE;
855-
}
856-
857819
static PyObject *
858820
gh_99240_clear_args(PyObject *self, PyObject *args)
859821
{
@@ -906,8 +868,6 @@ static PyMethodDef test_methods[] = {
906868
{"getargs_positional_only_and_keywords", _PyCFunction_CAST(getargs_positional_only_and_keywords), METH_VARARGS|METH_KEYWORDS},
907869
{"getargs_s", getargs_s, METH_VARARGS},
908870
{"getargs_s_hash", getargs_s_hash, METH_VARARGS},
909-
{"getargs_s_hash_int", _PyCFunction_CAST(getargs_s_hash_int), METH_VARARGS|METH_KEYWORDS},
910-
{"getargs_s_hash_int2", _PyCFunction_CAST(getargs_s_hash_int2), METH_VARARGS|METH_KEYWORDS},
911871
{"getargs_s_star", getargs_s_star, METH_VARARGS},
912872
{"getargs_tuple", getargs_tuple, METH_VARARGS},
913873
{"getargs_u", getargs_u, METH_VARARGS},

Objects/call.c

+21-46
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ _PyObject_Call_Prepend(PyThreadState *tstate, PyObject *callable,
519519

520520
static PyObject *
521521
_PyObject_CallFunctionVa(PyThreadState *tstate, PyObject *callable,
522-
const char *format, va_list va, int is_size_t)
522+
const char *format, va_list va)
523523
{
524524
PyObject* small_stack[_PY_FASTCALL_SMALL_STACK];
525525
const Py_ssize_t small_stack_len = Py_ARRAY_LENGTH(small_stack);
@@ -535,14 +535,8 @@ _PyObject_CallFunctionVa(PyThreadState *tstate, PyObject *callable,
535535
return _PyObject_CallNoArgsTstate(tstate, callable);
536536
}
537537

538-
if (is_size_t) {
539-
stack = _Py_VaBuildStack_SizeT(small_stack, small_stack_len,
540-
format, va, &nargs);
541-
}
542-
else {
543-
stack = _Py_VaBuildStack(small_stack, small_stack_len,
544-
format, va, &nargs);
545-
}
538+
stack = _Py_VaBuildStack(small_stack, small_stack_len,
539+
format, va, &nargs);
546540
if (stack == NULL) {
547541
return NULL;
548542
}
@@ -581,7 +575,7 @@ PyObject_CallFunction(PyObject *callable, const char *format, ...)
581575
PyThreadState *tstate = _PyThreadState_GET();
582576

583577
va_start(va, format);
584-
result = _PyObject_CallFunctionVa(tstate, callable, format, va, 0);
578+
result = _PyObject_CallFunctionVa(tstate, callable, format, va);
585579
va_end(va);
586580

587581
return result;
@@ -599,29 +593,32 @@ PyEval_CallFunction(PyObject *callable, const char *format, ...)
599593
PyThreadState *tstate = _PyThreadState_GET();
600594

601595
va_start(va, format);
602-
result = _PyObject_CallFunctionVa(tstate, callable, format, va, 0);
596+
result = _PyObject_CallFunctionVa(tstate, callable, format, va);
603597
va_end(va);
604598

605599
return result;
606600
}
607601

608602

609-
PyObject *
603+
/* _PyObject_CallFunction_SizeT is exact copy of PyObject_CallFunction.
604+
* This function must be kept because it is part of the stable ABI.
605+
*/
606+
PyAPI_FUNC(PyObject *) /* abi_only */
610607
_PyObject_CallFunction_SizeT(PyObject *callable, const char *format, ...)
611608
{
612609
PyThreadState *tstate = _PyThreadState_GET();
613610

614611
va_list va;
615612
va_start(va, format);
616-
PyObject *result = _PyObject_CallFunctionVa(tstate, callable, format, va, 1);
613+
PyObject *result = _PyObject_CallFunctionVa(tstate, callable, format, va);
617614
va_end(va);
618615

619616
return result;
620617
}
621618

622619

623620
static PyObject*
624-
callmethod(PyThreadState *tstate, PyObject* callable, const char *format, va_list va, int is_size_t)
621+
callmethod(PyThreadState *tstate, PyObject* callable, const char *format, va_list va)
625622
{
626623
assert(callable != NULL);
627624
if (!PyCallable_Check(callable)) {
@@ -631,7 +628,7 @@ callmethod(PyThreadState *tstate, PyObject* callable, const char *format, va_lis
631628
return NULL;
632629
}
633630

634-
return _PyObject_CallFunctionVa(tstate, callable, format, va, is_size_t);
631+
return _PyObject_CallFunctionVa(tstate, callable, format, va);
635632
}
636633

637634
PyObject *
@@ -650,7 +647,7 @@ PyObject_CallMethod(PyObject *obj, const char *name, const char *format, ...)
650647

651648
va_list va;
652649
va_start(va, format);
653-
PyObject *retval = callmethod(tstate, callable, format, va, 0);
650+
PyObject *retval = callmethod(tstate, callable, format, va);
654651
va_end(va);
655652

656653
Py_DECREF(callable);
@@ -676,7 +673,7 @@ PyEval_CallMethod(PyObject *obj, const char *name, const char *format, ...)
676673

677674
va_list va;
678675
va_start(va, format);
679-
PyObject *retval = callmethod(tstate, callable, format, va, 0);
676+
PyObject *retval = callmethod(tstate, callable, format, va);
680677
va_end(va);
681678

682679
Py_DECREF(callable);
@@ -700,7 +697,7 @@ _PyObject_CallMethod(PyObject *obj, PyObject *name,
700697

701698
va_list va;
702699
va_start(va, format);
703-
PyObject *retval = callmethod(tstate, callable, format, va, 1);
700+
PyObject *retval = callmethod(tstate, callable, format, va);
704701
va_end(va);
705702

706703
Py_DECREF(callable);
@@ -724,7 +721,7 @@ _PyObject_CallMethodId(PyObject *obj, _Py_Identifier *name,
724721

725722
va_list va;
726723
va_start(va, format);
727-
PyObject *retval = callmethod(tstate, callable, format, va, 0);
724+
PyObject *retval = callmethod(tstate, callable, format, va);
728725
va_end(va);
729726

730727
Py_DECREF(callable);
@@ -737,13 +734,15 @@ PyObject * _PyObject_CallMethodFormat(PyThreadState *tstate, PyObject *callable,
737734
{
738735
va_list va;
739736
va_start(va, format);
740-
PyObject *retval = callmethod(tstate, callable, format, va, 0);
737+
PyObject *retval = callmethod(tstate, callable, format, va);
741738
va_end(va);
742739
return retval;
743740
}
744741

745742

746-
PyObject *
743+
// _PyObject_CallMethod_SizeT is exact copy of PyObject_CallMethod.
744+
// This function must be kept because it is part of the stable ABI.
745+
PyAPI_FUNC(PyObject *) /* abi_only */
747746
_PyObject_CallMethod_SizeT(PyObject *obj, const char *name,
748747
const char *format, ...)
749748
{
@@ -759,31 +758,7 @@ _PyObject_CallMethod_SizeT(PyObject *obj, const char *name,
759758

760759
va_list va;
761760
va_start(va, format);
762-
PyObject *retval = callmethod(tstate, callable, format, va, 1);
763-
va_end(va);
764-
765-
Py_DECREF(callable);
766-
return retval;
767-
}
768-
769-
770-
PyObject *
771-
_PyObject_CallMethodId_SizeT(PyObject *obj, _Py_Identifier *name,
772-
const char *format, ...)
773-
{
774-
PyThreadState *tstate = _PyThreadState_GET();
775-
if (obj == NULL || name == NULL) {
776-
return null_error(tstate);
777-
}
778-
779-
PyObject *callable = _PyObject_GetAttrId(obj, name);
780-
if (callable == NULL) {
781-
return NULL;
782-
}
783-
784-
va_list va;
785-
va_start(va, format);
786-
PyObject *retval = callmethod(tstate, callable, format, va, 1);
761+
PyObject *retval = callmethod(tstate, callable, format, va);
787762
va_end(va);
788763

789764
Py_DECREF(callable);

0 commit comments

Comments
 (0)