17db96d56Sopenharmony_ci/* Abstract Object Interface (many thanks to Jim Fulton) */ 27db96d56Sopenharmony_ci 37db96d56Sopenharmony_ci#ifndef Py_ABSTRACTOBJECT_H 47db96d56Sopenharmony_ci#define Py_ABSTRACTOBJECT_H 57db96d56Sopenharmony_ci#ifdef __cplusplus 67db96d56Sopenharmony_ciextern "C" { 77db96d56Sopenharmony_ci#endif 87db96d56Sopenharmony_ci 97db96d56Sopenharmony_ci/* === Object Protocol ================================================== */ 107db96d56Sopenharmony_ci 117db96d56Sopenharmony_ci/* Implemented elsewhere: 127db96d56Sopenharmony_ci 137db96d56Sopenharmony_ci int PyObject_Print(PyObject *o, FILE *fp, int flags); 147db96d56Sopenharmony_ci 157db96d56Sopenharmony_ci Print an object 'o' on file 'fp'. Returns -1 on error. The flags argument 167db96d56Sopenharmony_ci is used to enable certain printing options. The only option currently 177db96d56Sopenharmony_ci supported is Py_Print_RAW. 187db96d56Sopenharmony_ci 197db96d56Sopenharmony_ci (What should be said about Py_Print_RAW?). */ 207db96d56Sopenharmony_ci 217db96d56Sopenharmony_ci 227db96d56Sopenharmony_ci/* Implemented elsewhere: 237db96d56Sopenharmony_ci 247db96d56Sopenharmony_ci int PyObject_HasAttrString(PyObject *o, const char *attr_name); 257db96d56Sopenharmony_ci 267db96d56Sopenharmony_ci Returns 1 if object 'o' has the attribute attr_name, and 0 otherwise. 277db96d56Sopenharmony_ci 287db96d56Sopenharmony_ci This is equivalent to the Python expression: hasattr(o,attr_name). 297db96d56Sopenharmony_ci 307db96d56Sopenharmony_ci This function always succeeds. */ 317db96d56Sopenharmony_ci 327db96d56Sopenharmony_ci 337db96d56Sopenharmony_ci/* Implemented elsewhere: 347db96d56Sopenharmony_ci 357db96d56Sopenharmony_ci PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name); 367db96d56Sopenharmony_ci 377db96d56Sopenharmony_ci Retrieve an attributed named attr_name form object o. 387db96d56Sopenharmony_ci Returns the attribute value on success, or NULL on failure. 397db96d56Sopenharmony_ci 407db96d56Sopenharmony_ci This is the equivalent of the Python expression: o.attr_name. */ 417db96d56Sopenharmony_ci 427db96d56Sopenharmony_ci 437db96d56Sopenharmony_ci/* Implemented elsewhere: 447db96d56Sopenharmony_ci 457db96d56Sopenharmony_ci int PyObject_HasAttr(PyObject *o, PyObject *attr_name); 467db96d56Sopenharmony_ci 477db96d56Sopenharmony_ci Returns 1 if o has the attribute attr_name, and 0 otherwise. 487db96d56Sopenharmony_ci 497db96d56Sopenharmony_ci This is equivalent to the Python expression: hasattr(o,attr_name). 507db96d56Sopenharmony_ci 517db96d56Sopenharmony_ci This function always succeeds. */ 527db96d56Sopenharmony_ci 537db96d56Sopenharmony_ci/* Implemented elsewhere: 547db96d56Sopenharmony_ci 557db96d56Sopenharmony_ci PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name); 567db96d56Sopenharmony_ci 577db96d56Sopenharmony_ci Retrieve an attributed named 'attr_name' form object 'o'. 587db96d56Sopenharmony_ci Returns the attribute value on success, or NULL on failure. 597db96d56Sopenharmony_ci 607db96d56Sopenharmony_ci This is the equivalent of the Python expression: o.attr_name. */ 617db96d56Sopenharmony_ci 627db96d56Sopenharmony_ci 637db96d56Sopenharmony_ci/* Implemented elsewhere: 647db96d56Sopenharmony_ci 657db96d56Sopenharmony_ci int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v); 667db96d56Sopenharmony_ci 677db96d56Sopenharmony_ci Set the value of the attribute named attr_name, for object 'o', 687db96d56Sopenharmony_ci to the value 'v'. Raise an exception and return -1 on failure; return 0 on 697db96d56Sopenharmony_ci success. 707db96d56Sopenharmony_ci 717db96d56Sopenharmony_ci This is the equivalent of the Python statement o.attr_name=v. */ 727db96d56Sopenharmony_ci 737db96d56Sopenharmony_ci 747db96d56Sopenharmony_ci/* Implemented elsewhere: 757db96d56Sopenharmony_ci 767db96d56Sopenharmony_ci int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v); 777db96d56Sopenharmony_ci 787db96d56Sopenharmony_ci Set the value of the attribute named attr_name, for object 'o', to the value 797db96d56Sopenharmony_ci 'v'. an exception and return -1 on failure; return 0 on success. 807db96d56Sopenharmony_ci 817db96d56Sopenharmony_ci This is the equivalent of the Python statement o.attr_name=v. */ 827db96d56Sopenharmony_ci 837db96d56Sopenharmony_ci/* Implemented as a macro: 847db96d56Sopenharmony_ci 857db96d56Sopenharmony_ci int PyObject_DelAttrString(PyObject *o, const char *attr_name); 867db96d56Sopenharmony_ci 877db96d56Sopenharmony_ci Delete attribute named attr_name, for object o. Returns 887db96d56Sopenharmony_ci -1 on failure. 897db96d56Sopenharmony_ci 907db96d56Sopenharmony_ci This is the equivalent of the Python statement: del o.attr_name. */ 917db96d56Sopenharmony_ci#define PyObject_DelAttrString(O,A) PyObject_SetAttrString((O),(A), NULL) 927db96d56Sopenharmony_ci 937db96d56Sopenharmony_ci 947db96d56Sopenharmony_ci/* Implemented as a macro: 957db96d56Sopenharmony_ci 967db96d56Sopenharmony_ci int PyObject_DelAttr(PyObject *o, PyObject *attr_name); 977db96d56Sopenharmony_ci 987db96d56Sopenharmony_ci Delete attribute named attr_name, for object o. Returns -1 997db96d56Sopenharmony_ci on failure. This is the equivalent of the Python 1007db96d56Sopenharmony_ci statement: del o.attr_name. */ 1017db96d56Sopenharmony_ci#define PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A), NULL) 1027db96d56Sopenharmony_ci 1037db96d56Sopenharmony_ci 1047db96d56Sopenharmony_ci/* Implemented elsewhere: 1057db96d56Sopenharmony_ci 1067db96d56Sopenharmony_ci PyObject *PyObject_Repr(PyObject *o); 1077db96d56Sopenharmony_ci 1087db96d56Sopenharmony_ci Compute the string representation of object 'o'. Returns the 1097db96d56Sopenharmony_ci string representation on success, NULL on failure. 1107db96d56Sopenharmony_ci 1117db96d56Sopenharmony_ci This is the equivalent of the Python expression: repr(o). 1127db96d56Sopenharmony_ci 1137db96d56Sopenharmony_ci Called by the repr() built-in function. */ 1147db96d56Sopenharmony_ci 1157db96d56Sopenharmony_ci 1167db96d56Sopenharmony_ci/* Implemented elsewhere: 1177db96d56Sopenharmony_ci 1187db96d56Sopenharmony_ci PyObject *PyObject_Str(PyObject *o); 1197db96d56Sopenharmony_ci 1207db96d56Sopenharmony_ci Compute the string representation of object, o. Returns the 1217db96d56Sopenharmony_ci string representation on success, NULL on failure. 1227db96d56Sopenharmony_ci 1237db96d56Sopenharmony_ci This is the equivalent of the Python expression: str(o). 1247db96d56Sopenharmony_ci 1257db96d56Sopenharmony_ci Called by the str() and print() built-in functions. */ 1267db96d56Sopenharmony_ci 1277db96d56Sopenharmony_ci 1287db96d56Sopenharmony_ci/* Declared elsewhere 1297db96d56Sopenharmony_ci 1307db96d56Sopenharmony_ci PyAPI_FUNC(int) PyCallable_Check(PyObject *o); 1317db96d56Sopenharmony_ci 1327db96d56Sopenharmony_ci Determine if the object, o, is callable. Return 1 if the object is callable 1337db96d56Sopenharmony_ci and 0 otherwise. 1347db96d56Sopenharmony_ci 1357db96d56Sopenharmony_ci This function always succeeds. */ 1367db96d56Sopenharmony_ci 1377db96d56Sopenharmony_ci 1387db96d56Sopenharmony_ci#ifdef PY_SSIZE_T_CLEAN 1397db96d56Sopenharmony_ci# define PyObject_CallFunction _PyObject_CallFunction_SizeT 1407db96d56Sopenharmony_ci# define PyObject_CallMethod _PyObject_CallMethod_SizeT 1417db96d56Sopenharmony_ci#endif 1427db96d56Sopenharmony_ci 1437db96d56Sopenharmony_ci 1447db96d56Sopenharmony_ci#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000 1457db96d56Sopenharmony_ci/* Call a callable Python object without any arguments */ 1467db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyObject_CallNoArgs(PyObject *func); 1477db96d56Sopenharmony_ci#endif 1487db96d56Sopenharmony_ci 1497db96d56Sopenharmony_ci 1507db96d56Sopenharmony_ci/* Call a callable Python object 'callable' with arguments given by the 1517db96d56Sopenharmony_ci tuple 'args' and keywords arguments given by the dictionary 'kwargs'. 1527db96d56Sopenharmony_ci 1537db96d56Sopenharmony_ci 'args' must not be NULL, use an empty tuple if no arguments are 1547db96d56Sopenharmony_ci needed. If no named arguments are needed, 'kwargs' can be NULL. 1557db96d56Sopenharmony_ci 1567db96d56Sopenharmony_ci This is the equivalent of the Python expression: 1577db96d56Sopenharmony_ci callable(*args, **kwargs). */ 1587db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable, 1597db96d56Sopenharmony_ci PyObject *args, PyObject *kwargs); 1607db96d56Sopenharmony_ci 1617db96d56Sopenharmony_ci 1627db96d56Sopenharmony_ci/* Call a callable Python object 'callable', with arguments given by the 1637db96d56Sopenharmony_ci tuple 'args'. If no arguments are needed, then 'args' can be NULL. 1647db96d56Sopenharmony_ci 1657db96d56Sopenharmony_ci Returns the result of the call on success, or NULL on failure. 1667db96d56Sopenharmony_ci 1677db96d56Sopenharmony_ci This is the equivalent of the Python expression: 1687db96d56Sopenharmony_ci callable(*args). */ 1697db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable, 1707db96d56Sopenharmony_ci PyObject *args); 1717db96d56Sopenharmony_ci 1727db96d56Sopenharmony_ci/* Call a callable Python object, callable, with a variable number of C 1737db96d56Sopenharmony_ci arguments. The C arguments are described using a mkvalue-style format 1747db96d56Sopenharmony_ci string. 1757db96d56Sopenharmony_ci 1767db96d56Sopenharmony_ci The format may be NULL, indicating that no arguments are provided. 1777db96d56Sopenharmony_ci 1787db96d56Sopenharmony_ci Returns the result of the call on success, or NULL on failure. 1797db96d56Sopenharmony_ci 1807db96d56Sopenharmony_ci This is the equivalent of the Python expression: 1817db96d56Sopenharmony_ci callable(arg1, arg2, ...). */ 1827db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable, 1837db96d56Sopenharmony_ci const char *format, ...); 1847db96d56Sopenharmony_ci 1857db96d56Sopenharmony_ci/* Call the method named 'name' of object 'obj' with a variable number of 1867db96d56Sopenharmony_ci C arguments. The C arguments are described by a mkvalue format string. 1877db96d56Sopenharmony_ci 1887db96d56Sopenharmony_ci The format can be NULL, indicating that no arguments are provided. 1897db96d56Sopenharmony_ci 1907db96d56Sopenharmony_ci Returns the result of the call on success, or NULL on failure. 1917db96d56Sopenharmony_ci 1927db96d56Sopenharmony_ci This is the equivalent of the Python expression: 1937db96d56Sopenharmony_ci obj.name(arg1, arg2, ...). */ 1947db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *obj, 1957db96d56Sopenharmony_ci const char *name, 1967db96d56Sopenharmony_ci const char *format, ...); 1977db96d56Sopenharmony_ci 1987db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable, 1997db96d56Sopenharmony_ci const char *format, 2007db96d56Sopenharmony_ci ...); 2017db96d56Sopenharmony_ci 2027db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *obj, 2037db96d56Sopenharmony_ci const char *name, 2047db96d56Sopenharmony_ci const char *format, 2057db96d56Sopenharmony_ci ...); 2067db96d56Sopenharmony_ci 2077db96d56Sopenharmony_ci/* Call a callable Python object 'callable' with a variable number of C 2087db96d56Sopenharmony_ci arguments. The C arguments are provided as PyObject* values, terminated 2097db96d56Sopenharmony_ci by a NULL. 2107db96d56Sopenharmony_ci 2117db96d56Sopenharmony_ci Returns the result of the call on success, or NULL on failure. 2127db96d56Sopenharmony_ci 2137db96d56Sopenharmony_ci This is the equivalent of the Python expression: 2147db96d56Sopenharmony_ci callable(arg1, arg2, ...). */ 2157db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable, 2167db96d56Sopenharmony_ci ...); 2177db96d56Sopenharmony_ci 2187db96d56Sopenharmony_ci/* Call the method named 'name' of object 'obj' with a variable number of 2197db96d56Sopenharmony_ci C arguments. The C arguments are provided as PyObject* values, terminated 2207db96d56Sopenharmony_ci by NULL. 2217db96d56Sopenharmony_ci 2227db96d56Sopenharmony_ci Returns the result of the call on success, or NULL on failure. 2237db96d56Sopenharmony_ci 2247db96d56Sopenharmony_ci This is the equivalent of the Python expression: obj.name(*args). */ 2257db96d56Sopenharmony_ci 2267db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs( 2277db96d56Sopenharmony_ci PyObject *obj, 2287db96d56Sopenharmony_ci PyObject *name, 2297db96d56Sopenharmony_ci ...); 2307db96d56Sopenharmony_ci 2317db96d56Sopenharmony_ci 2327db96d56Sopenharmony_ci/* Implemented elsewhere: 2337db96d56Sopenharmony_ci 2347db96d56Sopenharmony_ci Py_hash_t PyObject_Hash(PyObject *o); 2357db96d56Sopenharmony_ci 2367db96d56Sopenharmony_ci Compute and return the hash, hash_value, of an object, o. On 2377db96d56Sopenharmony_ci failure, return -1. 2387db96d56Sopenharmony_ci 2397db96d56Sopenharmony_ci This is the equivalent of the Python expression: hash(o). */ 2407db96d56Sopenharmony_ci 2417db96d56Sopenharmony_ci 2427db96d56Sopenharmony_ci/* Implemented elsewhere: 2437db96d56Sopenharmony_ci 2447db96d56Sopenharmony_ci int PyObject_IsTrue(PyObject *o); 2457db96d56Sopenharmony_ci 2467db96d56Sopenharmony_ci Returns 1 if the object, o, is considered to be true, 0 if o is 2477db96d56Sopenharmony_ci considered to be false and -1 on failure. 2487db96d56Sopenharmony_ci 2497db96d56Sopenharmony_ci This is equivalent to the Python expression: not not o. */ 2507db96d56Sopenharmony_ci 2517db96d56Sopenharmony_ci 2527db96d56Sopenharmony_ci/* Implemented elsewhere: 2537db96d56Sopenharmony_ci 2547db96d56Sopenharmony_ci int PyObject_Not(PyObject *o); 2557db96d56Sopenharmony_ci 2567db96d56Sopenharmony_ci Returns 0 if the object, o, is considered to be true, 1 if o is 2577db96d56Sopenharmony_ci considered to be false and -1 on failure. 2587db96d56Sopenharmony_ci 2597db96d56Sopenharmony_ci This is equivalent to the Python expression: not o. */ 2607db96d56Sopenharmony_ci 2617db96d56Sopenharmony_ci 2627db96d56Sopenharmony_ci/* Get the type of an object. 2637db96d56Sopenharmony_ci 2647db96d56Sopenharmony_ci On success, returns a type object corresponding to the object type of object 2657db96d56Sopenharmony_ci 'o'. On failure, returns NULL. 2667db96d56Sopenharmony_ci 2677db96d56Sopenharmony_ci This is equivalent to the Python expression: type(o) */ 2687db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o); 2697db96d56Sopenharmony_ci 2707db96d56Sopenharmony_ci 2717db96d56Sopenharmony_ci/* Return the size of object 'o'. If the object 'o' provides both sequence and 2727db96d56Sopenharmony_ci mapping protocols, the sequence size is returned. 2737db96d56Sopenharmony_ci 2747db96d56Sopenharmony_ci On error, -1 is returned. 2757db96d56Sopenharmony_ci 2767db96d56Sopenharmony_ci This is the equivalent to the Python expression: len(o) */ 2777db96d56Sopenharmony_ciPyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o); 2787db96d56Sopenharmony_ci 2797db96d56Sopenharmony_ci 2807db96d56Sopenharmony_ci/* For DLL compatibility */ 2817db96d56Sopenharmony_ci#undef PyObject_Length 2827db96d56Sopenharmony_ciPyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o); 2837db96d56Sopenharmony_ci#define PyObject_Length PyObject_Size 2847db96d56Sopenharmony_ci 2857db96d56Sopenharmony_ci/* Return element of 'o' corresponding to the object 'key'. Return NULL 2867db96d56Sopenharmony_ci on failure. 2877db96d56Sopenharmony_ci 2887db96d56Sopenharmony_ci This is the equivalent of the Python expression: o[key] */ 2897db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key); 2907db96d56Sopenharmony_ci 2917db96d56Sopenharmony_ci 2927db96d56Sopenharmony_ci/* Map the object 'key' to the value 'v' into 'o'. 2937db96d56Sopenharmony_ci 2947db96d56Sopenharmony_ci Raise an exception and return -1 on failure; return 0 on success. 2957db96d56Sopenharmony_ci 2967db96d56Sopenharmony_ci This is the equivalent of the Python statement: o[key]=v. */ 2977db96d56Sopenharmony_ciPyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v); 2987db96d56Sopenharmony_ci 2997db96d56Sopenharmony_ci/* Remove the mapping for the string 'key' from the object 'o'. 3007db96d56Sopenharmony_ci Returns -1 on failure. 3017db96d56Sopenharmony_ci 3027db96d56Sopenharmony_ci This is equivalent to the Python statement: del o[key]. */ 3037db96d56Sopenharmony_ciPyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, const char *key); 3047db96d56Sopenharmony_ci 3057db96d56Sopenharmony_ci/* Delete the mapping for the object 'key' from the object 'o'. 3067db96d56Sopenharmony_ci Returns -1 on failure. 3077db96d56Sopenharmony_ci 3087db96d56Sopenharmony_ci This is the equivalent of the Python statement: del o[key]. */ 3097db96d56Sopenharmony_ciPyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key); 3107db96d56Sopenharmony_ci 3117db96d56Sopenharmony_ci 3127db96d56Sopenharmony_ci/* === Old Buffer API ============================================ */ 3137db96d56Sopenharmony_ci 3147db96d56Sopenharmony_ci/* FIXME: usage of these should all be replaced in Python itself 3157db96d56Sopenharmony_ci but for backwards compatibility we will implement them. 3167db96d56Sopenharmony_ci Their usage without a corresponding "unlock" mechanism 3177db96d56Sopenharmony_ci may create issues (but they would already be there). */ 3187db96d56Sopenharmony_ci 3197db96d56Sopenharmony_ci/* Takes an arbitrary object which must support the (character, single segment) 3207db96d56Sopenharmony_ci buffer interface and returns a pointer to a read-only memory location 3217db96d56Sopenharmony_ci usable as character based input for subsequent processing. 3227db96d56Sopenharmony_ci 3237db96d56Sopenharmony_ci Return 0 on success. buffer and buffer_len are only set in case no error 3247db96d56Sopenharmony_ci occurs. Otherwise, -1 is returned and an exception set. */ 3257db96d56Sopenharmony_ciPy_DEPRECATED(3.0) 3267db96d56Sopenharmony_ciPyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj, 3277db96d56Sopenharmony_ci const char **buffer, 3287db96d56Sopenharmony_ci Py_ssize_t *buffer_len); 3297db96d56Sopenharmony_ci 3307db96d56Sopenharmony_ci/* Checks whether an arbitrary object supports the (character, single segment) 3317db96d56Sopenharmony_ci buffer interface. 3327db96d56Sopenharmony_ci 3337db96d56Sopenharmony_ci Returns 1 on success, 0 on failure. */ 3347db96d56Sopenharmony_ciPy_DEPRECATED(3.0) PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj); 3357db96d56Sopenharmony_ci 3367db96d56Sopenharmony_ci/* Same as PyObject_AsCharBuffer() except that this API expects (readable, 3377db96d56Sopenharmony_ci single segment) buffer interface and returns a pointer to a read-only memory 3387db96d56Sopenharmony_ci location which can contain arbitrary data. 3397db96d56Sopenharmony_ci 3407db96d56Sopenharmony_ci 0 is returned on success. buffer and buffer_len are only set in case no 3417db96d56Sopenharmony_ci error occurs. Otherwise, -1 is returned and an exception set. */ 3427db96d56Sopenharmony_ciPy_DEPRECATED(3.0) 3437db96d56Sopenharmony_ciPyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj, 3447db96d56Sopenharmony_ci const void **buffer, 3457db96d56Sopenharmony_ci Py_ssize_t *buffer_len); 3467db96d56Sopenharmony_ci 3477db96d56Sopenharmony_ci/* Takes an arbitrary object which must support the (writable, single segment) 3487db96d56Sopenharmony_ci buffer interface and returns a pointer to a writable memory location in 3497db96d56Sopenharmony_ci buffer of size 'buffer_len'. 3507db96d56Sopenharmony_ci 3517db96d56Sopenharmony_ci Return 0 on success. buffer and buffer_len are only set in case no error 3527db96d56Sopenharmony_ci occurs. Otherwise, -1 is returned and an exception set. */ 3537db96d56Sopenharmony_ciPy_DEPRECATED(3.0) 3547db96d56Sopenharmony_ciPyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj, 3557db96d56Sopenharmony_ci void **buffer, 3567db96d56Sopenharmony_ci Py_ssize_t *buffer_len); 3577db96d56Sopenharmony_ci 3587db96d56Sopenharmony_ci 3597db96d56Sopenharmony_ci/* === New Buffer API ============================================ */ 3607db96d56Sopenharmony_ci 3617db96d56Sopenharmony_ci/* Takes an arbitrary object and returns the result of calling 3627db96d56Sopenharmony_ci obj.__format__(format_spec). */ 3637db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyObject_Format(PyObject *obj, 3647db96d56Sopenharmony_ci PyObject *format_spec); 3657db96d56Sopenharmony_ci 3667db96d56Sopenharmony_ci 3677db96d56Sopenharmony_ci/* ==== Iterators ================================================ */ 3687db96d56Sopenharmony_ci 3697db96d56Sopenharmony_ci/* Takes an object and returns an iterator for it. 3707db96d56Sopenharmony_ci This is typically a new iterator but if the argument is an iterator, this 3717db96d56Sopenharmony_ci returns itself. */ 3727db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *); 3737db96d56Sopenharmony_ci 3747db96d56Sopenharmony_ci/* Takes an AsyncIterable object and returns an AsyncIterator for it. 3757db96d56Sopenharmony_ci This is typically a new iterator but if the argument is an AsyncIterator, 3767db96d56Sopenharmony_ci this returns itself. */ 3777db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyObject_GetAIter(PyObject *); 3787db96d56Sopenharmony_ci 3797db96d56Sopenharmony_ci/* Returns non-zero if the object 'obj' provides iterator protocols, and 0 otherwise. 3807db96d56Sopenharmony_ci 3817db96d56Sopenharmony_ci This function always succeeds. */ 3827db96d56Sopenharmony_ciPyAPI_FUNC(int) PyIter_Check(PyObject *); 3837db96d56Sopenharmony_ci 3847db96d56Sopenharmony_ci/* Returns non-zero if the object 'obj' provides AsyncIterator protocols, and 0 otherwise. 3857db96d56Sopenharmony_ci 3867db96d56Sopenharmony_ci This function always succeeds. */ 3877db96d56Sopenharmony_ciPyAPI_FUNC(int) PyAIter_Check(PyObject *); 3887db96d56Sopenharmony_ci 3897db96d56Sopenharmony_ci/* Takes an iterator object and calls its tp_iternext slot, 3907db96d56Sopenharmony_ci returning the next value. 3917db96d56Sopenharmony_ci 3927db96d56Sopenharmony_ci If the iterator is exhausted, this returns NULL without setting an 3937db96d56Sopenharmony_ci exception. 3947db96d56Sopenharmony_ci 3957db96d56Sopenharmony_ci NULL with an exception means an error occurred. */ 3967db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyIter_Next(PyObject *); 3977db96d56Sopenharmony_ci 3987db96d56Sopenharmony_ci#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000 3997db96d56Sopenharmony_ci 4007db96d56Sopenharmony_ci/* Takes generator, coroutine or iterator object and sends the value into it. 4017db96d56Sopenharmony_ci Returns: 4027db96d56Sopenharmony_ci - PYGEN_RETURN (0) if generator has returned. 4037db96d56Sopenharmony_ci 'result' parameter is filled with return value 4047db96d56Sopenharmony_ci - PYGEN_ERROR (-1) if exception was raised. 4057db96d56Sopenharmony_ci 'result' parameter is NULL 4067db96d56Sopenharmony_ci - PYGEN_NEXT (1) if generator has yielded. 4077db96d56Sopenharmony_ci 'result' parameter is filled with yielded value. */ 4087db96d56Sopenharmony_ciPyAPI_FUNC(PySendResult) PyIter_Send(PyObject *, PyObject *, PyObject **); 4097db96d56Sopenharmony_ci#endif 4107db96d56Sopenharmony_ci 4117db96d56Sopenharmony_ci 4127db96d56Sopenharmony_ci/* === Number Protocol ================================================== */ 4137db96d56Sopenharmony_ci 4147db96d56Sopenharmony_ci/* Returns 1 if the object 'o' provides numeric protocols, and 0 otherwise. 4157db96d56Sopenharmony_ci 4167db96d56Sopenharmony_ci This function always succeeds. */ 4177db96d56Sopenharmony_ciPyAPI_FUNC(int) PyNumber_Check(PyObject *o); 4187db96d56Sopenharmony_ci 4197db96d56Sopenharmony_ci/* Returns the result of adding o1 and o2, or NULL on failure. 4207db96d56Sopenharmony_ci 4217db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 + o2. */ 4227db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2); 4237db96d56Sopenharmony_ci 4247db96d56Sopenharmony_ci/* Returns the result of subtracting o2 from o1, or NULL on failure. 4257db96d56Sopenharmony_ci 4267db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 - o2. */ 4277db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2); 4287db96d56Sopenharmony_ci 4297db96d56Sopenharmony_ci/* Returns the result of multiplying o1 and o2, or NULL on failure. 4307db96d56Sopenharmony_ci 4317db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 * o2. */ 4327db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2); 4337db96d56Sopenharmony_ci 4347db96d56Sopenharmony_ci#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 4357db96d56Sopenharmony_ci/* This is the equivalent of the Python expression: o1 @ o2. */ 4367db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2); 4377db96d56Sopenharmony_ci#endif 4387db96d56Sopenharmony_ci 4397db96d56Sopenharmony_ci/* Returns the result of dividing o1 by o2 giving an integral result, 4407db96d56Sopenharmony_ci or NULL on failure. 4417db96d56Sopenharmony_ci 4427db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 // o2. */ 4437db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2); 4447db96d56Sopenharmony_ci 4457db96d56Sopenharmony_ci/* Returns the result of dividing o1 by o2 giving a float result, or NULL on 4467db96d56Sopenharmony_ci failure. 4477db96d56Sopenharmony_ci 4487db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 / o2. */ 4497db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2); 4507db96d56Sopenharmony_ci 4517db96d56Sopenharmony_ci/* Returns the remainder of dividing o1 by o2, or NULL on failure. 4527db96d56Sopenharmony_ci 4537db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 % o2. */ 4547db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2); 4557db96d56Sopenharmony_ci 4567db96d56Sopenharmony_ci/* See the built-in function divmod. 4577db96d56Sopenharmony_ci 4587db96d56Sopenharmony_ci Returns NULL on failure. 4597db96d56Sopenharmony_ci 4607db96d56Sopenharmony_ci This is the equivalent of the Python expression: divmod(o1, o2). */ 4617db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2); 4627db96d56Sopenharmony_ci 4637db96d56Sopenharmony_ci/* See the built-in function pow. Returns NULL on failure. 4647db96d56Sopenharmony_ci 4657db96d56Sopenharmony_ci This is the equivalent of the Python expression: pow(o1, o2, o3), 4667db96d56Sopenharmony_ci where o3 is optional. */ 4677db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2, 4687db96d56Sopenharmony_ci PyObject *o3); 4697db96d56Sopenharmony_ci 4707db96d56Sopenharmony_ci/* Returns the negation of o on success, or NULL on failure. 4717db96d56Sopenharmony_ci 4727db96d56Sopenharmony_ci This is the equivalent of the Python expression: -o. */ 4737db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o); 4747db96d56Sopenharmony_ci 4757db96d56Sopenharmony_ci/* Returns the positive of o on success, or NULL on failure. 4767db96d56Sopenharmony_ci 4777db96d56Sopenharmony_ci This is the equivalent of the Python expression: +o. */ 4787db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o); 4797db96d56Sopenharmony_ci 4807db96d56Sopenharmony_ci/* Returns the absolute value of 'o', or NULL on failure. 4817db96d56Sopenharmony_ci 4827db96d56Sopenharmony_ci This is the equivalent of the Python expression: abs(o). */ 4837db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o); 4847db96d56Sopenharmony_ci 4857db96d56Sopenharmony_ci/* Returns the bitwise negation of 'o' on success, or NULL on failure. 4867db96d56Sopenharmony_ci 4877db96d56Sopenharmony_ci This is the equivalent of the Python expression: ~o. */ 4887db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o); 4897db96d56Sopenharmony_ci 4907db96d56Sopenharmony_ci/* Returns the result of left shifting o1 by o2 on success, or NULL on failure. 4917db96d56Sopenharmony_ci 4927db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 << o2. */ 4937db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2); 4947db96d56Sopenharmony_ci 4957db96d56Sopenharmony_ci/* Returns the result of right shifting o1 by o2 on success, or NULL on 4967db96d56Sopenharmony_ci failure. 4977db96d56Sopenharmony_ci 4987db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 >> o2. */ 4997db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2); 5007db96d56Sopenharmony_ci 5017db96d56Sopenharmony_ci/* Returns the result of bitwise and of o1 and o2 on success, or NULL on 5027db96d56Sopenharmony_ci failure. 5037db96d56Sopenharmony_ci 5047db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 & o2. */ 5057db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2); 5067db96d56Sopenharmony_ci 5077db96d56Sopenharmony_ci/* Returns the bitwise exclusive or of o1 by o2 on success, or NULL on failure. 5087db96d56Sopenharmony_ci 5097db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 ^ o2. */ 5107db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2); 5117db96d56Sopenharmony_ci 5127db96d56Sopenharmony_ci/* Returns the result of bitwise or on o1 and o2 on success, or NULL on 5137db96d56Sopenharmony_ci failure. 5147db96d56Sopenharmony_ci 5157db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 | o2. */ 5167db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2); 5177db96d56Sopenharmony_ci 5187db96d56Sopenharmony_ci/* Returns 1 if obj is an index integer (has the nb_index slot of the 5197db96d56Sopenharmony_ci tp_as_number structure filled in), and 0 otherwise. */ 5207db96d56Sopenharmony_ciPyAPI_FUNC(int) PyIndex_Check(PyObject *); 5217db96d56Sopenharmony_ci 5227db96d56Sopenharmony_ci/* Returns the object 'o' converted to a Python int, or NULL with an exception 5237db96d56Sopenharmony_ci raised on failure. */ 5247db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o); 5257db96d56Sopenharmony_ci 5267db96d56Sopenharmony_ci/* Returns the object 'o' converted to Py_ssize_t by going through 5277db96d56Sopenharmony_ci PyNumber_Index() first. 5287db96d56Sopenharmony_ci 5297db96d56Sopenharmony_ci If an overflow error occurs while converting the int to Py_ssize_t, then the 5307db96d56Sopenharmony_ci second argument 'exc' is the error-type to return. If it is NULL, then the 5317db96d56Sopenharmony_ci overflow error is cleared and the value is clipped. */ 5327db96d56Sopenharmony_ciPyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc); 5337db96d56Sopenharmony_ci 5347db96d56Sopenharmony_ci/* Returns the object 'o' converted to an integer object on success, or NULL 5357db96d56Sopenharmony_ci on failure. 5367db96d56Sopenharmony_ci 5377db96d56Sopenharmony_ci This is the equivalent of the Python expression: int(o). */ 5387db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o); 5397db96d56Sopenharmony_ci 5407db96d56Sopenharmony_ci/* Returns the object 'o' converted to a float object on success, or NULL 5417db96d56Sopenharmony_ci on failure. 5427db96d56Sopenharmony_ci 5437db96d56Sopenharmony_ci This is the equivalent of the Python expression: float(o). */ 5447db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o); 5457db96d56Sopenharmony_ci 5467db96d56Sopenharmony_ci 5477db96d56Sopenharmony_ci/* --- In-place variants of (some of) the above number protocol functions -- */ 5487db96d56Sopenharmony_ci 5497db96d56Sopenharmony_ci/* Returns the result of adding o2 to o1, possibly in-place, or NULL 5507db96d56Sopenharmony_ci on failure. 5517db96d56Sopenharmony_ci 5527db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 += o2. */ 5537db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2); 5547db96d56Sopenharmony_ci 5557db96d56Sopenharmony_ci/* Returns the result of subtracting o2 from o1, possibly in-place or 5567db96d56Sopenharmony_ci NULL on failure. 5577db96d56Sopenharmony_ci 5587db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 -= o2. */ 5597db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2); 5607db96d56Sopenharmony_ci 5617db96d56Sopenharmony_ci/* Returns the result of multiplying o1 by o2, possibly in-place, or NULL on 5627db96d56Sopenharmony_ci failure. 5637db96d56Sopenharmony_ci 5647db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 *= o2. */ 5657db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2); 5667db96d56Sopenharmony_ci 5677db96d56Sopenharmony_ci#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 5687db96d56Sopenharmony_ci/* This is the equivalent of the Python expression: o1 @= o2. */ 5697db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2); 5707db96d56Sopenharmony_ci#endif 5717db96d56Sopenharmony_ci 5727db96d56Sopenharmony_ci/* Returns the result of dividing o1 by o2 giving an integral result, possibly 5737db96d56Sopenharmony_ci in-place, or NULL on failure. 5747db96d56Sopenharmony_ci 5757db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 /= o2. */ 5767db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1, 5777db96d56Sopenharmony_ci PyObject *o2); 5787db96d56Sopenharmony_ci 5797db96d56Sopenharmony_ci/* Returns the result of dividing o1 by o2 giving a float result, possibly 5807db96d56Sopenharmony_ci in-place, or null on failure. 5817db96d56Sopenharmony_ci 5827db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 /= o2. */ 5837db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1, 5847db96d56Sopenharmony_ci PyObject *o2); 5857db96d56Sopenharmony_ci 5867db96d56Sopenharmony_ci/* Returns the remainder of dividing o1 by o2, possibly in-place, or NULL on 5877db96d56Sopenharmony_ci failure. 5887db96d56Sopenharmony_ci 5897db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 %= o2. */ 5907db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2); 5917db96d56Sopenharmony_ci 5927db96d56Sopenharmony_ci/* Returns the result of raising o1 to the power of o2, possibly in-place, 5937db96d56Sopenharmony_ci or NULL on failure. 5947db96d56Sopenharmony_ci 5957db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 **= o2, 5967db96d56Sopenharmony_ci or o1 = pow(o1, o2, o3) if o3 is present. */ 5977db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2, 5987db96d56Sopenharmony_ci PyObject *o3); 5997db96d56Sopenharmony_ci 6007db96d56Sopenharmony_ci/* Returns the result of left shifting o1 by o2, possibly in-place, or NULL 6017db96d56Sopenharmony_ci on failure. 6027db96d56Sopenharmony_ci 6037db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 <<= o2. */ 6047db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2); 6057db96d56Sopenharmony_ci 6067db96d56Sopenharmony_ci/* Returns the result of right shifting o1 by o2, possibly in-place or NULL 6077db96d56Sopenharmony_ci on failure. 6087db96d56Sopenharmony_ci 6097db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 >>= o2. */ 6107db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2); 6117db96d56Sopenharmony_ci 6127db96d56Sopenharmony_ci/* Returns the result of bitwise and of o1 and o2, possibly in-place, or NULL 6137db96d56Sopenharmony_ci on failure. 6147db96d56Sopenharmony_ci 6157db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 &= o2. */ 6167db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2); 6177db96d56Sopenharmony_ci 6187db96d56Sopenharmony_ci/* Returns the bitwise exclusive or of o1 by o2, possibly in-place, or NULL 6197db96d56Sopenharmony_ci on failure. 6207db96d56Sopenharmony_ci 6217db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 ^= o2. */ 6227db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2); 6237db96d56Sopenharmony_ci 6247db96d56Sopenharmony_ci/* Returns the result of bitwise or of o1 and o2, possibly in-place, 6257db96d56Sopenharmony_ci or NULL on failure. 6267db96d56Sopenharmony_ci 6277db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 |= o2. */ 6287db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2); 6297db96d56Sopenharmony_ci 6307db96d56Sopenharmony_ci/* Returns the integer n converted to a string with a base, with a base 6317db96d56Sopenharmony_ci marker of 0b, 0o or 0x prefixed if applicable. 6327db96d56Sopenharmony_ci 6337db96d56Sopenharmony_ci If n is not an int object, it is converted with PyNumber_Index first. */ 6347db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base); 6357db96d56Sopenharmony_ci 6367db96d56Sopenharmony_ci 6377db96d56Sopenharmony_ci/* === Sequence protocol ================================================ */ 6387db96d56Sopenharmony_ci 6397db96d56Sopenharmony_ci/* Return 1 if the object provides sequence protocol, and zero 6407db96d56Sopenharmony_ci otherwise. 6417db96d56Sopenharmony_ci 6427db96d56Sopenharmony_ci This function always succeeds. */ 6437db96d56Sopenharmony_ciPyAPI_FUNC(int) PySequence_Check(PyObject *o); 6447db96d56Sopenharmony_ci 6457db96d56Sopenharmony_ci/* Return the size of sequence object o, or -1 on failure. */ 6467db96d56Sopenharmony_ciPyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o); 6477db96d56Sopenharmony_ci 6487db96d56Sopenharmony_ci/* For DLL compatibility */ 6497db96d56Sopenharmony_ci#undef PySequence_Length 6507db96d56Sopenharmony_ciPyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o); 6517db96d56Sopenharmony_ci#define PySequence_Length PySequence_Size 6527db96d56Sopenharmony_ci 6537db96d56Sopenharmony_ci 6547db96d56Sopenharmony_ci/* Return the concatenation of o1 and o2 on success, and NULL on failure. 6557db96d56Sopenharmony_ci 6567db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 + o2. */ 6577db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2); 6587db96d56Sopenharmony_ci 6597db96d56Sopenharmony_ci/* Return the result of repeating sequence object 'o' 'count' times, 6607db96d56Sopenharmony_ci or NULL on failure. 6617db96d56Sopenharmony_ci 6627db96d56Sopenharmony_ci This is the equivalent of the Python expression: o * count. */ 6637db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count); 6647db96d56Sopenharmony_ci 6657db96d56Sopenharmony_ci/* Return the ith element of o, or NULL on failure. 6667db96d56Sopenharmony_ci 6677db96d56Sopenharmony_ci This is the equivalent of the Python expression: o[i]. */ 6687db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i); 6697db96d56Sopenharmony_ci 6707db96d56Sopenharmony_ci/* Return the slice of sequence object o between i1 and i2, or NULL on failure. 6717db96d56Sopenharmony_ci 6727db96d56Sopenharmony_ci This is the equivalent of the Python expression: o[i1:i2]. */ 6737db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); 6747db96d56Sopenharmony_ci 6757db96d56Sopenharmony_ci/* Assign object 'v' to the ith element of the sequence 'o'. Raise an exception 6767db96d56Sopenharmony_ci and return -1 on failure; return 0 on success. 6777db96d56Sopenharmony_ci 6787db96d56Sopenharmony_ci This is the equivalent of the Python statement o[i] = v. */ 6797db96d56Sopenharmony_ciPyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v); 6807db96d56Sopenharmony_ci 6817db96d56Sopenharmony_ci/* Delete the 'i'-th element of the sequence 'v'. Returns -1 on failure. 6827db96d56Sopenharmony_ci 6837db96d56Sopenharmony_ci This is the equivalent of the Python statement: del o[i]. */ 6847db96d56Sopenharmony_ciPyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i); 6857db96d56Sopenharmony_ci 6867db96d56Sopenharmony_ci/* Assign the sequence object 'v' to the slice in sequence object 'o', 6877db96d56Sopenharmony_ci from 'i1' to 'i2'. Returns -1 on failure. 6887db96d56Sopenharmony_ci 6897db96d56Sopenharmony_ci This is the equivalent of the Python statement: o[i1:i2] = v. */ 6907db96d56Sopenharmony_ciPyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, 6917db96d56Sopenharmony_ci PyObject *v); 6927db96d56Sopenharmony_ci 6937db96d56Sopenharmony_ci/* Delete the slice in sequence object 'o' from 'i1' to 'i2'. 6947db96d56Sopenharmony_ci Returns -1 on failure. 6957db96d56Sopenharmony_ci 6967db96d56Sopenharmony_ci This is the equivalent of the Python statement: del o[i1:i2]. */ 6977db96d56Sopenharmony_ciPyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); 6987db96d56Sopenharmony_ci 6997db96d56Sopenharmony_ci/* Returns the sequence 'o' as a tuple on success, and NULL on failure. 7007db96d56Sopenharmony_ci 7017db96d56Sopenharmony_ci This is equivalent to the Python expression: tuple(o). */ 7027db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o); 7037db96d56Sopenharmony_ci 7047db96d56Sopenharmony_ci/* Returns the sequence 'o' as a list on success, and NULL on failure. 7057db96d56Sopenharmony_ci This is equivalent to the Python expression: list(o) */ 7067db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PySequence_List(PyObject *o); 7077db96d56Sopenharmony_ci 7087db96d56Sopenharmony_ci/* Return the sequence 'o' as a list, unless it's already a tuple or list. 7097db96d56Sopenharmony_ci 7107db96d56Sopenharmony_ci Use PySequence_Fast_GET_ITEM to access the members of this list, and 7117db96d56Sopenharmony_ci PySequence_Fast_GET_SIZE to get its length. 7127db96d56Sopenharmony_ci 7137db96d56Sopenharmony_ci Returns NULL on failure. If the object does not support iteration, raises a 7147db96d56Sopenharmony_ci TypeError exception with 'm' as the message text. */ 7157db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m); 7167db96d56Sopenharmony_ci 7177db96d56Sopenharmony_ci/* Return the size of the sequence 'o', assuming that 'o' was returned by 7187db96d56Sopenharmony_ci PySequence_Fast and is not NULL. */ 7197db96d56Sopenharmony_ci#define PySequence_Fast_GET_SIZE(o) \ 7207db96d56Sopenharmony_ci (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o)) 7217db96d56Sopenharmony_ci 7227db96d56Sopenharmony_ci/* Return the 'i'-th element of the sequence 'o', assuming that o was returned 7237db96d56Sopenharmony_ci by PySequence_Fast, and that i is within bounds. */ 7247db96d56Sopenharmony_ci#define PySequence_Fast_GET_ITEM(o, i)\ 7257db96d56Sopenharmony_ci (PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i)) 7267db96d56Sopenharmony_ci 7277db96d56Sopenharmony_ci/* Return a pointer to the underlying item array for 7287db96d56Sopenharmony_ci an object returned by PySequence_Fast */ 7297db96d56Sopenharmony_ci#define PySequence_Fast_ITEMS(sf) \ 7307db96d56Sopenharmony_ci (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \ 7317db96d56Sopenharmony_ci : ((PyTupleObject *)(sf))->ob_item) 7327db96d56Sopenharmony_ci 7337db96d56Sopenharmony_ci/* Return the number of occurrences on value on 'o', that is, return 7347db96d56Sopenharmony_ci the number of keys for which o[key] == value. 7357db96d56Sopenharmony_ci 7367db96d56Sopenharmony_ci On failure, return -1. This is equivalent to the Python expression: 7377db96d56Sopenharmony_ci o.count(value). */ 7387db96d56Sopenharmony_ciPyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value); 7397db96d56Sopenharmony_ci 7407db96d56Sopenharmony_ci/* Return 1 if 'ob' is in the sequence 'seq'; 0 if 'ob' is not in the sequence 7417db96d56Sopenharmony_ci 'seq'; -1 on error. 7427db96d56Sopenharmony_ci 7437db96d56Sopenharmony_ci Use __contains__ if possible, else _PySequence_IterSearch(). */ 7447db96d56Sopenharmony_ciPyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob); 7457db96d56Sopenharmony_ci 7467db96d56Sopenharmony_ci/* For DLL-level backwards compatibility */ 7477db96d56Sopenharmony_ci#undef PySequence_In 7487db96d56Sopenharmony_ci/* Determine if the sequence 'o' contains 'value'. If an item in 'o' is equal 7497db96d56Sopenharmony_ci to 'value', return 1, otherwise return 0. On error, return -1. 7507db96d56Sopenharmony_ci 7517db96d56Sopenharmony_ci This is equivalent to the Python expression: value in o. */ 7527db96d56Sopenharmony_ciPyAPI_FUNC(int) PySequence_In(PyObject *o, PyObject *value); 7537db96d56Sopenharmony_ci 7547db96d56Sopenharmony_ci/* For source-level backwards compatibility */ 7557db96d56Sopenharmony_ci#define PySequence_In PySequence_Contains 7567db96d56Sopenharmony_ci 7577db96d56Sopenharmony_ci 7587db96d56Sopenharmony_ci/* Return the first index for which o[i] == value. 7597db96d56Sopenharmony_ci On error, return -1. 7607db96d56Sopenharmony_ci 7617db96d56Sopenharmony_ci This is equivalent to the Python expression: o.index(value). */ 7627db96d56Sopenharmony_ciPyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value); 7637db96d56Sopenharmony_ci 7647db96d56Sopenharmony_ci 7657db96d56Sopenharmony_ci/* --- In-place versions of some of the above Sequence functions --- */ 7667db96d56Sopenharmony_ci 7677db96d56Sopenharmony_ci/* Append sequence 'o2' to sequence 'o1', in-place when possible. Return the 7687db96d56Sopenharmony_ci resulting object, which could be 'o1', or NULL on failure. 7697db96d56Sopenharmony_ci 7707db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 += o2. */ 7717db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2); 7727db96d56Sopenharmony_ci 7737db96d56Sopenharmony_ci/* Repeat sequence 'o' by 'count', in-place when possible. Return the resulting 7747db96d56Sopenharmony_ci object, which could be 'o', or NULL on failure. 7757db96d56Sopenharmony_ci 7767db96d56Sopenharmony_ci This is the equivalent of the Python expression: o1 *= count. */ 7777db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count); 7787db96d56Sopenharmony_ci 7797db96d56Sopenharmony_ci 7807db96d56Sopenharmony_ci/* === Mapping protocol ================================================= */ 7817db96d56Sopenharmony_ci 7827db96d56Sopenharmony_ci/* Return 1 if the object provides mapping protocol, and 0 otherwise. 7837db96d56Sopenharmony_ci 7847db96d56Sopenharmony_ci This function always succeeds. */ 7857db96d56Sopenharmony_ciPyAPI_FUNC(int) PyMapping_Check(PyObject *o); 7867db96d56Sopenharmony_ci 7877db96d56Sopenharmony_ci/* Returns the number of keys in mapping object 'o' on success, and -1 on 7887db96d56Sopenharmony_ci failure. This is equivalent to the Python expression: len(o). */ 7897db96d56Sopenharmony_ciPyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o); 7907db96d56Sopenharmony_ci 7917db96d56Sopenharmony_ci/* For DLL compatibility */ 7927db96d56Sopenharmony_ci#undef PyMapping_Length 7937db96d56Sopenharmony_ciPyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o); 7947db96d56Sopenharmony_ci#define PyMapping_Length PyMapping_Size 7957db96d56Sopenharmony_ci 7967db96d56Sopenharmony_ci 7977db96d56Sopenharmony_ci/* Implemented as a macro: 7987db96d56Sopenharmony_ci 7997db96d56Sopenharmony_ci int PyMapping_DelItemString(PyObject *o, const char *key); 8007db96d56Sopenharmony_ci 8017db96d56Sopenharmony_ci Remove the mapping for the string 'key' from the mapping 'o'. Returns -1 on 8027db96d56Sopenharmony_ci failure. 8037db96d56Sopenharmony_ci 8047db96d56Sopenharmony_ci This is equivalent to the Python statement: del o[key]. */ 8057db96d56Sopenharmony_ci#define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K)) 8067db96d56Sopenharmony_ci 8077db96d56Sopenharmony_ci/* Implemented as a macro: 8087db96d56Sopenharmony_ci 8097db96d56Sopenharmony_ci int PyMapping_DelItem(PyObject *o, PyObject *key); 8107db96d56Sopenharmony_ci 8117db96d56Sopenharmony_ci Remove the mapping for the object 'key' from the mapping object 'o'. 8127db96d56Sopenharmony_ci Returns -1 on failure. 8137db96d56Sopenharmony_ci 8147db96d56Sopenharmony_ci This is equivalent to the Python statement: del o[key]. */ 8157db96d56Sopenharmony_ci#define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K)) 8167db96d56Sopenharmony_ci 8177db96d56Sopenharmony_ci/* On success, return 1 if the mapping object 'o' has the key 'key', 8187db96d56Sopenharmony_ci and 0 otherwise. 8197db96d56Sopenharmony_ci 8207db96d56Sopenharmony_ci This is equivalent to the Python expression: key in o. 8217db96d56Sopenharmony_ci 8227db96d56Sopenharmony_ci This function always succeeds. */ 8237db96d56Sopenharmony_ciPyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, const char *key); 8247db96d56Sopenharmony_ci 8257db96d56Sopenharmony_ci/* Return 1 if the mapping object has the key 'key', and 0 otherwise. 8267db96d56Sopenharmony_ci 8277db96d56Sopenharmony_ci This is equivalent to the Python expression: key in o. 8287db96d56Sopenharmony_ci 8297db96d56Sopenharmony_ci This function always succeeds. */ 8307db96d56Sopenharmony_ciPyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key); 8317db96d56Sopenharmony_ci 8327db96d56Sopenharmony_ci/* On success, return a list or tuple of the keys in mapping object 'o'. 8337db96d56Sopenharmony_ci On failure, return NULL. */ 8347db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyMapping_Keys(PyObject *o); 8357db96d56Sopenharmony_ci 8367db96d56Sopenharmony_ci/* On success, return a list or tuple of the values in mapping object 'o'. 8377db96d56Sopenharmony_ci On failure, return NULL. */ 8387db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyMapping_Values(PyObject *o); 8397db96d56Sopenharmony_ci 8407db96d56Sopenharmony_ci/* On success, return a list or tuple of the items in mapping object 'o', 8417db96d56Sopenharmony_ci where each item is a tuple containing a key-value pair. On failure, return 8427db96d56Sopenharmony_ci NULL. */ 8437db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyMapping_Items(PyObject *o); 8447db96d56Sopenharmony_ci 8457db96d56Sopenharmony_ci/* Return element of 'o' corresponding to the string 'key' or NULL on failure. 8467db96d56Sopenharmony_ci 8477db96d56Sopenharmony_ci This is the equivalent of the Python expression: o[key]. */ 8487db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o, 8497db96d56Sopenharmony_ci const char *key); 8507db96d56Sopenharmony_ci 8517db96d56Sopenharmony_ci/* Map the string 'key' to the value 'v' in the mapping 'o'. 8527db96d56Sopenharmony_ci Returns -1 on failure. 8537db96d56Sopenharmony_ci 8547db96d56Sopenharmony_ci This is the equivalent of the Python statement: o[key]=v. */ 8557db96d56Sopenharmony_ciPyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, const char *key, 8567db96d56Sopenharmony_ci PyObject *value); 8577db96d56Sopenharmony_ci 8587db96d56Sopenharmony_ci/* isinstance(object, typeorclass) */ 8597db96d56Sopenharmony_ciPyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass); 8607db96d56Sopenharmony_ci 8617db96d56Sopenharmony_ci/* issubclass(object, typeorclass) */ 8627db96d56Sopenharmony_ciPyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass); 8637db96d56Sopenharmony_ci 8647db96d56Sopenharmony_ci#ifndef Py_LIMITED_API 8657db96d56Sopenharmony_ci# define Py_CPYTHON_ABSTRACTOBJECT_H 8667db96d56Sopenharmony_ci# include "cpython/abstract.h" 8677db96d56Sopenharmony_ci# undef Py_CPYTHON_ABSTRACTOBJECT_H 8687db96d56Sopenharmony_ci#endif 8697db96d56Sopenharmony_ci 8707db96d56Sopenharmony_ci#ifdef __cplusplus 8717db96d56Sopenharmony_ci} 8727db96d56Sopenharmony_ci#endif 8737db96d56Sopenharmony_ci#endif /* Py_ABSTRACTOBJECT_H */ 874