Skip to content

Commit

Permalink
Revert "pythongh-93274: Expose receiving vectorcall in the Limited API (
Browse files Browse the repository at this point in the history
pythonGH-95717)"

This reverts commit 656dad7.
  • Loading branch information
encukou committed Aug 8, 2022
1 parent 63140b4 commit 4ed63c9
Show file tree
Hide file tree
Showing 18 changed files with 13 additions and 152 deletions.
3 changes: 0 additions & 3 deletions Doc/data/stable_abi.dat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 3 additions & 11 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -426,22 +426,14 @@ New Features
an additional metaclass argument.
(Contributed by Wenzel Jakob in :gh:`93012`.)

* API for creating objects that can be called using
:ref:`the vectorcall protocol <vectorcall>` was added to the
:ref:`Limited API <stable>`:

* :const:`Py_TPFLAGS_HAVE_VECTORCALL`
* :c:func:`PyVectorcall_NARGS`
* :c:func:`PyVectorcall_Call`
* :c:type:`vectorcallfunc`

* (XXX: this should be combined with :gh:`93274` when that is done)
The :const:`Py_TPFLAGS_HAVE_VECTORCALL` flag is now removed from a class
when the class's :py:meth:`~object.__call__` method is reassigned.
This makes vectorcall safe to use with mutable types (i.e. heap types
without the :const:`immutable <Py_TPFLAGS_IMMUTABLETYPE>` flag).
Mutable types that do not override :c:member:`~PyTypeObject.tp_call` now
inherit the ``Py_TPFLAGS_HAVE_VECTORCALL`` flag.
(Contributed by Petr Viktorin in :gh:`93274`.)
inherit the :const:`Py_TPFLAGS_HAVE_VECTORCALL` flag.
(Contributed by Petr Viktorin in :gh:`93012`.)

Porting to Python 3.12
----------------------
Expand Down
10 changes: 0 additions & 10 deletions Include/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,6 @@ PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs(
PyObject *name,
...);

/* Given a vectorcall nargsf argument, return the actual number of arguments.
* (For use outside the limited API, this is re-defined as a static inline
* function in cpython/abstract.h)
*/
PyAPI_FUNC(Py_ssize_t) PyVectorcall_NARGS(size_t nargsf);

/* Call "callable" (which must support vectorcall) with positional arguments
"tuple" and keyword arguments "dict". "dict" may also be NULL */
PyAPI_FUNC(PyObject *) PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *dict);


/* Implemented elsewhere:
Expand Down
10 changes: 5 additions & 5 deletions Include/cpython/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,8 @@ PyAPI_FUNC(PyObject *) _PyObject_MakeTpCall(
#define PY_VECTORCALL_ARGUMENTS_OFFSET \
(_Py_STATIC_CAST(size_t, 1) << (8 * sizeof(size_t) - 1))

// PyVectorcall_NARGS() is exported as a function for the stable ABI.
// Here (when we are not using the stable ABI), the name is overridden to
// call a static inline function for best performance.
#define PyVectorcall_NARGS(n) _PyVectorcall_NARGS(n)
static inline Py_ssize_t
_PyVectorcall_NARGS(size_t n)
PyVectorcall_NARGS(size_t n)
{
return n & ~PY_VECTORCALL_ARGUMENTS_OFFSET;
}
Expand Down Expand Up @@ -88,6 +84,10 @@ PyAPI_FUNC(PyObject *) PyObject_VectorcallDict(
size_t nargsf,
PyObject *kwargs);

/* Call "callable" (which must support vectorcall) with positional arguments
"tuple" and keyword arguments "dict". "dict" may also be NULL */
PyAPI_FUNC(PyObject *) PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *dict);

