Skip to content

Commit 4060283

Browse files
authored
bpo-35134: Create Include/cpython/abstract.h (GH-10728)
Move abstract.h code surrounded by "#ifndef Py_LIMITED_API" to a new Include/cpython/abstract.h header file.
1 parent 8c281ed commit 4060283

File tree

2 files changed

+285
-281
lines changed

2 files changed

+285
-281
lines changed

Include/abstract.h

+4-281
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,6 @@ extern "C" {
138138
#ifdef PY_SSIZE_T_CLEAN
139139
# define PyObject_CallFunction _PyObject_CallFunction_SizeT
140140
# define PyObject_CallMethod _PyObject_CallMethod_SizeT
141-
# ifndef Py_LIMITED_API
142-
# define _PyObject_CallMethodId _PyObject_CallMethodId_SizeT
143-
# endif /* !Py_LIMITED_API */
144141
#endif
145142

146143

@@ -155,123 +152,6 @@ extern "C" {
155152
PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable,
156153
PyObject *args, PyObject *kwargs);
157154

158-
#ifndef Py_LIMITED_API
159-
PyAPI_FUNC(PyObject*) _PyStack_AsTuple(
160-
PyObject *const *stack,
161-
Py_ssize_t nargs);
162-
163-
PyAPI_FUNC(PyObject*) _PyStack_AsTupleSlice(
164-
PyObject *const *stack,
165-
Py_ssize_t nargs,
166-
Py_ssize_t start,
167-
Py_ssize_t end);
168-
169-
/* Convert keyword arguments from the FASTCALL (stack: C array, kwnames: tuple)
170-
format to a Python dictionary ("kwargs" dict).
171-
172-
The type of kwnames keys is not checked. The final function getting
173-
arguments is responsible to check if all keys are strings, for example using
174-
PyArg_ParseTupleAndKeywords() or PyArg_ValidateKeywordArguments().
175-
176-
Duplicate keys are merged using the last value. If duplicate keys must raise
177-
an exception, the caller is responsible to implement an explicit keys on
178-
kwnames. */
179-
PyAPI_FUNC(PyObject *) _PyStack_AsDict(
180-
PyObject *const *values,
181-
PyObject *kwnames);
182-
183-
/* Convert (args, nargs, kwargs: dict) into a (stack, nargs, kwnames: tuple).
184-
185-
Return 0 on success, raise an exception and return -1 on error.
186-
187-
Write the new stack into *p_stack. If *p_stack is differen than args, it
188-
must be released by PyMem_Free().
189-
190-
The stack uses borrowed references.
191-
192-
The type of keyword keys is not checked, these checks should be done
193-
later (ex: _PyArg_ParseStackAndKeywords). */
194-
PyAPI_FUNC(int) _PyStack_UnpackDict(
195-
PyObject *const *args,
196-
Py_ssize_t nargs,
197-
PyObject *kwargs,
198-
PyObject *const **p_stack,
199-
PyObject **p_kwnames);
200-
201-
/* Suggested size (number of positional arguments) for arrays of PyObject*
202-
allocated on a C stack to avoid allocating memory on the heap memory. Such
203-
array is used to pass positional arguments to call functions of the
204-
_PyObject_FastCall() family.
205-
206-
The size is chosen to not abuse the C stack and so limit the risk of stack
207-
overflow. The size is also chosen to allow using the small stack for most
208-
function calls of the Python standard library. On 64-bit CPU, it allocates
209-
40 bytes on the stack. */
210-
#define _PY_FASTCALL_SMALL_STACK 5
211-
212-
/* Return 1 if callable supports FASTCALL calling convention for positional
213-
arguments: see _PyObject_FastCallDict() and _PyObject_FastCallKeywords() */
214-
PyAPI_FUNC(int) _PyObject_HasFastCall(PyObject *callable);
215-
216-
/* Call the callable object 'callable' with the "fast call" calling convention:
217-
args is a C array for positional arguments (nargs is the number of
218-
positional arguments), kwargs is a dictionary for keyword arguments.
219-
220-
If nargs is equal to zero, args can be NULL. kwargs can be NULL.
221-
nargs must be greater or equal to zero.
222-
223-
Return the result on success. Raise an exception on return NULL on
224-
error. */
225-
PyAPI_FUNC(PyObject *) _PyObject_FastCallDict(
226-
PyObject *callable,
227-
PyObject *const *args,
228-
Py_ssize_t nargs,
229-
PyObject *kwargs);
230-
231-
/* Call the callable object 'callable' with the "fast call" calling convention:
232-
args is a C array for positional arguments followed by values of
233-
keyword arguments. Keys of keyword arguments are stored as a tuple
234-
of strings in kwnames. nargs is the number of positional parameters at
235-
the beginning of stack. The size of kwnames gives the number of keyword
236-
values in the stack after positional arguments.
237-
238-
kwnames must only contains str strings, no subclass, and all keys must
239-
be unique.
240-
241-
If nargs is equal to zero and there is no keyword argument (kwnames is
242-
NULL or its size is zero), args can be NULL.
243-
244-
Return the result on success. Raise an exception and return NULL on
245-
error. */
246-
PyAPI_FUNC(PyObject *) _PyObject_FastCallKeywords(
247-
PyObject *callable,
248-
PyObject *const *args,
249-
Py_ssize_t nargs,
250-
PyObject *kwnames);
251-
252-
#define _PyObject_FastCall(func, args, nargs) \
253-
_PyObject_FastCallDict((func), (args), (nargs), NULL)
254-
255-
#define _PyObject_CallNoArg(func) \
256-
_PyObject_FastCallDict((func), NULL, 0, NULL)
257-
258-
PyAPI_FUNC(PyObject *) _PyObject_Call_Prepend(
259-
PyObject *callable,
260-
PyObject *obj,
261-
PyObject *args,
262-
PyObject *kwargs);
263-
264-
PyAPI_FUNC(PyObject *) _PyObject_FastCall_Prepend(
265-
PyObject *callable,
266-
PyObject *obj,
267-
PyObject *const *args,
268-
Py_ssize_t nargs);
269-
270-
PyAPI_FUNC(PyObject *) _Py_CheckFunctionResult(PyObject *callable,
271-
PyObject *result,
272-
const char *where);
273-
#endif /* Py_LIMITED_API */
274-
275155

276156
/* Call a callable Python object 'callable', with arguments given by the
277157
tuple 'args'. If no arguments are needed, then 'args' can be *NULL*.
@@ -309,14 +189,6 @@ PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *obj,
309189
const char *name,
310190
const char *format, ...);
311191

312-
#ifndef Py_LIMITED_API
313-
/* Like PyObject_CallMethod(), but expect a _Py_Identifier*
314-
as the method name. */
315-
PyAPI_FUNC(PyObject *) _PyObject_CallMethodId(PyObject *obj,
316-
_Py_Identifier *name,
317-
const char *format, ...);
318-
#endif /* !Py_LIMITED_API */
319-
320192
PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable,
321193
const char *format,
322194
...);
@@ -326,13 +198,6 @@ PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *obj,
326198
const char *format,
327199
...);
328200

