Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:06:48

0001 /* Abstract Object Interface (many thanks to Jim Fulton) */
0002 
0003 #ifndef Py_ABSTRACTOBJECT_H
0004 #define Py_ABSTRACTOBJECT_H
0005 #ifdef __cplusplus
0006 extern "C" {
0007 #endif
0008 
0009 /* === Object Protocol ================================================== */
0010 
0011 /* Implemented elsewhere:
0012 
0013    int PyObject_Print(PyObject *o, FILE *fp, int flags);
0014 
0015    Print an object 'o' on file 'fp'.  Returns -1 on error. The flags argument
0016    is used to enable certain printing options. The only option currently
0017    supported is Py_PRINT_RAW. By default (flags=0), PyObject_Print() formats
0018    the object by calling PyObject_Repr(). If flags equals to Py_PRINT_RAW, it
0019    formats the object by calling PyObject_Str(). */
0020 
0021 
0022 /* Implemented elsewhere:
0023 
0024    int PyObject_HasAttrString(PyObject *o, const char *attr_name);
0025 
0026    Returns 1 if object 'o' has the attribute attr_name, and 0 otherwise.
0027 
0028    This is equivalent to the Python expression: hasattr(o,attr_name).
0029 
0030    This function always succeeds. */
0031 
0032 
0033 /* Implemented elsewhere:
0034 
0035    PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name);
0036 
0037    Retrieve an attributed named attr_name form object o.
0038    Returns the attribute value on success, or NULL on failure.
0039 
0040    This is the equivalent of the Python expression: o.attr_name. */
0041 
0042 
0043 /* Implemented elsewhere:
0044 
0045    int PyObject_HasAttr(PyObject *o, PyObject *attr_name);
0046 
0047    Returns 1 if o has the attribute attr_name, and 0 otherwise.
0048 
0049    This is equivalent to the Python expression: hasattr(o,attr_name).
0050 
0051    This function always succeeds. */
0052 
0053 /* Implemented elsewhere:
0054 
0055    PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name);
0056 
0057    Retrieve an attributed named 'attr_name' form object 'o'.
0058    Returns the attribute value on success, or NULL on failure.
0059 
0060    This is the equivalent of the Python expression: o.attr_name. */
0061 
0062 
0063 /* Implemented elsewhere:
0064 
0065    int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v);
0066 
0067    Set the value of the attribute named attr_name, for object 'o',
0068    to the value 'v'. Raise an exception and return -1 on failure; return 0 on
0069    success.
0070 
0071    This is the equivalent of the Python statement o.attr_name=v. */
0072 
0073 
0074 /* Implemented elsewhere:
0075 
0076    int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v);
0077 
0078    Set the value of the attribute named attr_name, for object 'o', to the value
0079    'v'. an exception and return -1 on failure; return 0 on success.
0080 
0081    This is the equivalent of the Python statement o.attr_name=v. */
0082 
0083 /* Implemented as a macro:
0084 
0085    int PyObject_DelAttrString(PyObject *o, const char *attr_name);
0086 
0087    Delete attribute named attr_name, for object o. Returns
0088    -1 on failure.
0089 
0090    This is the equivalent of the Python statement: del o.attr_name. */
0091 #define PyObject_DelAttrString(O, A) PyObject_SetAttrString((O), (A), NULL)
0092 
0093 
0094 /* Implemented as a macro:
0095 
0096    int PyObject_DelAttr(PyObject *o, PyObject *attr_name);
0097 
0098    Delete attribute named attr_name, for object o. Returns -1
0099    on failure.  This is the equivalent of the Python
0100    statement: del o.attr_name. */
0101 #define  PyObject_DelAttr(O, A) PyObject_SetAttr((O), (A), NULL)
0102 
0103 
0104 /* Implemented elsewhere:
0105 
0106    PyObject *PyObject_Repr(PyObject *o);
0107 
0108    Compute the string representation of object 'o'.  Returns the
0109    string representation on success, NULL on failure.
0110 
0111    This is the equivalent of the Python expression: repr(o).
0112 
0113    Called by the repr() built-in function. */
0114 
0115 
0116 /* Implemented elsewhere:
0117 
0118    PyObject *PyObject_Str(PyObject *o);
0119 
0120    Compute the string representation of object, o.  Returns the
0121    string representation on success, NULL on failure.
0122 
0123    This is the equivalent of the Python expression: str(o).
0124 
0125    Called by the str() and print() built-in functions. */
0126 
0127 
0128 /* Declared elsewhere
0129 
0130    PyAPI_FUNC(int) PyCallable_Check(PyObject *o);
0131 
0132    Determine if the object, o, is callable.  Return 1 if the object is callable
0133    and 0 otherwise.
0134 
0135    This function always succeeds. */
0136 
0137 
0138 #ifdef PY_SSIZE_T_CLEAN
0139 #  define PyObject_CallFunction _PyObject_CallFunction_SizeT
0140 #  define PyObject_CallMethod _PyObject_CallMethod_SizeT
0141 #endif
0142 
0143 
0144 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
0145 /* Call a callable Python object without any arguments */
0146 PyAPI_FUNC(PyObject *) PyObject_CallNoArgs(PyObject *func);
0147 #endif
0148 
0149 
0150 /* Call a callable Python object 'callable' with arguments given by the
0151    tuple 'args' and keywords arguments given by the dictionary 'kwargs'.
0152 
0153    'args' must not be NULL, use an empty tuple if no arguments are
0154    needed. If no named arguments are needed, 'kwargs' can be NULL.
0155 
0156    This is the equivalent of the Python expression:
0157    callable(*args, **kwargs). */
0158 PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable,
0159                                      PyObject *args, PyObject *kwargs);
0160 
0161 
0162 /* Call a callable Python object 'callable', with arguments given by the
0163    tuple 'args'.  If no arguments are needed, then 'args' can be NULL.
0164 
0165    Returns the result of the call on success, or NULL on failure.
0166 
0167    This is the equivalent of the Python expression:
0168    callable(*args). */
0169 PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable,
0170                                            PyObject *args);
0171 
0172 /* Call a callable Python object, callable, with a variable number of C
0173    arguments. The C arguments are described using a mkvalue-style format
0174    string.
0175 
0176    The format may be NULL, indicating that no arguments are provided.
0177 
0178    Returns the result of the call on success, or NULL on failure.
0179 
0180    This is the equivalent of the Python expression:
0181    callable(arg1, arg2, ...). */
0182 PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable,
0183                                              const char *format, ...);
0184 
0185 /* Call the method named 'name' of object 'obj' with a variable number of
0186    C arguments.  The C arguments are described by a mkvalue format string.
0187 
0188    The format can be NULL, indicating that no arguments are provided.
0189 
0190    Returns the result of the call on success, or NULL on failure.
0191 
0192    This is the equivalent of the Python expression:
0193    obj.name(arg1, arg2, ...). */
0194 PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *obj,
0195                                            const char *name,
0196                                            const char *format, ...);
0197 
0198 PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable,
0199                                                     const char *format,
0200                                                     ...);
0201 
0202 PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *obj,
0203                                                   const char *name,
0204                                                   const char *format,
0205                                                   ...);
0206 
0207 /* Call a callable Python object 'callable' with a variable number of C
0208    arguments. The C arguments are provided as PyObject* values, terminated
0209    by a NULL.
0210 
0211    Returns the result of the call on success, or NULL on failure.
0212 
0213    This is the equivalent of the Python expression:
0214    callable(arg1, arg2, ...). */
0215 PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable,
0216                                                     ...);
0217 
0218 /* Call the method named 'name' of object 'obj' with a variable number of
0219    C arguments.  The C arguments are provided as PyObject* values, terminated
0220    by NULL.
0221 
0222    Returns the result of the call on success, or NULL on failure.
0223 
0224    This is the equivalent of the Python expression: obj.name(*args). */
0225 
0226 PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs(
0227     PyObject *obj,
0228     PyObject *name,
0229     ...);
0230 
0231 /* Given a vectorcall nargsf argument, return the actual number of arguments.
0232  * (For use outside the limited API, this is re-defined as a static inline
0233  * function in cpython/abstract.h)
0234  */
0235 PyAPI_FUNC(Py_ssize_t) PyVectorcall_NARGS(size_t nargsf);
0236 
0237 /* Call "callable" (which must support vectorcall) with positional arguments
0238    "tuple" and keyword arguments "dict". "dict" may also be NULL */
0239 PyAPI_FUNC(PyObject *) PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *dict);
0240 
0241 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030C0000
0242 #define PY_VECTORCALL_ARGUMENTS_OFFSET \
0243     (_Py_STATIC_CAST(size_t, 1) << (8 * sizeof(size_t) - 1))
0244 
0245 /* Perform a PEP 590-style vector call on 'callable' */
0246 PyAPI_FUNC(PyObject *) PyObject_Vectorcall(
0247     PyObject *callable,
0248     PyObject *const *args,
0249     size_t nargsf,
0250     PyObject *kwnames);
0251 
0252 /* Call the method 'name' on args[0] with arguments in args[1..nargsf-1]. */
0253 PyAPI_FUNC(PyObject *) PyObject_VectorcallMethod(
0254     PyObject *name, PyObject *const *args,
0255     size_t nargsf, PyObject *kwnames);
0256 #endif
0257 
0258 /* Implemented elsewhere:
0259 
0260    Py_hash_t PyObject_Hash(PyObject *o);
0261 
0262    Compute and return the hash, hash_value, of an object, o.  On
0263    failure, return -1.
0264 
0265    This is the equivalent of the Python expression: hash(o). */
0266 
0267 
0268 /* Implemented elsewhere:
0269 
0270    int PyObject_IsTrue(PyObject *o);
0271 
0272    Returns 1 if the object, o, is considered to be true, 0 if o is
0273    considered to be false and -1 on failure.
0274 
0275    This is equivalent to the Python expression: not not o. */
0276 
0277 
0278 /* Implemented elsewhere:
0279 
0280    int PyObject_Not(PyObject *o);
0281 
0282    Returns 0 if the object, o, is considered to be true, 1 if o is
0283    considered to be false and -1 on failure.
0284 
0285    This is equivalent to the Python expression: not o. */
0286 
0287 
0288 /* Get the type of an object.
0289 
0290    On success, returns a type object corresponding to the object type of object
0291    'o'. On failure, returns NULL.
0292 
0293    This is equivalent to the Python expression: type(o) */
0294 PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o);
0295 
0296 
0297 /* Return the size of object 'o'.  If the object 'o' provides both sequence and
0298    mapping protocols, the sequence size is returned.
0299 
0300    On error, -1 is returned.
0301 
0302    This is the equivalent to the Python expression: len(o) */
0303 PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o);
0304 
0305 
0306 /* For DLL compatibility */
0307 #undef PyObject_Length
0308 PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o);
0309 #define PyObject_Length PyObject_Size
0310 
0311 /* Return element of 'o' corresponding to the object 'key'. Return NULL
0312   on failure.
0313 
0314   This is the equivalent of the Python expression: o[key] */
0315 PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key);
0316 
0317 
0318 /* Map the object 'key' to the value 'v' into 'o'.
0319 
0320    Raise an exception and return -1 on failure; return 0 on success.
0321 
0322    This is the equivalent of the Python statement: o[key]=v. */
0323 PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v);
0324 
0325 /* Remove the mapping for the string 'key' from the object 'o'.
0326    Returns -1 on failure.
0327 
0328    This is equivalent to the Python statement: del o[key]. */
0329 PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, const char *key);
0330 
0331 /* Delete the mapping for the object 'key' from the object 'o'.
0332    Returns -1 on failure.
0333 
0334    This is the equivalent of the Python statement: del o[key]. */
0335 PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key);
0336 
0337 
0338 /* === Old Buffer API ============================================ */
0339 
0340 /* FIXME:  usage of these should all be replaced in Python itself
0341    but for backwards compatibility we will implement them.
0342    Their usage without a corresponding "unlock" mechanism
0343    may create issues (but they would already be there). */
0344 
0345 /* Takes an arbitrary object which must support the (character, single segment)
0346    buffer interface and returns a pointer to a read-only memory location
0347    usable as character based input for subsequent processing.
0348 
0349    Return 0 on success.  buffer and buffer_len are only set in case no error
0350    occurs. Otherwise, -1 is returned and an exception set. */
0351 Py_DEPRECATED(3.0)
0352 PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj,
0353                                       const char **buffer,
0354                                       Py_ssize_t *buffer_len);
0355 
0356 /* Checks whether an arbitrary object supports the (character, single segment)
0357    buffer interface.
0358 
0359    Returns 1 on success, 0 on failure. */
0360 Py_DEPRECATED(3.0) PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj);
0361 
0362 /* Same as PyObject_AsCharBuffer() except that this API expects (readable,
0363    single segment) buffer interface and returns a pointer to a read-only memory
0364    location which can contain arbitrary data.
0365 
0366    0 is returned on success.  buffer and buffer_len are only set in case no
0367    error occurs.  Otherwise, -1 is returned and an exception set. */
0368 Py_DEPRECATED(3.0)
0369 PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj,
0370                                       const void **buffer,
0371                                       Py_ssize_t *buffer_len);
0372 
0373 /* Takes an arbitrary object which must support the (writable, single segment)
0374    buffer interface and returns a pointer to a writable memory location in
0375    buffer of size 'buffer_len'.
0376 
0377    Return 0 on success.  buffer and buffer_len are only set in case no error
0378    occurs. Otherwise, -1 is returned and an exception set. */
0379 Py_DEPRECATED(3.0)
0380 PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj,
0381                                        void **buffer,
0382                                        Py_ssize_t *buffer_len);
0383 
0384 
0385 /* === New Buffer API ============================================ */
0386 
0387 /* Takes an arbitrary object and returns the result of calling
0388    obj.__format__(format_spec). */
0389 PyAPI_FUNC(PyObject *) PyObject_Format(PyObject *obj,
0390                                        PyObject *format_spec);
0391 
0392 
0393 /* ==== Iterators ================================================ */
0394 
0395 /* Takes an object and returns an iterator for it.
0396    This is typically a new iterator but if the argument is an iterator, this
0397    returns itself. */
0398 PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *);
0399 
0400 /* Takes an AsyncIterable object and returns an AsyncIterator for it.
0401    This is typically a new iterator but if the argument is an AsyncIterator,
0402    this returns itself. */
0403 PyAPI_FUNC(PyObject *) PyObject_GetAIter(PyObject *);
0404 
0405 /* Returns non-zero if the object 'obj' provides iterator protocols, and 0 otherwise.
0406 
0407    This function always succeeds. */
0408 PyAPI_FUNC(int) PyIter_Check(PyObject *);
0409 
0410 /* Returns non-zero if the object 'obj' provides AsyncIterator protocols, and 0 otherwise.
0411 
0412    This function always succeeds. */
0413 PyAPI_FUNC(int) PyAIter_Check(PyObject *);
0414 
0415 /* Takes an iterator object and calls its tp_iternext slot,
0416    returning the next value.
0417 
0418    If the iterator is exhausted, this returns NULL without setting an
0419    exception.
0420 
0421    NULL with an exception means an error occurred. */
0422 PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *);
0423 
0424 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000
0425 
0426 /* Takes generator, coroutine or iterator object and sends the value into it.
0427    Returns:
0428    - PYGEN_RETURN (0) if generator has returned.
0429      'result' parameter is filled with return value
0430    - PYGEN_ERROR (-1) if exception was raised.
0431      'result' parameter is NULL
0432    - PYGEN_NEXT (1) if generator has yielded.
0433      'result' parameter is filled with yielded value. */
0434 PyAPI_FUNC(PySendResult) PyIter_Send(PyObject *, PyObject *, PyObject **);
0435 #endif
0436 
0437 
0438 /* === Number Protocol ================================================== */
0439 
0440 /* Returns 1 if the object 'o' provides numeric protocols, and 0 otherwise.
0441 
0442    This function always succeeds. */
0443 PyAPI_FUNC(int) PyNumber_Check(PyObject *o);
0444 
0445 /* Returns the result of adding o1 and o2, or NULL on failure.
0446 
0447    This is the equivalent of the Python expression: o1 + o2. */
0448 PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2);
0449 
0450 /* Returns the result of subtracting o2 from o1, or NULL on failure.
0451 
0452    This is the equivalent of the Python expression: o1 - o2. */
0453 PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2);
0454 
0455 /* Returns the result of multiplying o1 and o2, or NULL on failure.
0456 
0457    This is the equivalent of the Python expression: o1 * o2. */
0458 PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2);
0459 
0460 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
0461 /* This is the equivalent of the Python expression: o1 @ o2. */
0462 PyAPI_FUNC(PyObject *) PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2);
0463 #endif
0464 
0465 /* Returns the result of dividing o1 by o2 giving an integral result,
0466    or NULL on failure.
0467 
0468    This is the equivalent of the Python expression: o1 // o2. */
0469 PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2);
0470 
0471 /* Returns the result of dividing o1 by o2 giving a float result, or NULL on
0472    failure.
0473 
0474    This is the equivalent of the Python expression: o1 / o2. */
0475 PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2);
0476 
0477 /* Returns the remainder of dividing o1 by o2, or NULL on failure.
0478 
0479    This is the equivalent of the Python expression: o1 % o2. */
0480 PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2);
0481 
0482 /* See the built-in function divmod.
0483 
0484    Returns NULL on failure.
0485 
0486    This is the equivalent of the Python expression: divmod(o1, o2). */
0487 PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2);
0488 
0489 /* See the built-in function pow. Returns NULL on failure.
0490 
0491    This is the equivalent of the Python expression: pow(o1, o2, o3),
0492    where o3 is optional. */
0493 PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2,
0494                                       PyObject *o3);
0495 
0496 /* Returns the negation of o on success, or NULL on failure.
0497 
0498  This is the equivalent of the Python expression: -o. */
0499 PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o);
0500 
0501 /* Returns the positive of o on success, or NULL on failure.
0502 
0503    This is the equivalent of the Python expression: +o. */
0504 PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o);
0505 
0506 /* Returns the absolute value of 'o', or NULL on failure.
0507 
0508    This is the equivalent of the Python expression: abs(o). */
0509 PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o);
0510 
0511 /* Returns the bitwise negation of 'o' on success, or NULL on failure.
0512 
0513    This is the equivalent of the Python expression: ~o. */
0514 PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o);
0515 
0516 /* Returns the result of left shifting o1 by o2 on success, or NULL on failure.
0517 
0518    This is the equivalent of the Python expression: o1 << o2. */
0519 PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2);
0520 
0521 /* Returns the result of right shifting o1 by o2 on success, or NULL on
0522    failure.
0523 
0524    This is the equivalent of the Python expression: o1 >> o2. */
0525 PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2);
0526 
0527 /* Returns the result of bitwise and of o1 and o2 on success, or NULL on
0528    failure.
0529 
0530    This is the equivalent of the Python expression: o1 & o2. */
0531 PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2);
0532 
0533 /* Returns the bitwise exclusive or of o1 by o2 on success, or NULL on failure.
0534 
0535    This is the equivalent of the Python expression: o1 ^ o2. */
0536 PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2);
0537 
0538 /* Returns the result of bitwise or on o1 and o2 on success, or NULL on
0539    failure.
0540 
0541    This is the equivalent of the Python expression: o1 | o2. */
0542 PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2);
0543 
0544 /* Returns 1 if obj is an index integer (has the nb_index slot of the
0545    tp_as_number structure filled in), and 0 otherwise. */
0546 PyAPI_FUNC(int) PyIndex_Check(PyObject *);
0547 
0548 /* Returns the object 'o' converted to a Python int, or NULL with an exception
0549    raised on failure. */
0550 PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o);
0551 
0552 /* Returns the object 'o' converted to Py_ssize_t by going through
0553    PyNumber_Index() first.
0554 
0555    If an overflow error occurs while converting the int to Py_ssize_t, then the
0556    second argument 'exc' is the error-type to return.  If it is NULL, then the
0557    overflow error is cleared and the value is clipped. */
0558 PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc);
0559 
0560 /* Returns the object 'o' converted to an integer object on success, or NULL
0561    on failure.
0562 
0563    This is the equivalent of the Python expression: int(o). */
0564 PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o);
0565 
0566 /* Returns the object 'o' converted to a float object on success, or NULL
0567   on failure.
0568 
0569   This is the equivalent of the Python expression: float(o). */
0570 PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o);
0571 
0572 
0573 /* --- In-place variants of (some of) the above number protocol functions -- */
0574 
0575 /* Returns the result of adding o2 to o1, possibly in-place, or NULL
0576    on failure.
0577 
0578    This is the equivalent of the Python expression: o1 += o2. */
0579 PyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2);
0580 
0581 /* Returns the result of subtracting o2 from o1, possibly in-place or
0582    NULL on failure.
0583 
0584    This is the equivalent of the Python expression: o1 -= o2. */
0585 PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2);
0586 
0587 /* Returns the result of multiplying o1 by o2, possibly in-place, or NULL on
0588    failure.
0589 
0590    This is the equivalent of the Python expression: o1 *= o2. */
0591 PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2);
0592 
0593 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
0594 /* This is the equivalent of the Python expression: o1 @= o2. */
0595 PyAPI_FUNC(PyObject *) PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2);
0596 #endif
0597 
0598 /* Returns the result of dividing o1 by o2 giving an integral result, possibly
0599    in-place, or NULL on failure.
0600 
0601    This is the equivalent of the Python expression: o1 /= o2. */
0602 PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1,
0603                                                    PyObject *o2);
0604 
0605 /* Returns the result of dividing o1 by o2 giving a float result, possibly
0606    in-place, or null on failure.
0607 
0608    This is the equivalent of the Python expression: o1 /= o2. */
0609 PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1,
0610                                                   PyObject *o2);
0611 
0612 /* Returns the remainder of dividing o1 by o2, possibly in-place, or NULL on
0613    failure.
0614 
0615    This is the equivalent of the Python expression: o1 %= o2. */
0616 PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2);
0617 
0618 /* Returns the result of raising o1 to the power of o2, possibly in-place,
0619    or NULL on failure.
0620 
0621    This is the equivalent of the Python expression: o1 **= o2,
0622    or o1 = pow(o1, o2, o3) if o3 is present. */
0623 PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2,
0624                                              PyObject *o3);
0625 
0626 /* Returns the result of left shifting o1 by o2, possibly in-place, or NULL
0627    on failure.
0628 
0629    This is the equivalent of the Python expression: o1 <<= o2. */
0630 PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2);
0631 
0632 /* Returns the result of right shifting o1 by o2, possibly in-place or NULL
0633    on failure.
0634 
0635    This is the equivalent of the Python expression: o1 >>= o2. */
0636 PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2);
0637 
0638 /* Returns the result of bitwise and of o1 and o2, possibly in-place, or NULL
0639    on failure.
0640 
0641    This is the equivalent of the Python expression: o1 &= o2. */
0642 PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2);
0643 
0644 /* Returns the bitwise exclusive or of o1 by o2, possibly in-place, or NULL
0645    on failure.
0646 
0647    This is the equivalent of the Python expression: o1 ^= o2. */
0648 PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2);
0649 
0650 /* Returns the result of bitwise or of o1 and o2, possibly in-place,
0651    or NULL on failure.
0652 
0653    This is the equivalent of the Python expression: o1 |= o2. */
0654 PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2);
0655 
0656 /* Returns the integer n converted to a string with a base, with a base
0657    marker of 0b, 0o or 0x prefixed if applicable.
0658 
0659    If n is not an int object, it is converted with PyNumber_Index first. */
0660 PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base);
0661 
0662 
0663 /* === Sequence protocol ================================================ */
0664 
0665 /* Return 1 if the object provides sequence protocol, and zero
0666    otherwise.
0667 
0668    This function always succeeds. */
0669 PyAPI_FUNC(int) PySequence_Check(PyObject *o);
0670 
0671 /* Return the size of sequence object o, or -1 on failure. */
0672 PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o);
0673 
0674 /* For DLL compatibility */
0675 #undef PySequence_Length
0676 PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o);
0677 #define PySequence_Length PySequence_Size
0678 
0679 
0680 /* Return the concatenation of o1 and o2 on success, and NULL on failure.
0681 
0682    This is the equivalent of the Python expression: o1 + o2. */
0683 PyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2);
0684 
0685 /* Return the result of repeating sequence object 'o' 'count' times,
0686   or NULL on failure.
0687 
0688   This is the equivalent of the Python expression: o * count. */
0689 PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count);
0690 
0691 /* Return the ith element of o, or NULL on failure.
0692 
0693    This is the equivalent of the Python expression: o[i]. */
0694 PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i);
0695 
0696 /* Return the slice of sequence object o between i1 and i2, or NULL on failure.
0697 
0698    This is the equivalent of the Python expression: o[i1:i2]. */
0699 PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
0700 
0701 /* Assign object 'v' to the ith element of the sequence 'o'. Raise an exception
0702    and return -1 on failure; return 0 on success.
0703 
0704    This is the equivalent of the Python statement o[i] = v. */
0705 PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v);
0706 
0707 /* Delete the 'i'-th element of the sequence 'v'. Returns -1 on failure.
0708 
0709    This is the equivalent of the Python statement: del o[i]. */
0710 PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i);
0711 
0712 /* Assign the sequence object 'v' to the slice in sequence object 'o',
0713    from 'i1' to 'i2'. Returns -1 on failure.
0714 
0715    This is the equivalent of the Python statement: o[i1:i2] = v. */
0716 PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2,
0717                                     PyObject *v);
0718 
0719 /* Delete the slice in sequence object 'o' from 'i1' to 'i2'.
0720    Returns -1 on failure.
0721 
0722    This is the equivalent of the Python statement: del o[i1:i2]. */
0723 PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
0724 
0725 /* Returns the sequence 'o' as a tuple on success, and NULL on failure.
0726 
0727    This is equivalent to the Python expression: tuple(o). */
0728 PyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o);
0729 
0730 /* Returns the sequence 'o' as a list on success, and NULL on failure.
0731    This is equivalent to the Python expression: list(o) */
0732 PyAPI_FUNC(PyObject *) PySequence_List(PyObject *o);
0733 
0734 /* Return the sequence 'o' as a list, unless it's already a tuple or list.
0735 
0736    Use PySequence_Fast_GET_ITEM to access the members of this list, and
0737    PySequence_Fast_GET_SIZE to get its length.
0738 
0739    Returns NULL on failure.  If the object does not support iteration, raises a
0740    TypeError exception with 'm' as the message text. */
0741 PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m);
0742 
0743 /* Return the size of the sequence 'o', assuming that 'o' was returned by
0744    PySequence_Fast and is not NULL. */
0745 #define PySequence_Fast_GET_SIZE(o) \
0746     (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o))
0747 
0748 /* Return the 'i'-th element of the sequence 'o', assuming that o was returned
0749    by PySequence_Fast, and that i is within bounds. */
0750 #define PySequence_Fast_GET_ITEM(o, i)\
0751      (PyList_Check(o) ? PyList_GET_ITEM((o), (i)) : PyTuple_GET_ITEM((o), (i)))
0752 
0753 /* Return a pointer to the underlying item array for
0754    an object returned by PySequence_Fast */
0755 #define PySequence_Fast_ITEMS(sf) \
0756     (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \
0757                       : ((PyTupleObject *)(sf))->ob_item)
0758 
0759 /* Return the number of occurrences on value on 'o', that is, return
0760    the number of keys for which o[key] == value.
0761 
0762    On failure, return -1.  This is equivalent to the Python expression:
0763    o.count(value). */
0764 PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value);
0765 
0766 /* Return 1 if 'ob' is in the sequence 'seq'; 0 if 'ob' is not in the sequence
0767    'seq'; -1 on error.
0768 
0769    Use __contains__ if possible, else _PySequence_IterSearch(). */
0770 PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob);
0771 
0772 /* For DLL-level backwards compatibility */
0773 #undef PySequence_In
0774 /* Determine if the sequence 'o' contains 'value'. If an item in 'o' is equal
0775    to 'value', return 1, otherwise return 0. On error, return -1.
0776 
0777    This is equivalent to the Python expression: value in o. */
0778 PyAPI_FUNC(int) PySequence_In(PyObject *o, PyObject *value);
0779 
0780 /* For source-level backwards compatibility */
0781 #define PySequence_In PySequence_Contains
0782 
0783 
0784 /* Return the first index for which o[i] == value.
0785    On error, return -1.
0786 
0787    This is equivalent to the Python expression: o.index(value). */
0788 PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value);
0789 
0790 
0791 /* --- In-place versions of some of the above Sequence functions --- */
0792 
0793 /* Append sequence 'o2' to sequence 'o1', in-place when possible. Return the
0794    resulting object, which could be 'o1', or NULL on failure.
0795 
0796   This is the equivalent of the Python expression: o1 += o2. */
0797 PyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2);
0798 
0799 /* Repeat sequence 'o' by 'count', in-place when possible. Return the resulting
0800    object, which could be 'o', or NULL on failure.
0801 
0802    This is the equivalent of the Python expression: o1 *= count.  */
0803 PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count);
0804 
0805 
0806 /* === Mapping protocol ================================================= */
0807 
0808 /* Return 1 if the object provides mapping protocol, and 0 otherwise.
0809 
0810    This function always succeeds. */
0811 PyAPI_FUNC(int) PyMapping_Check(PyObject *o);
0812 
0813 /* Returns the number of keys in mapping object 'o' on success, and -1 on
0814   failure. This is equivalent to the Python expression: len(o). */
0815 PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o);
0816 
0817 /* For DLL compatibility */
0818 #undef PyMapping_Length
0819 PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o);
0820 #define PyMapping_Length PyMapping_Size
0821 
0822 
0823 /* Implemented as a macro:
0824 
0825    int PyMapping_DelItemString(PyObject *o, const char *key);
0826 
0827    Remove the mapping for the string 'key' from the mapping 'o'. Returns -1 on
0828    failure.
0829 
0830    This is equivalent to the Python statement: del o[key]. */
0831 #define PyMapping_DelItemString(O, K) PyObject_DelItemString((O), (K))
0832 
0833 /* Implemented as a macro:
0834 
0835    int PyMapping_DelItem(PyObject *o, PyObject *key);
0836 
0837    Remove the mapping for the object 'key' from the mapping object 'o'.
0838    Returns -1 on failure.
0839 
0840    This is equivalent to the Python statement: del o[key]. */
0841 #define PyMapping_DelItem(O, K) PyObject_DelItem((O), (K))
0842 
0843 /* On success, return 1 if the mapping object 'o' has the key 'key',
0844    and 0 otherwise.
0845 
0846    This is equivalent to the Python expression: key in o.
0847 
0848    This function always succeeds. */
0849 PyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, const char *key);
0850 
0851 /* Return 1 if the mapping object has the key 'key', and 0 otherwise.
0852 
0853    This is equivalent to the Python expression: key in o.
0854 
0855    This function always succeeds. */
0856 PyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key);
0857 
0858 /* On success, return a list or tuple of the keys in mapping object 'o'.
0859    On failure, return NULL. */
0860 PyAPI_FUNC(PyObject *) PyMapping_Keys(PyObject *o);
0861 
0862 /* On success, return a list or tuple of the values in mapping object 'o'.
0863    On failure, return NULL. */
0864 PyAPI_FUNC(PyObject *) PyMapping_Values(PyObject *o);
0865 
0866 /* On success, return a list or tuple of the items in mapping object 'o',
0867    where each item is a tuple containing a key-value pair. On failure, return
0868    NULL. */
0869 PyAPI_FUNC(PyObject *) PyMapping_Items(PyObject *o);
0870 
0871 /* Return element of 'o' corresponding to the string 'key' or NULL on failure.
0872 
0873    This is the equivalent of the Python expression: o[key]. */
0874 PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o,
0875                                                const char *key);
0876 
0877 /* Map the string 'key' to the value 'v' in the mapping 'o'.
0878    Returns -1 on failure.
0879 
0880    This is the equivalent of the Python statement: o[key]=v. */
0881 PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, const char *key,
0882                                         PyObject *value);
0883 
0884 /* isinstance(object, typeorclass) */
0885 PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass);
0886 
0887 /* issubclass(object, typeorclass) */
0888 PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass);
0889 
0890 #ifndef Py_LIMITED_API
0891 #  define Py_CPYTHON_ABSTRACTOBJECT_H
0892 #  include "cpython/abstract.h"
0893 #  undef Py_CPYTHON_ABSTRACTOBJECT_H
0894 #endif
0895 
0896 #ifdef __cplusplus
0897 }
0898 #endif
0899 #endif /* Py_ABSTRACTOBJECT_H */