// Same as PyObject_Vectorcall(), except without keyword arguments
PyAPI_FUNC(PyObject *) _PyObject_FastCall(
PyObject *func,
Expand Down
3 changes: 3 additions & 0 deletions Include/cpython/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ typedef struct _Py_Identifier {
typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
typedef void (*releasebufferproc)(PyObject *, Py_buffer *);

typedef PyObject *(*vectorcallfunc)(PyObject *callable, PyObject *const *args,
size_t nargsf, PyObject *kwnames);


typedef struct {
/* Number implementations must check *both*
Expand Down
9 changes: 1 addition & 8 deletions Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,6 @@ typedef int (*initproc)(PyObject *, PyObject *, PyObject *);
typedef PyObject *(*newfunc)(PyTypeObject *, PyObject *, PyObject *);
typedef PyObject *(*allocfunc)(PyTypeObject *, Py_ssize_t);

#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030c0000 // 3.12
typedef PyObject *(*vectorcallfunc)(PyObject *callable, PyObject *const *args,
size_t nargsf, PyObject *kwnames);
#endif

typedef struct{
int slot; /* slot id, see below */
void *pfunc; /* function pointer */
Expand Down Expand Up @@ -386,13 +381,11 @@ given type object has a specified feature.
#define Py_TPFLAGS_BASETYPE (1UL << 10)

/* Set if the type implements the vectorcall protocol (PEP 590) */
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030C0000
#define Py_TPFLAGS_HAVE_VECTORCALL (1UL << 11)
#ifndef Py_LIMITED_API
#define Py_TPFLAGS_HAVE_VECTORCALL (1UL << 11)
// Backwards compatibility alias for API that was provisional in Python 3.8
#define _Py_TPFLAGS_HAVE_VECTORCALL Py_TPFLAGS_HAVE_VECTORCALL
#endif
#endif

/* Set if the type is 'ready' -- fully initialized */
#define Py_TPFLAGS_READY (1UL << 12)
Expand Down
5 changes: 0 additions & 5 deletions Lib/test/test_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,11 +759,6 @@ def __call__(self, *args):
self.assertEqual(expected, meth(*args1, **kwargs))
self.assertEqual(expected, wrapped(*args, **kwargs))

def test_vectorcall_limited(self):
from _testcapi import pyobject_vectorcall
obj = _testcapi.LimitedVectorCallClass()
self.assertEqual(pyobject_vectorcall(obj, (), ()), "vectorcall called")


class A:
def method_two_args(self, x, y):
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_stable_abi_ctypes.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

9 changes: 0 additions & 9 deletions Misc/stable_abi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2275,14 +2275,5 @@
added = '3.11'
[function.PyErr_SetHandledException]
added = '3.11'

[function.PyType_FromMetaclass]
added = '3.12'
[const.Py_TPFLAGS_HAVE_VECTORCALL]
added = '3.12'
[function.PyVectorcall_NARGS]
added = '3.12'
[function.PyVectorcall_Call]
added = '3.12'
[typedef.vectorcallfunc]
added = '3.12'
2 changes: 1 addition & 1 deletion Modules/Setup.stdlib.in
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
@MODULE__XXTESTFUZZ_TRUE@_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
@MODULE__TESTBUFFER_TRUE@_testbuffer _testbuffer.c
@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c
@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/vectorcall_limited.c _testcapi/heaptype.c
@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/heaptype.c

# Some testing modules MUST be built as shared libraries.
*shared*
Expand Down
1 change: 0 additions & 1 deletion Modules/_testcapi/parts.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "Python.h"

int _PyTestCapi_Init_Vectorcall(PyObject *module);
int _PyTestCapi_Init_VectorcallLimited(PyObject *module);
int _PyTestCapi_Init_Heaptype(PyObject *module);
77 changes: 0 additions & 77 deletions Modules/_testcapi/vectorcall_limited.c

This file was deleted.

3 changes: 0 additions & 3 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -6865,9 +6865,6 @@ PyInit__testcapi(void)
if (_PyTestCapi_Init_Vectorcall(m) < 0) {
return NULL;
}
if (_PyTestCapi_Init_VectorcallLimited(m) < 0) {
return NULL;
}
if (_PyTestCapi_Init_Heaptype(m) < 0) {
return NULL;
}
Expand Down
8 changes: 0 additions & 8 deletions Objects/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -1047,11 +1047,3 @@ _PyStack_UnpackDict_Free(PyObject *const *stack, Py_ssize_t nargs,
PyMem_Free((PyObject **)stack - 1);
Py_DECREF(kwnames);
}

// Export for the stable ABI
#undef PyVectorcall_NARGS
Py_ssize_t
PyVectorcall_NARGS(size_t n)
{
return _PyVectorcall_NARGS(n);
}
2 changes: 0 additions & 2 deletions PC/python3dll.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion PCbuild/_testcapi.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
<ItemGroup>
<ClCompile Include="..\Modules\_testcapimodule.c" />
<ClCompile Include="..\Modules\_testcapi\vectorcall.c" />
<ClCompile Include="..\Modules\_testcapi\vectorcall_limited.c" />
<ClCompile Include="..\Modules\_testcapi\heaptype.c" />
</ItemGroup>
<ItemGroup>
Expand Down
3 changes: 0 additions & 3 deletions PCbuild/_testcapi.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
<ClCompile Include="..\Modules\_testcapi\vectorcall.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Modules\_testcapi\vectorcall_limited.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Modules\_testcapi\heaptype.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down

0 comments on commit 4ed63c9

Please sign in to comment.