329-
#ifndef Py_LIMITED_API
330-
PyAPI_FUNC(PyObject *) _PyObject_CallMethodId_SizeT(PyObject *obj,
331-
_Py_Identifier *name,
332-
const char *format,
333-
...);
334-
#endif /* !Py_LIMITED_API */
335-
336201
/* Call a callable Python object 'callable' with a variable number of C
337202
arguments. The C arguments are provided as PyObject* values, terminated
338203
by a NULL.
@@ -357,13 +222,6 @@ PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs(
357222
PyObject *name,
358223
...);
359224

360-
#ifndef Py_LIMITED_API
361-
PyAPI_FUNC(PyObject *) _PyObject_CallMethodIdObjArgs(
362-
PyObject *obj,
363-
struct _Py_Identifier *name,
364-
...);
365-
#endif /* !Py_LIMITED_API */
366-
367225

368226
/* Implemented elsewhere:
369227
@@ -418,16 +276,6 @@ PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o);
418276
PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o);
419277
#define PyObject_Length PyObject_Size
420278

421-
422-
#ifndef Py_LIMITED_API
423-
PyAPI_FUNC(int) _PyObject_HasLen(PyObject *o);
424-
425-
/* Guess the size of object 'o' using len(o) or o.__length_hint__().
426-
If neither of those return a non-negative value, then return the default
427-
value. If one of the calls fails, this function returns -1. */
428-
PyAPI_FUNC(Py_ssize_t) PyObject_LengthHint(PyObject *o, Py_ssize_t);
429-
#endif
430-
431279
/* Return element of 'o' corresponding to the object 'key'. Return NULL
432280
on failure.
433281
@@ -505,78 +353,6 @@ PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj,
505353

506354
/* === New Buffer API ============================================ */
507355

