cpython: 654ec6ed3225 (original) (raw)

--- a/Include/abstract.h +++ b/Include/abstract.h @@ -4,14 +4,6 @@ extern "C" { #endif -#ifdef PY_SSIZE_T_CLEAN -# define PyObject_CallFunction _PyObject_CallFunction_SizeT -# define PyObject_CallMethod _PyObject_CallMethod_SizeT -# ifndef Py_LIMITED_API -# define _PyObject_CallMethodId _PyObject_CallMethodId_SizeT -# endif /* !Py_LIMITED_API / -#endif - / Abstract Object Interface (many thanks to Jim Fulton) / / @@ -134,136 +126,139 @@ Protocols /* Implemented elsewhere: -int PyObject_Print(PyObject *o, FILE *fp, int flags);

-Print an object, o, on file, fp. Returns -1 on -error. The flags argument is used to enable certain printing -options. The only option currently supported is Py_Print_RAW.

-(What should be said about Py_Print_RAW?)

-Returns 1 if o has the attribute attr_name, and 0 otherwise. -This is equivalent to the Python expression: -hasattr(o,attr_name).

-This function always succeeds.

-Retrieve an attributed named attr_name form object o. -Returns the attribute value on success, or NULL on failure. -This is the equivalent of the Python expression: o.attr_name.

/* Implemented elsewhere: -int PyObject_HasAttr(PyObject *o, PyObject *attr_name);

-Returns 1 if o has the attribute attr_name, and 0 otherwise. -This is equivalent to the Python expression: -hasattr(o,attr_name).

-This function always succeeds. -

/* Implemented elsewhere: -PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name);

-Retrieve an attributed named attr_name form object o. -Returns the attribute value on success, or NULL on failure. -This is the equivalent of the Python expression: o.attr_name. +/* Implemented elsewhere: +

/* Implemented elsewhere: -int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v);

+/* Implemented as a macro: +

-Set the value of the attribute named attr_name, for object o, -to the value v. Raise an exception and return -1 on failure; return 0 on -success. This is the equivalent of the Python statement o.attr_name=v.

+ +/* Implemented as a macro:

/* Implemented elsewhere: -int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v); - -Set the value of the attribute named attr_name, for object o, -to the value v. Raise an exception and return -1 on failure; return 0 on -success. This is the equivalent of the Python statement o.attr_name=v.

-Delete attribute named attr_name, for object o. Returns --1 on failure. This is the equivalent of the Python -statement: del o.attr_name. -

-int PyObject_DelAttr(PyObject *o, PyObject *attr_name);

-Delete attribute named attr_name, for object o. Returns -1 -on failure. This is the equivalent of the Python -statement: del o.attr_name. -

-Compute the string representation of object, o. Returns the -string representation on success, NULL on failure. This is -the equivalent of the Python expression: repr(o).

-Called by the repr() built-in function.

-Compute the string representation of object, o. Returns the -string representation on success, NULL on failure. This is -the equivalent of the Python expression: str(o).)

-Called by the str() and print() built-in functions.

- #ifndef Py_LIMITED_API PyAPI_FUNC(PyObject*) _PyStack_AsTuple( PyObject stack, @@ -285,9 +279,9 @@ PyAPI_FUNC(PyObject) _PyStack_AsTuple( / Convert keyword arguments from the (stack, kwnames) format to a Python dictionary.

@@ -382,7 +376,7 @@ PyAPI_FUNC(PyObject *) PyObject_CallObje Returns the result of the call on success, or NULL on failure. This is the equivalent of the Python expression:

@@ -394,20 +388,17 @@ PyAPI_FUNC(PyObject *) PyObject_CallFunc Returns the result of the call on success, or NULL on failure. This is the equivalent of the Python expression:

#ifndef Py_LIMITED_API +/* Like PyObject_CallMethod(), but expect a _Py_Identifier*

- -/*

#endif /* !Py_LIMITED_API */ PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable, @@ -433,23 +424,25 @@ PyAPI_FUNC(PyObject *) _PyObject_CallMet Returns the result of the call on success, or NULL on failure. This is the equivalent of the Python expression:

#ifndef Py_LIMITED_API +/* Similar PyObject_CallFunctionObjArgs(), but pass positional arguments

#endif

PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs( PyObject *obj, @@ -466,190 +459,166 @@ PyAPI_FUNC(PyObject ) _PyObject_CallMet / Implemented elsewhere: -long PyObject_Hash(PyObject *o);

-Compute and return the hash, hash_value, of an object, o. On -failure, return -1. This is the equivalent of the Python -expression: hash(o).

/* Implemented elsewhere: -int PyObject_IsTrue(PyObject *o);

-Returns 1 if the object, o, is considered to be true, 0 if o is -considered to be false and -1 on failure. This is equivalent to the -Python expression: not not o

-/* Implemented elsewhere: -int PyObject_Not(PyObject o); +/ Get the type of an object. -Returns 0 if the object, o, is considered to be true, 1 if o is -considered to be false and -1 on failure. This is equivalent to the -Python expression: not o

#undef PyObject_Length PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o); #define PyObject_Length PyObject_Size + #ifndef Py_LIMITED_API PyAPI_FUNC(int) _PyObject_HasLen(PyObject o); + +/ Guess the size of object 'o' using len(o) or o.length_hint().

#endif

+/* FIXME: usage of these should all be replaced in Python itself but for backwards compatibility we will implement them. Their usage without a corresponding "unlock" mechanism may create issues (but they would already be there). / +/ Takes an arbitrary object which must support the (character, single segment)

-0 is returned on success. buffer and buffer_len are only -set in case no error occurs. Otherwise, -1 is returned and -an exception set.

-/ -Checks whether an arbitrary object supports the (character, -single segment) buffer interface. Returns 1 on success, 0 -on failure. -/ +/* Same as PyObject_AsCharBuffer() except that this API expects (readable,

-0 is returned on success. buffer and buffer_len are only -set in case no error occurs. Otherwise, -1 is returned and -an exception set.

#ifndef Py_LIMITED_API + +/* Return 1 if the getbuffer function is available, otherwise return 0. / #define PyObject_CheckBuffer(obj) [](#l1.567) (((obj)->ob_type->tp_as_buffer != NULL) && [](#l1.568) ((obj)->ob_type->tp_as_buffer->bf_getbuffer != NULL)) -/ Return 1 if the getbuffer function is available, otherwise

-/* This is a C-API version of the getbuffer function call. It checks

+/* Get the memory area pointed to by the indices for the buffer given.

-/* Get the memory area pointed to by the indices for the buffer given.

+/* Return the implied itemsize of the data-format area from a

-/* Return the implied itemsize of the data-format area from a

- - /* Implementation in memoryobject.c */ PyAPI_FUNC(int) PyBuffer_ToContiguous(void *buf, Py_buffer *view, Py_ssize_t len, char order); @@ -657,7 +626,6 @@ PyAPI_FUNC(int) PyBuffer_ToContiguous(vo PyAPI_FUNC(int) PyBuffer_FromContiguous(Py_buffer *view, void buf, Py_ssize_t len, char order); - / Copy len bytes of data from the contiguous chunk of memory pointed to by buf into the buffer exported by obj. Return 0 on success and return -1 and raise a PyBuffer_Error on @@ -670,703 +638,537 @@ PyAPI_FUNC(int) PyBuffer_FromContiguous( fort is 'C', then the data will be copied into the array in C-style (last dimension varies the fastest). If fort is 'A', then it does not matter and the copy will be made

-*/ -

-/* Copy the data from the src buffer to the buffer of destination

-/* Fill the strides array with byte-strides of a contiguous

-/ +/ Fills in a buffer-info structure correctly for an exporter

-/* Fills in a buffer-info structure correctly for an exporter

#endif /* Py_LIMITED_API / -PyAPI_FUNC(PyObject ) PyObject_Format(PyObject obj, +/ Takes an arbitrary object and returns the result of calling

#define PyIter_Check(obj) [](#l1.692) ((obj)->ob_type->tp_iternext != NULL && [](#l1.693) (obj)->ob_type->tp_iternext != &_PyObject_NextNotImplemented) +/* Takes an iterator object and calls its tp_iternext slot,

-#define PyIndex_Check(obj) [](#l1.910)

- +/* Returns the object 'o' converted to a Python int, or NULL with an exception

-/* In-place variants of (some of) the above number protocol functions */ -

#undef PySequence_Length

+PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject o); #define PySequence_Length PySequence_Size +/ Return the concatenation of o1 and o2 on success, and NULL on failure. +

#define PySequence_Fast_GET_SIZE(o) [](#l1.1273) (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o))

+/* Return the 'i'-th element of the sequence 'o', assuming that o was returned

#define PySequence_Fast_GET_ITEM(o, i)[](#l1.1282) (PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i))

+/* Assume tp_as_sequence and sq_item exist and that 'i' does not

#define PySequence_ITEM(o, i)[](#l1.1291) ( Py_TYPE(o)->tp_as_sequence->sq_item(o, i) )

+/* Return a pointer to the underlying item array for

#define PySequence_Fast_ITEMS(sf) [](#l1.1299) (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item [](#l1.1300) : ((PyTupleObject )(sf))->ob_item) -/ Return a pointer to the underlying item array for

+/* Return the number of occurrences on value on 'o', that is, return

#ifndef Py_LIMITED_API #define PY_ITERSEARCH_COUNT 1 #define PY_ITERSEARCH_INDEX 2 #define PY_ITERSEARCH_CONTAINS 3 + +/* Iterate over seq. +

PyAPI_FUNC(Py_ssize_t) _PySequence_IterSearch(PyObject *seq, PyObject obj, int operation); #endif -/

-/ + / For DLL-level backwards compatibility / #undef PySequence_In +/ Determine if the sequence 'o' contains 'value'. If an item in 'o' is equal

/* For source-level backwards compatibility */ #define PySequence_In PySequence_Contains

-/* In-place versions of some of the above Sequence functions. */ -

#undef PyMapping_Length PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject o); #define PyMapping_Length PyMapping_Size -/ implemented as a macro: +/* Implemented as a macro: -int PyMapping_DelItemString(PyObject *o, const char *key);

-Remove the mapping for object, key, from the object *o. -Returns -1 on failure. This is equivalent to -the Python statement: del o[key].

#define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K)) -/* implemented as a macro: +/* Implemented as a macro: -int PyMapping_DelItem(PyObject *o, PyObject *key);

-Remove the mapping for object, key, from the object *o. -Returns -1 on failure. This is equivalent to -the Python statement: del o[key].

#define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K)) +/* On success, return 1 if the mapping object 'o' has the key 'key',

- +/* issubclass(object, typeorclass) */ PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass);

#ifndef Py_LIMITED_API