bpo-36974: implement PEP 590 (GH-13185)
Co-authored-by: Jeroen Demeyer <J.Demeyer@UGent.be>
Co-authored-by: Mark Shannon <mark@hotpy.org>
diff --git a/Include/cpython/object.h b/Include/cpython/object.h
index ba52a48..a65aaf6 100644
--- a/Include/cpython/object.h
+++ b/Include/cpython/object.h
@@ -55,6 +55,9 @@
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);
+
/* Maximum number of dimensions */
#define PyBUF_MAX_NDIM 64
@@ -167,12 +170,9 @@
releasebufferproc bf_releasebuffer;
} PyBufferProcs;
-/* We can't provide a full compile-time check that limited-API
- users won't implement tp_print. However, not defining printfunc
- and making tp_print of a different function pointer type
- if Py_LIMITED_API is set should at least cause a warning
- in most cases. */
-typedef int (*printfunc)(PyObject *, FILE *, int);
+/* Allow printfunc in the tp_vectorcall_offset slot for
+ * backwards-compatibility */
+typedef Py_ssize_t printfunc;
typedef struct _typeobject {
PyObject_VAR_HEAD
@@ -182,7 +182,7 @@
/* Methods to implement standard operations */
destructor tp_dealloc;
- printfunc tp_print;
+ Py_ssize_t tp_vectorcall_offset;
getattrfunc tp_getattr;
setattrfunc tp_setattr;
PyAsyncMethods *tp_as_async; /* formerly known as tp_compare (Python 2)
@@ -254,6 +254,7 @@
unsigned int tp_version_tag;
destructor tp_finalize;
+ vectorcallfunc tp_vectorcall;
#ifdef COUNT_ALLOCS
/* these must be last and never explicitly initialized */