508-
#ifndef Py_LIMITED_API
509-
510-
/* Return 1 if the getbuffer function is available, otherwise return 0. */
511-
#define PyObject_CheckBuffer(obj) \
512-
(((obj)->ob_type->tp_as_buffer != NULL) && \
513-
((obj)->ob_type->tp_as_buffer->bf_getbuffer != NULL))
514-
515-
/* This is a C-API version of the getbuffer function call. It checks
516-
to make sure object has the required function pointer and issues the
517-
call.
518-
519-
Returns -1 and raises an error on failure and returns 0 on success. */
520-
PyAPI_FUNC(int) PyObject_GetBuffer(PyObject *obj, Py_buffer *view,
521-
int flags);
522-
523-
/* Get the memory area pointed to by the indices for the buffer given.
524-
Note that view->ndim is the assumed size of indices. */
525-
PyAPI_FUNC(void *) PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices);
526-
527-
/* Return the implied itemsize of the data-format area from a
528-
struct-style description. */
529-
PyAPI_FUNC(int) PyBuffer_SizeFromFormat(const char *);
530-
531-
/* Implementation in memoryobject.c */
532-
PyAPI_FUNC(int) PyBuffer_ToContiguous(void *buf, Py_buffer *view,
533-
Py_ssize_t len, char order);
534-
535-
PyAPI_FUNC(int) PyBuffer_FromContiguous(Py_buffer *view, void *buf,
536-
Py_ssize_t len, char order);
537-
538-
/* Copy len bytes of data from the contiguous chunk of memory
539-
pointed to by buf into the buffer exported by obj. Return
540-
0 on success and return -1 and raise a PyBuffer_Error on
541-
error (i.e. the object does not have a buffer interface or
542-
it is not working).
543-
544-
If fort is 'F', then if the object is multi-dimensional,
545-
then the data will be copied into the array in
546-
Fortran-style (first dimension varies the fastest). If
547-
fort is 'C', then the data will be copied into the array
548-
in C-style (last dimension varies the fastest). If fort
549-
is 'A', then it does not matter and the copy will be made
550-
in whatever way is more efficient. */
551-
PyAPI_FUNC(int) PyObject_CopyData(PyObject *dest, PyObject *src);
552-
553-
/* Copy the data from the src buffer to the buffer of destination. */
554-
PyAPI_FUNC(int) PyBuffer_IsContiguous(const Py_buffer *view, char fort);
555-
556-
/*Fill the strides array with byte-strides of a contiguous
557-
(Fortran-style if fort is 'F' or C-style otherwise)
558-
array of the given shape with the given number of bytes
559-
per element. */
560-
PyAPI_FUNC(void) PyBuffer_FillContiguousStrides(int ndims,
561-
Py_ssize_t *shape,
562-
Py_ssize_t *strides,
563-
int itemsize,
564-
char fort);
565-
566-
/* Fills in a buffer-info structure correctly for an exporter
567-
that can only share a contiguous chunk of memory of
568-
"unsigned bytes" of the given length.
569-
570-
Returns 0 on success and -1 (with raising an error) on error. */
571-
PyAPI_FUNC(int) PyBuffer_FillInfo(Py_buffer *view, PyObject *o, void *buf,
572-
Py_ssize_t len, int readonly,
573-
int flags);
574-
575-
/* Releases a Py_buffer obtained from getbuffer ParseTuple's "s*". */
576-
PyAPI_FUNC(void) PyBuffer_Release(Py_buffer *view);
577-
578-
#endif /* Py_LIMITED_API */
579-
580356
/* Takes an arbitrary object and returns the result of calling
581357
obj.__format__(format_spec). */
582358
PyAPI_FUNC(PyObject *) PyObject_Format(PyObject *obj,
@@ -594,11 +370,6 @@ PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *);
594370
595371
This function always succeeds. */
596372
PyAPI_FUNC(int) PyIter_Check(PyObject *);
597-
#ifndef Py_LIMITED_API
598-
#define PyIter_Check(obj) \
599-
((obj)->ob_type->tp_iternext != NULL && \
600-
(obj)->ob_type->tp_iternext != &_PyObject_NextNotImplemented)
601-
#endif
602373

