/* Abstract Object Interface (many thanks to Jim Fulton) */12#ifndef Py_ABSTRACTOBJECT_H3#define Py_ABSTRACTOBJECT_H4#ifdef __cplusplus5extern "C" {6#endif78/* === Object Protocol ================================================== */910/* Implemented elsewhere:1112int PyObject_Print(PyObject *o, FILE *fp, int flags);1314Print an object 'o' on file 'fp'. Returns -1 on error. The flags argument15is used to enable certain printing options. The only option currently16supported is Py_PRINT_RAW. By default (flags=0), PyObject_Print() formats17the object by calling PyObject_Repr(). If flags equals to Py_PRINT_RAW, it18formats the object by calling PyObject_Str(). */192021/* Implemented elsewhere:2223int PyObject_HasAttrString(PyObject *o, const char *attr_name);2425Returns 1 if object 'o' has the attribute attr_name, and 0 otherwise.2627This is equivalent to the Python expression: hasattr(o,attr_name).2829This function always succeeds. */303132/* Implemented elsewhere:3334PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name);3536Retrieve an attributed named attr_name form object o.37Returns the attribute value on success, or NULL on failure.3839This is the equivalent of the Python expression: o.attr_name. */404142/* Implemented elsewhere:4344int PyObject_HasAttr(PyObject *o, PyObject *attr_name);4546Returns 1 if o has the attribute attr_name, and 0 otherwise.4748This is equivalent to the Python expression: hasattr(o,attr_name).4950This function always succeeds. */5152/* Implemented elsewhere:5354PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name);5556Retrieve an attributed named 'attr_name' form object 'o'.57Returns the attribute value on success, or NULL on failure.5859This is the equivalent of the Python expression: o.attr_name. */606162/* Implemented elsewhere:6364int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v);6566Set the value of the attribute named attr_name, for object 'o',67to the value 'v'. Raise an exception and return -1 on failure; return 0 on68success.6970This is the equivalent of the Python statement o.attr_name=v. */717273/* Implemented elsewhere:7475int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v);7677Set the value of the attribute named attr_name, for object 'o', to the value78'v'. an exception and return -1 on failure; return 0 on success.7980This is the equivalent of the Python statement o.attr_name=v. */8182/* Implemented as a macro:8384int PyObject_DelAttrString(PyObject *o, const char *attr_name);8586Delete attribute named attr_name, for object o. Returns87-1 on failure.8889This is the equivalent of the Python statement: del o.attr_name. */90#define PyObject_DelAttrString(O, A) PyObject_SetAttrString((O), (A), NULL)919293/* Implemented as a macro:9495int PyObject_DelAttr(PyObject *o, PyObject *attr_name);9697Delete attribute named attr_name, for object o. Returns -198on failure. This is the equivalent of the Python99statement: del o.attr_name. */100#define PyObject_DelAttr(O, A) PyObject_SetAttr((O), (A), NULL)101102103/* Implemented elsewhere:104105PyObject *PyObject_Repr(PyObject *o);106107Compute the string representation of object 'o'. Returns the108string representation on success, NULL on failure.109110This is the equivalent of the Python expression: repr(o).111112Called by the repr() built-in function. */113114115/* Implemented elsewhere:116117PyObject *PyObject_Str(PyObject *o);118119Compute the string representation of object, o. Returns the120string representation on success, NULL on failure.121122This is the equivalent of the Python expression: str(o).123124Called by the str() and print() built-in functions. */125126127/* Declared elsewhere128129PyAPI_FUNC(int) PyCallable_Check(PyObject *o);130131Determine if the object, o, is callable. Return 1 if the object is callable132and 0 otherwise.133134This function always succeeds. */135136137#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000138/* Call a callable Python object without any arguments */139PyAPI_FUNC(PyObject *) PyObject_CallNoArgs(PyObject *func);140#endif141142143/* Call a callable Python object 'callable' with arguments given by the144tuple 'args' and keywords arguments given by the dictionary 'kwargs'.145146'args' must not be NULL, use an empty tuple if no arguments are147needed. If no named arguments are needed, 'kwargs' can be NULL.148149This is the equivalent of the Python expression:150callable(*args, **kwargs). */151PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable,152PyObject *args, PyObject *kwargs);153154155/* Call a callable Python object 'callable', with arguments given by the156tuple 'args'. If no arguments are needed, then 'args' can be NULL.157158Returns the result of the call on success, or NULL on failure.159160This is the equivalent of the Python expression:161callable(*args). */162PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable,163PyObject *args);164165/* Call a callable Python object, callable, with a variable number of C166arguments. The C arguments are described using a mkvalue-style format167string.168169The format may be NULL, indicating that no arguments are provided.170171Returns the result of the call on success, or NULL on failure.172173This is the equivalent of the Python expression:174callable(arg1, arg2, ...). */175PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable,176const char *format, ...);177178/* Call the method named 'name' of object 'obj' with a variable number of179C arguments. The C arguments are described by a mkvalue format string.180181The format can be NULL, indicating that no arguments are provided.182183Returns the result of the call on success, or NULL on failure.184185This is the equivalent of the Python expression:186obj.name(arg1, arg2, ...). */187PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *obj,188const char *name,189const char *format, ...);190191/* Call a callable Python object 'callable' with a variable number of C192arguments. The C arguments are provided as PyObject* values, terminated193by a NULL.194195Returns the result of the call on success, or NULL on failure.196197This is the equivalent of the Python expression:198callable(arg1, arg2, ...). */199PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable,200...);201202/* Call the method named 'name' of object 'obj' with a variable number of203C arguments. The C arguments are provided as PyObject* values, terminated204by NULL.205206Returns the result of the call on success, or NULL on failure.207208This is the equivalent of the Python expression: obj.name(*args). */209210PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs(211PyObject *obj,212PyObject *name,213...);214215/* Given a vectorcall nargsf argument, return the actual number of arguments.216* (For use outside the limited API, this is re-defined as a static inline217* function in cpython/abstract.h)218*/219PyAPI_FUNC(Py_ssize_t) PyVectorcall_NARGS(size_t nargsf);220221/* Call "callable" (which must support vectorcall) with positional arguments222"tuple" and keyword arguments "dict". "dict" may also be NULL */223PyAPI_FUNC(PyObject *) PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *dict);224225#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030C0000226#define PY_VECTORCALL_ARGUMENTS_OFFSET \227(_Py_STATIC_CAST(size_t, 1) << (8 * sizeof(size_t) - 1))228229/* Perform a PEP 590-style vector call on 'callable' */230PyAPI_FUNC(PyObject *) PyObject_Vectorcall(231PyObject *callable,232PyObject *const *args,233size_t nargsf,234PyObject *kwnames);235236/* Call the method 'name' on args[0] with arguments in args[1..nargsf-1]. */237PyAPI_FUNC(PyObject *) PyObject_VectorcallMethod(238PyObject *name, PyObject *const *args,239size_t nargsf, PyObject *kwnames);240#endif241242/* Implemented elsewhere:243244Py_hash_t PyObject_Hash(PyObject *o);245246Compute and return the hash, hash_value, of an object, o. On247failure, return -1.248249This is the equivalent of the Python expression: hash(o). */250251252/* Implemented elsewhere:253254int PyObject_IsTrue(PyObject *o);255256Returns 1 if the object, o, is considered to be true, 0 if o is257considered to be false and -1 on failure.258259This is equivalent to the Python expression: not not o. */260261262/* Implemented elsewhere:263264int PyObject_Not(PyObject *o);265266Returns 0 if the object, o, is considered to be true, 1 if o is267considered to be false and -1 on failure.268269This is equivalent to the Python expression: not o. */270271272/* Get the type of an object.273274On success, returns a type object corresponding to the object type of object275'o'. On failure, returns NULL.276277This is equivalent to the Python expression: type(o) */278PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o);279280281/* Return the size of object 'o'. If the object 'o' provides both sequence and282mapping protocols, the sequence size is returned.283284On error, -1 is returned.285286This is the equivalent to the Python expression: len(o) */287PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o);288289290/* For DLL compatibility */291#undef PyObject_Length292PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o);293#define PyObject_Length PyObject_Size294295/* Return element of 'o' corresponding to the object 'key'. Return NULL296on failure.297298This is the equivalent of the Python expression: o[key] */299PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key);300301302/* Map the object 'key' to the value 'v' into 'o'.303304Raise an exception and return -1 on failure; return 0 on success.305306This is the equivalent of the Python statement: o[key]=v. */307PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v);308309/* Remove the mapping for the string 'key' from the object 'o'.310Returns -1 on failure.311312This is equivalent to the Python statement: del o[key]. */313PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, const char *key);314315/* Delete the mapping for the object 'key' from the object 'o'.316Returns -1 on failure.317318This is the equivalent of the Python statement: del o[key]. */319PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key);320321322/* Takes an arbitrary object and returns the result of calling323obj.__format__(format_spec). */324PyAPI_FUNC(PyObject *) PyObject_Format(PyObject *obj,325PyObject *format_spec);326327328/* ==== Iterators ================================================ */329330/* Takes an object and returns an iterator for it.331This is typically a new iterator but if the argument is an iterator, this332returns itself. */333PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *);334335/* Takes an AsyncIterable object and returns an AsyncIterator for it.336This is typically a new iterator but if the argument is an AsyncIterator,337this returns itself. */338PyAPI_FUNC(PyObject *) PyObject_GetAIter(PyObject *);339340/* Returns non-zero if the object 'obj' provides iterator protocols, and 0 otherwise.341342This function always succeeds. */343PyAPI_FUNC(int) PyIter_Check(PyObject *);344345/* Returns non-zero if the object 'obj' provides AsyncIterator protocols, and 0 otherwise.346347This function always succeeds. */348PyAPI_FUNC(int) PyAIter_Check(PyObject *);349350/* Takes an iterator object and calls its tp_iternext slot,351returning the next value.352353If the iterator is exhausted, this returns NULL without setting an354exception.355356NULL with an exception means an error occurred. */357PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *);358359#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000360361/* Takes generator, coroutine or iterator object and sends the value into it.362Returns:363- PYGEN_RETURN (0) if generator has returned.364'result' parameter is filled with return value365- PYGEN_ERROR (-1) if exception was raised.366'result' parameter is NULL367- PYGEN_NEXT (1) if generator has yielded.368'result' parameter is filled with yielded value. */369PyAPI_FUNC(PySendResult) PyIter_Send(PyObject *, PyObject *, PyObject **);370#endif371372373/* === Number Protocol ================================================== */374375/* Returns 1 if the object 'o' provides numeric protocols, and 0 otherwise.376377This function always succeeds. */378PyAPI_FUNC(int) PyNumber_Check(PyObject *o);379380/* Returns the result of adding o1 and o2, or NULL on failure.381382This is the equivalent of the Python expression: o1 + o2. */383PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2);384385/* Returns the result of subtracting o2 from o1, or NULL on failure.386387This is the equivalent of the Python expression: o1 - o2. */388PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2);389390/* Returns the result of multiplying o1 and o2, or NULL on failure.391392This is the equivalent of the Python expression: o1 * o2. */393PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2);394395#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000396/* This is the equivalent of the Python expression: o1 @ o2. */397PyAPI_FUNC(PyObject *) PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2);398#endif399400/* Returns the result of dividing o1 by o2 giving an integral result,401or NULL on failure.402403This is the equivalent of the Python expression: o1 // o2. */404PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2);405406/* Returns the result of dividing o1 by o2 giving a float result, or NULL on407failure.408409This is the equivalent of the Python expression: o1 / o2. */410PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2);411412/* Returns the remainder of dividing o1 by o2, or NULL on failure.413414This is the equivalent of the Python expression: o1 % o2. */415PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2);416417/* See the built-in function divmod.418419Returns NULL on failure.420421This is the equivalent of the Python expression: divmod(o1, o2). */422PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2);423424/* See the built-in function pow. Returns NULL on failure.425426This is the equivalent of the Python expression: pow(o1, o2, o3),427where o3 is optional. */428PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2,429PyObject *o3);430431/* Returns the negation of o on success, or NULL on failure.432433This is the equivalent of the Python expression: -o. */434PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o);435436/* Returns the positive of o on success, or NULL on failure.437438This is the equivalent of the Python expression: +o. */439PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o);440441/* Returns the absolute value of 'o', or NULL on failure.442443This is the equivalent of the Python expression: abs(o). */444PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o);445446/* Returns the bitwise negation of 'o' on success, or NULL on failure.447448This is the equivalent of the Python expression: ~o. */449PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o);450451/* Returns the result of left shifting o1 by o2 on success, or NULL on failure.452453This is the equivalent of the Python expression: o1 << o2. */454PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2);455456/* Returns the result of right shifting o1 by o2 on success, or NULL on457failure.458459This is the equivalent of the Python expression: o1 >> o2. */460PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2);461462/* Returns the result of bitwise and of o1 and o2 on success, or NULL on463failure.464465This is the equivalent of the Python expression: o1 & o2. */466PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2);467468/* Returns the bitwise exclusive or of o1 by o2 on success, or NULL on failure.469470This is the equivalent of the Python expression: o1 ^ o2. */471PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2);472473/* Returns the result of bitwise or on o1 and o2 on success, or NULL on474failure.475476This is the equivalent of the Python expression: o1 | o2. */477PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2);478479/* Returns 1 if obj is an index integer (has the nb_index slot of the480tp_as_number structure filled in), and 0 otherwise. */481PyAPI_FUNC(int) PyIndex_Check(PyObject *);482483/* Returns the object 'o' converted to a Python int, or NULL with an exception484raised on failure. */485PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o);486487/* Returns the object 'o' converted to Py_ssize_t by going through488PyNumber_Index() first.489490If an overflow error occurs while converting the int to Py_ssize_t, then the491second argument 'exc' is the error-type to return. If it is NULL, then the492overflow error is cleared and the value is clipped. */493PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc);494495/* Returns the object 'o' converted to an integer object on success, or NULL496on failure.497498This is the equivalent of the Python expression: int(o). */499PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o);500501/* Returns the object 'o' converted to a float object on success, or NULL502on failure.503504This is the equivalent of the Python expression: float(o). */505PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o);506507508/* --- In-place variants of (some of) the above number protocol functions -- */509510/* Returns the result of adding o2 to o1, possibly in-place, or NULL511on failure.512513This is the equivalent of the Python expression: o1 += o2. */514PyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2);515516/* Returns the result of subtracting o2 from o1, possibly in-place or517NULL on failure.518519This is the equivalent of the Python expression: o1 -= o2. */520PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2);521522/* Returns the result of multiplying o1 by o2, possibly in-place, or NULL on523failure.524525This is the equivalent of the Python expression: o1 *= o2. */526PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2);527528#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000529/* This is the equivalent of the Python expression: o1 @= o2. */530PyAPI_FUNC(PyObject *) PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2);531#endif532533/* Returns the result of dividing o1 by o2 giving an integral result, possibly534in-place, or NULL on failure.535536This is the equivalent of the Python expression: o1 /= o2. */537PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1,538PyObject *o2);539540/* Returns the result of dividing o1 by o2 giving a float result, possibly541in-place, or null on failure.542543This is the equivalent of the Python expression: o1 /= o2. */544PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1,545PyObject *o2);546547/* Returns the remainder of dividing o1 by o2, possibly in-place, or NULL on548failure.549550This is the equivalent of the Python expression: o1 %= o2. */551PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2);552553/* Returns the result of raising o1 to the power of o2, possibly in-place,554or NULL on failure.555556This is the equivalent of the Python expression: o1 **= o2,557or o1 = pow(o1, o2, o3) if o3 is present. */558PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2,559PyObject *o3);560561/* Returns the result of left shifting o1 by o2, possibly in-place, or NULL562on failure.563564This is the equivalent of the Python expression: o1 <<= o2. */565PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2);566567/* Returns the result of right shifting o1 by o2, possibly in-place or NULL568on failure.569570This is the equivalent of the Python expression: o1 >>= o2. */571PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2);572573/* Returns the result of bitwise and of o1 and o2, possibly in-place, or NULL574on failure.575576This is the equivalent of the Python expression: o1 &= o2. */577PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2);578579/* Returns the bitwise exclusive or of o1 by o2, possibly in-place, or NULL580on failure.581582This is the equivalent of the Python expression: o1 ^= o2. */583PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2);584585/* Returns the result of bitwise or of o1 and o2, possibly in-place,586or NULL on failure.587588This is the equivalent of the Python expression: o1 |= o2. */589PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2);590591/* Returns the integer n converted to a string with a base, with a base592marker of 0b, 0o or 0x prefixed if applicable.593594If n is not an int object, it is converted with PyNumber_Index first. */595PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base);596597598/* === Sequence protocol ================================================ */599600/* Return 1 if the object provides sequence protocol, and zero601otherwise.602603This function always succeeds. */604PyAPI_FUNC(int) PySequence_Check(PyObject *o);605606/* Return the size of sequence object o, or -1 on failure. */607PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o);608609/* For DLL compatibility */610#undef PySequence_Length611PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o);612#define PySequence_Length PySequence_Size613614615/* Return the concatenation of o1 and o2 on success, and NULL on failure.616617This is the equivalent of the Python expression: o1 + o2. */618PyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2);619620/* Return the result of repeating sequence object 'o' 'count' times,621or NULL on failure.622623This is the equivalent of the Python expression: o * count. */624PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count);625626/* Return the ith element of o, or NULL on failure.627628This is the equivalent of the Python expression: o[i]. */629PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i);630631/* Return the slice of sequence object o between i1 and i2, or NULL on failure.632633This is the equivalent of the Python expression: o[i1:i2]. */634PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);635636/* Assign object 'v' to the ith element of the sequence 'o'. Raise an exception637and return -1 on failure; return 0 on success.638639This is the equivalent of the Python statement o[i] = v. */640PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v);641642/* Delete the 'i'-th element of the sequence 'v'. Returns -1 on failure.643644This is the equivalent of the Python statement: del o[i]. */645PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i);646647/* Assign the sequence object 'v' to the slice in sequence object 'o',648from 'i1' to 'i2'. Returns -1 on failure.649650This is the equivalent of the Python statement: o[i1:i2] = v. */651PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2,652PyObject *v);653654/* Delete the slice in sequence object 'o' from 'i1' to 'i2'.655Returns -1 on failure.656657This is the equivalent of the Python statement: del o[i1:i2]. */658PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);659660/* Returns the sequence 'o' as a tuple on success, and NULL on failure.661662This is equivalent to the Python expression: tuple(o). */663PyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o);664665/* Returns the sequence 'o' as a list on success, and NULL on failure.666This is equivalent to the Python expression: list(o) */667PyAPI_FUNC(PyObject *) PySequence_List(PyObject *o);668669/* Return the sequence 'o' as a list, unless it's already a tuple or list.670671Use PySequence_Fast_GET_ITEM to access the members of this list, and672PySequence_Fast_GET_SIZE to get its length.673674Returns NULL on failure. If the object does not support iteration, raises a675TypeError exception with 'm' as the message text. */676PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m);677678/* Return the size of the sequence 'o', assuming that 'o' was returned by679PySequence_Fast and is not NULL. */680#define PySequence_Fast_GET_SIZE(o) \681(PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o))682683/* Return the 'i'-th element of the sequence 'o', assuming that o was returned684by PySequence_Fast, and that i is within bounds. */685#define PySequence_Fast_GET_ITEM(o, i)\686(PyList_Check(o) ? PyList_GET_ITEM((o), (i)) : PyTuple_GET_ITEM((o), (i)))687688/* Return a pointer to the underlying item array for689an object returned by PySequence_Fast */690#define PySequence_Fast_ITEMS(sf) \691(PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \692: ((PyTupleObject *)(sf))->ob_item)693694/* Return the number of occurrences on value on 'o', that is, return695the number of keys for which o[key] == value.696697On failure, return -1. This is equivalent to the Python expression:698o.count(value). */699PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value);700701/* Return 1 if 'ob' is in the sequence 'seq'; 0 if 'ob' is not in the sequence702'seq'; -1 on error.703704Use __contains__ if possible, else _PySequence_IterSearch(). */705PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob);706707/* For DLL-level backwards compatibility */708#undef PySequence_In709/* Determine if the sequence 'o' contains 'value'. If an item in 'o' is equal710to 'value', return 1, otherwise return 0. On error, return -1.711712This is equivalent to the Python expression: value in o. */713PyAPI_FUNC(int) PySequence_In(PyObject *o, PyObject *value);714715/* For source-level backwards compatibility */716#define PySequence_In PySequence_Contains717718719/* Return the first index for which o[i] == value.720On error, return -1.721722This is equivalent to the Python expression: o.index(value). */723PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value);724725726/* --- In-place versions of some of the above Sequence functions --- */727728/* Append sequence 'o2' to sequence 'o1', in-place when possible. Return the729resulting object, which could be 'o1', or NULL on failure.730731This is the equivalent of the Python expression: o1 += o2. */732PyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2);733734/* Repeat sequence 'o' by 'count', in-place when possible. Return the resulting735object, which could be 'o', or NULL on failure.736737This is the equivalent of the Python expression: o1 *= count. */738PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count);739740741/* === Mapping protocol ================================================= */742743/* Return 1 if the object provides mapping protocol, and 0 otherwise.744745This function always succeeds. */746PyAPI_FUNC(int) PyMapping_Check(PyObject *o);747748/* Returns the number of keys in mapping object 'o' on success, and -1 on749failure. This is equivalent to the Python expression: len(o). */750PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o);751752/* For DLL compatibility */753#undef PyMapping_Length754PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o);755#define PyMapping_Length PyMapping_Size756757758/* Implemented as a macro:759760int PyMapping_DelItemString(PyObject *o, const char *key);761762Remove the mapping for the string 'key' from the mapping 'o'. Returns -1 on763failure.764765This is equivalent to the Python statement: del o[key]. */766#define PyMapping_DelItemString(O, K) PyObject_DelItemString((O), (K))767768/* Implemented as a macro:769770int PyMapping_DelItem(PyObject *o, PyObject *key);771772Remove the mapping for the object 'key' from the mapping object 'o'.773Returns -1 on failure.774775This is equivalent to the Python statement: del o[key]. */776#define PyMapping_DelItem(O, K) PyObject_DelItem((O), (K))777778/* On success, return 1 if the mapping object 'o' has the key 'key',779and 0 otherwise.780781This is equivalent to the Python expression: key in o.782783This function always succeeds. */784PyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, const char *key);785786/* Return 1 if the mapping object has the key 'key', and 0 otherwise.787788This is equivalent to the Python expression: key in o.789790This function always succeeds. */791PyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key);792793/* On success, return a list or tuple of the keys in mapping object 'o'.794On failure, return NULL. */795PyAPI_FUNC(PyObject *) PyMapping_Keys(PyObject *o);796797/* On success, return a list or tuple of the values in mapping object 'o'.798On failure, return NULL. */799PyAPI_FUNC(PyObject *) PyMapping_Values(PyObject *o);800801/* On success, return a list or tuple of the items in mapping object 'o',802where each item is a tuple containing a key-value pair. On failure, return803NULL. */804PyAPI_FUNC(PyObject *) PyMapping_Items(PyObject *o);805806/* Return element of 'o' corresponding to the string 'key' or NULL on failure.807808This is the equivalent of the Python expression: o[key]. */809PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o,810const char *key);811812/* Map the string 'key' to the value 'v' in the mapping 'o'.813Returns -1 on failure.814815This is the equivalent of the Python statement: o[key]=v. */816PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, const char *key,817PyObject *value);818819/* isinstance(object, typeorclass) */820PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass);821822/* issubclass(object, typeorclass) */823PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass);824825#ifndef Py_LIMITED_API826# define Py_CPYTHON_ABSTRACTOBJECT_H827# include "cpython/abstract.h"828# undef Py_CPYTHON_ABSTRACTOBJECT_H829#endif830831#ifdef __cplusplus832}833#endif834#endif /* Py_ABSTRACTOBJECT_H */835836837