603374
/* Takes an iterator object and calls its tp_iternext slot,
604375
returning the next value.
@@ -719,11 +490,6 @@ PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2);
719490
/* Returns 1 if obj is an index integer (has the nb_index slot of the
720491
tp_as_number structure filled in), and 0 otherwise. */
721492
PyAPI_FUNC(int) PyIndex_Check(PyObject *);
722-
#ifndef Py_LIMITED_API
723-
#define PyIndex_Check(obj) \
724-
((obj)->ob_type->tp_as_number != NULL && \
725-
(obj)->ob_type->tp_as_number->nb_index != NULL)
726-
#endif
727493

728494
/* Returns the object 'o' converted to a Python int, or NULL with an exception
729495
raised on failure. */
@@ -930,13 +696,6 @@ PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m);
930696
#define PySequence_Fast_GET_ITEM(o, i)\
931697
(PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i))
932698

933-
/* Assume tp_as_sequence and sq_item exist and that 'i' does not
934-
need to be corrected for a negative index. */
935-
#ifndef Py_LIMITED_API
936-
#define PySequence_ITEM(o, i)\
937-
( Py_TYPE(o)->tp_as_sequence->sq_item(o, i) )
938-
#endif
939-
940699
/* Return a pointer to the underlying item array for
941700
an object retured by PySequence_Fast */
942701
#define PySequence_Fast_ITEMS(sf) \
@@ -956,27 +715,6 @@ PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value);
956715
Use __contains__ if possible, else _PySequence_IterSearch(). */
957716
PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob);
958717

959-
#ifndef Py_LIMITED_API
960-
#define PY_ITERSEARCH_COUNT 1
961-
#define PY_ITERSEARCH_INDEX 2
962-
#define PY_ITERSEARCH_CONTAINS 3
963-
964-
/* Iterate over seq.
965-
966-
Result depends on the operation:
967-
968-
PY_ITERSEARCH_COUNT: return # of times obj appears in seq; -1 if
969-
error.
970-
PY_ITERSEARCH_INDEX: return 0-based index of first occurrence of
971-
obj in seq; set ValueError and return -1 if none found;
972-
also return -1 on error.
973-
PY_ITERSEARCH_CONTAINS: return 1 if obj in seq, else 0; -1 on
974-
error. */
975-
PyAPI_FUNC(Py_ssize_t) _PySequence_IterSearch(PyObject *seq,
976-
PyObject *obj, int operation);
977-
#endif
978-
979-
980718
/* For DLL-level backwards compatibility */
981719
#undef PySequence_In
982720
/* Determine if the sequence 'o' contains 'value'. If an item in 'o' is equal
@@ -1095,26 +833,11 @@ PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass);
1095833
/* issubclass(object, typeorclass) */
1096834
PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass);
1097835

1098-
1099836
#ifndef Py_LIMITED_API
1100-
PyAPI_FUNC(int) _PyObject_RealIsInstance(PyObject *inst, PyObject *cls);
1101-
1102-
PyAPI_FUNC(int) _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls);
1103-
1104-
PyAPI_FUNC(char *const *) _PySequence_BytesToCharpArray(PyObject* self);
1105-
1106-
PyAPI_FUNC(void) _Py_FreeCharPArray(char *const array[]);
1107-
1108-
/* For internal use by buffer API functions */
1109-
PyAPI_FUNC(void) _Py_add_one_to_index_F(int nd, Py_ssize_t *index,
1110-
const Py_ssize_t *shape);
1111-
PyAPI_FUNC(void) _Py_add_one_to_index_C(int nd, Py_ssize_t *index,
1112-
const Py_ssize_t *shape);
1113-
1114-
/* Convert Python int to Py_ssize_t. Do nothing if the argument is None. */
1115-
PyAPI_FUNC(int) _Py_convert_optional_to_ssize_t(PyObject *, void *);
1116-
#endif /* !Py_LIMITED_API */
1117-
837+
# define Py_CPYTHON_ABSTRACTOBJECT_H
838+
# include "cpython/abstract.h"
839+
# undef Py_CPYTHON_ABSTRACTOBJECT_H
840+
#endif
1118841

1119842
#ifdef __cplusplus
1120843
}

0 commit comments

Comments
 (0)