jpayne@69: /* Abstract Object Interface (many thanks to Jim Fulton) */ jpayne@69: jpayne@69: #ifndef Py_ABSTRACTOBJECT_H jpayne@69: #define Py_ABSTRACTOBJECT_H jpayne@69: #ifdef __cplusplus jpayne@69: extern "C" { jpayne@69: #endif jpayne@69: jpayne@69: /* === Object Protocol ================================================== */ jpayne@69: jpayne@69: /* Implemented elsewhere: jpayne@69: jpayne@69: int PyObject_Print(PyObject *o, FILE *fp, int flags); jpayne@69: jpayne@69: Print an object 'o' on file 'fp'. Returns -1 on error. The flags argument jpayne@69: is used to enable certain printing options. The only option currently jpayne@69: supported is Py_Print_RAW. jpayne@69: jpayne@69: (What should be said about Py_Print_RAW?). */ jpayne@69: jpayne@69: jpayne@69: /* Implemented elsewhere: jpayne@69: jpayne@69: int PyObject_HasAttrString(PyObject *o, const char *attr_name); jpayne@69: jpayne@69: Returns 1 if object 'o' has the attribute attr_name, and 0 otherwise. jpayne@69: jpayne@69: This is equivalent to the Python expression: hasattr(o,attr_name). jpayne@69: jpayne@69: This function always succeeds. */ jpayne@69: jpayne@69: jpayne@69: /* Implemented elsewhere: jpayne@69: jpayne@69: PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name); jpayne@69: jpayne@69: Retrieve an attributed named attr_name form object o. jpayne@69: Returns the attribute value on success, or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o.attr_name. */ jpayne@69: jpayne@69: jpayne@69: /* Implemented elsewhere: jpayne@69: jpayne@69: int PyObject_HasAttr(PyObject *o, PyObject *attr_name); jpayne@69: jpayne@69: Returns 1 if o has the attribute attr_name, and 0 otherwise. jpayne@69: jpayne@69: This is equivalent to the Python expression: hasattr(o,attr_name). jpayne@69: jpayne@69: This function always succeeds. */ jpayne@69: jpayne@69: /* Implemented elsewhere: jpayne@69: jpayne@69: PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name); jpayne@69: jpayne@69: Retrieve an attributed named 'attr_name' form object 'o'. jpayne@69: Returns the attribute value on success, or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o.attr_name. */ jpayne@69: jpayne@69: jpayne@69: /* Implemented elsewhere: jpayne@69: jpayne@69: int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v); jpayne@69: jpayne@69: Set the value of the attribute named attr_name, for object 'o', jpayne@69: to the value 'v'. Raise an exception and return -1 on failure; return 0 on jpayne@69: success. jpayne@69: jpayne@69: This is the equivalent of the Python statement o.attr_name=v. */ jpayne@69: jpayne@69: jpayne@69: /* Implemented elsewhere: jpayne@69: jpayne@69: int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v); jpayne@69: jpayne@69: Set the value of the attribute named attr_name, for object 'o', to the value jpayne@69: 'v'. an exception and return -1 on failure; return 0 on success. jpayne@69: jpayne@69: This is the equivalent of the Python statement o.attr_name=v. */ jpayne@69: jpayne@69: /* Implemented as a macro: jpayne@69: jpayne@69: int PyObject_DelAttrString(PyObject *o, const char *attr_name); jpayne@69: jpayne@69: Delete attribute named attr_name, for object o. Returns jpayne@69: -1 on failure. jpayne@69: jpayne@69: This is the equivalent of the Python statement: del o.attr_name. */ jpayne@69: #define PyObject_DelAttrString(O,A) PyObject_SetAttrString((O),(A), NULL) jpayne@69: jpayne@69: jpayne@69: /* Implemented as a macro: jpayne@69: jpayne@69: int PyObject_DelAttr(PyObject *o, PyObject *attr_name); jpayne@69: jpayne@69: Delete attribute named attr_name, for object o. Returns -1 jpayne@69: on failure. This is the equivalent of the Python jpayne@69: statement: del o.attr_name. */ jpayne@69: #define PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A), NULL) jpayne@69: jpayne@69: jpayne@69: /* Implemented elsewhere: jpayne@69: jpayne@69: PyObject *PyObject_Repr(PyObject *o); jpayne@69: jpayne@69: Compute the string representation of object 'o'. Returns the jpayne@69: string representation on success, NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: repr(o). jpayne@69: jpayne@69: Called by the repr() built-in function. */ jpayne@69: jpayne@69: jpayne@69: /* Implemented elsewhere: jpayne@69: jpayne@69: PyObject *PyObject_Str(PyObject *o); jpayne@69: jpayne@69: Compute the string representation of object, o. Returns the jpayne@69: string representation on success, NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: str(o). jpayne@69: jpayne@69: Called by the str() and print() built-in functions. */ jpayne@69: jpayne@69: jpayne@69: /* Declared elsewhere jpayne@69: jpayne@69: PyAPI_FUNC(int) PyCallable_Check(PyObject *o); jpayne@69: jpayne@69: Determine if the object, o, is callable. Return 1 if the object is callable jpayne@69: and 0 otherwise. jpayne@69: jpayne@69: This function always succeeds. */ jpayne@69: jpayne@69: jpayne@69: #ifdef PY_SSIZE_T_CLEAN jpayne@69: # define PyObject_CallFunction _PyObject_CallFunction_SizeT jpayne@69: # define PyObject_CallMethod _PyObject_CallMethod_SizeT jpayne@69: #endif jpayne@69: jpayne@69: jpayne@69: /* Call a callable Python object 'callable' with arguments given by the jpayne@69: tuple 'args' and keywords arguments given by the dictionary 'kwargs'. jpayne@69: jpayne@69: 'args' must not be NULL, use an empty tuple if no arguments are jpayne@69: needed. If no named arguments are needed, 'kwargs' can be NULL. jpayne@69: jpayne@69: This is the equivalent of the Python expression: jpayne@69: callable(*args, **kwargs). */ jpayne@69: PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable, jpayne@69: PyObject *args, PyObject *kwargs); jpayne@69: jpayne@69: jpayne@69: /* Call a callable Python object 'callable', with arguments given by the jpayne@69: tuple 'args'. If no arguments are needed, then 'args' can be NULL. jpayne@69: jpayne@69: Returns the result of the call on success, or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: jpayne@69: callable(*args). */ jpayne@69: PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable, jpayne@69: PyObject *args); jpayne@69: jpayne@69: /* Call a callable Python object, callable, with a variable number of C jpayne@69: arguments. The C arguments are described using a mkvalue-style format jpayne@69: string. jpayne@69: jpayne@69: The format may be NULL, indicating that no arguments are provided. jpayne@69: jpayne@69: Returns the result of the call on success, or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: jpayne@69: callable(arg1, arg2, ...). */ jpayne@69: PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable, jpayne@69: const char *format, ...); jpayne@69: jpayne@69: /* Call the method named 'name' of object 'obj' with a variable number of jpayne@69: C arguments. The C arguments are described by a mkvalue format string. jpayne@69: jpayne@69: The format can be NULL, indicating that no arguments are provided. jpayne@69: jpayne@69: Returns the result of the call on success, or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: jpayne@69: obj.name(arg1, arg2, ...). */ jpayne@69: PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *obj, jpayne@69: const char *name, jpayne@69: const char *format, ...); jpayne@69: jpayne@69: PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable, jpayne@69: const char *format, jpayne@69: ...); jpayne@69: jpayne@69: PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *obj, jpayne@69: const char *name, jpayne@69: const char *format, jpayne@69: ...); jpayne@69: jpayne@69: /* Call a callable Python object 'callable' with a variable number of C jpayne@69: arguments. The C arguments are provided as PyObject* values, terminated jpayne@69: by a NULL. jpayne@69: jpayne@69: Returns the result of the call on success, or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: jpayne@69: callable(arg1, arg2, ...). */ jpayne@69: PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable, jpayne@69: ...); jpayne@69: jpayne@69: /* Call the method named 'name' of object 'obj' with a variable number of jpayne@69: C arguments. The C arguments are provided as PyObject* values, terminated jpayne@69: by NULL. jpayne@69: jpayne@69: Returns the result of the call on success, or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: obj.name(*args). */ jpayne@69: jpayne@69: PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs( jpayne@69: PyObject *obj, jpayne@69: PyObject *name, jpayne@69: ...); jpayne@69: jpayne@69: jpayne@69: /* Implemented elsewhere: jpayne@69: jpayne@69: Py_hash_t PyObject_Hash(PyObject *o); jpayne@69: jpayne@69: Compute and return the hash, hash_value, of an object, o. On jpayne@69: failure, return -1. jpayne@69: jpayne@69: This is the equivalent of the Python expression: hash(o). */ jpayne@69: jpayne@69: jpayne@69: /* Implemented elsewhere: jpayne@69: jpayne@69: int PyObject_IsTrue(PyObject *o); jpayne@69: jpayne@69: Returns 1 if the object, o, is considered to be true, 0 if o is jpayne@69: considered to be false and -1 on failure. jpayne@69: jpayne@69: This is equivalent to the Python expression: not not o. */ jpayne@69: jpayne@69: jpayne@69: /* Implemented elsewhere: jpayne@69: jpayne@69: int PyObject_Not(PyObject *o); jpayne@69: jpayne@69: Returns 0 if the object, o, is considered to be true, 1 if o is jpayne@69: considered to be false and -1 on failure. jpayne@69: jpayne@69: This is equivalent to the Python expression: not o. */ jpayne@69: jpayne@69: jpayne@69: /* Get the type of an object. jpayne@69: jpayne@69: On success, returns a type object corresponding to the object type of object jpayne@69: 'o'. On failure, returns NULL. jpayne@69: jpayne@69: This is equivalent to the Python expression: type(o) */ jpayne@69: PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o); jpayne@69: jpayne@69: jpayne@69: /* Return the size of object 'o'. If the object 'o' provides both sequence and jpayne@69: mapping protocols, the sequence size is returned. jpayne@69: jpayne@69: On error, -1 is returned. jpayne@69: jpayne@69: This is the equivalent to the Python expression: len(o) */ jpayne@69: PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o); jpayne@69: jpayne@69: jpayne@69: /* For DLL compatibility */ jpayne@69: #undef PyObject_Length jpayne@69: PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o); jpayne@69: #define PyObject_Length PyObject_Size jpayne@69: jpayne@69: /* Return element of 'o' corresponding to the object 'key'. Return NULL jpayne@69: on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o[key] */ jpayne@69: PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key); jpayne@69: jpayne@69: jpayne@69: /* Map the object 'key' to the value 'v' into 'o'. jpayne@69: jpayne@69: Raise an exception and return -1 on failure; return 0 on success. jpayne@69: jpayne@69: This is the equivalent of the Python statement: o[key]=v. */ jpayne@69: PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v); jpayne@69: jpayne@69: /* Remove the mapping for the string 'key' from the object 'o'. jpayne@69: Returns -1 on failure. jpayne@69: jpayne@69: This is equivalent to the Python statement: del o[key]. */ jpayne@69: PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, const char *key); jpayne@69: jpayne@69: /* Delete the mapping for the object 'key' from the object 'o'. jpayne@69: Returns -1 on failure. jpayne@69: jpayne@69: This is the equivalent of the Python statement: del o[key]. */ jpayne@69: PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key); jpayne@69: jpayne@69: jpayne@69: /* === Old Buffer API ============================================ */ jpayne@69: jpayne@69: /* FIXME: usage of these should all be replaced in Python itself jpayne@69: but for backwards compatibility we will implement them. jpayne@69: Their usage without a corresponding "unlock" mechanism jpayne@69: may create issues (but they would already be there). */ jpayne@69: jpayne@69: /* Takes an arbitrary object which must support the (character, single segment) jpayne@69: buffer interface and returns a pointer to a read-only memory location jpayne@69: useable as character based input for subsequent processing. jpayne@69: jpayne@69: Return 0 on success. buffer and buffer_len are only set in case no error jpayne@69: occurs. Otherwise, -1 is returned and an exception set. */ jpayne@69: Py_DEPRECATED(3.0) jpayne@69: PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj, jpayne@69: const char **buffer, jpayne@69: Py_ssize_t *buffer_len); jpayne@69: jpayne@69: /* Checks whether an arbitrary object supports the (character, single segment) jpayne@69: buffer interface. jpayne@69: jpayne@69: Returns 1 on success, 0 on failure. */ jpayne@69: Py_DEPRECATED(3.0) PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj); jpayne@69: jpayne@69: /* Same as PyObject_AsCharBuffer() except that this API expects (readable, jpayne@69: single segment) buffer interface and returns a pointer to a read-only memory jpayne@69: location which can contain arbitrary data. jpayne@69: jpayne@69: 0 is returned on success. buffer and buffer_len are only set in case no jpayne@69: error occurs. Otherwise, -1 is returned and an exception set. */ jpayne@69: Py_DEPRECATED(3.0) jpayne@69: PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj, jpayne@69: const void **buffer, jpayne@69: Py_ssize_t *buffer_len); jpayne@69: jpayne@69: /* Takes an arbitrary object which must support the (writable, single segment) jpayne@69: buffer interface and returns a pointer to a writable memory location in jpayne@69: buffer of size 'buffer_len'. jpayne@69: jpayne@69: Return 0 on success. buffer and buffer_len are only set in case no error jpayne@69: occurs. Otherwise, -1 is returned and an exception set. */ jpayne@69: Py_DEPRECATED(3.0) jpayne@69: PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj, jpayne@69: void **buffer, jpayne@69: Py_ssize_t *buffer_len); jpayne@69: jpayne@69: jpayne@69: /* === New Buffer API ============================================ */ jpayne@69: jpayne@69: /* Takes an arbitrary object and returns the result of calling jpayne@69: obj.__format__(format_spec). */ jpayne@69: PyAPI_FUNC(PyObject *) PyObject_Format(PyObject *obj, jpayne@69: PyObject *format_spec); jpayne@69: jpayne@69: jpayne@69: /* ==== Iterators ================================================ */ jpayne@69: jpayne@69: /* Takes an object and returns an iterator for it. jpayne@69: This is typically a new iterator but if the argument is an iterator, this jpayne@69: returns itself. */ jpayne@69: PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *); jpayne@69: jpayne@69: /* Returns 1 if the object 'obj' provides iterator protocols, and 0 otherwise. jpayne@69: jpayne@69: This function always succeeds. */ jpayne@69: PyAPI_FUNC(int) PyIter_Check(PyObject *); jpayne@69: jpayne@69: /* Takes an iterator object and calls its tp_iternext slot, jpayne@69: returning the next value. jpayne@69: jpayne@69: If the iterator is exhausted, this returns NULL without setting an jpayne@69: exception. jpayne@69: jpayne@69: NULL with an exception means an error occurred. */ jpayne@69: PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *); jpayne@69: jpayne@69: jpayne@69: /* === Number Protocol ================================================== */ jpayne@69: jpayne@69: /* Returns 1 if the object 'o' provides numeric protocols, and 0 otherwise. jpayne@69: jpayne@69: This function always succeeds. */ jpayne@69: PyAPI_FUNC(int) PyNumber_Check(PyObject *o); jpayne@69: jpayne@69: /* Returns the result of adding o1 and o2, or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 + o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* Returns the result of subtracting o2 from o1, or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 - o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* Returns the result of multiplying o1 and o2, or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 * o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 jpayne@69: /* This is the equivalent of the Python expression: o1 @ o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2); jpayne@69: #endif jpayne@69: jpayne@69: /* Returns the result of dividing o1 by o2 giving an integral result, jpayne@69: or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 // o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* Returns the result of dividing o1 by o2 giving a float result, or NULL on jpayne@69: failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 / o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* Returns the remainder of dividing o1 by o2, or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 % o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* See the built-in function divmod. jpayne@69: jpayne@69: Returns NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: divmod(o1, o2). */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* See the built-in function pow. Returns NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: pow(o1, o2, o3), jpayne@69: where o3 is optional. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2, jpayne@69: PyObject *o3); jpayne@69: jpayne@69: /* Returns the negation of o on success, or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: -o. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o); jpayne@69: jpayne@69: /* Returns the positive of o on success, or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: +o. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o); jpayne@69: jpayne@69: /* Returns the absolute value of 'o', or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: abs(o). */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o); jpayne@69: jpayne@69: /* Returns the bitwise negation of 'o' on success, or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: ~o. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o); jpayne@69: jpayne@69: /* Returns the result of left shifting o1 by o2 on success, or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 << o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* Returns the result of right shifting o1 by o2 on success, or NULL on jpayne@69: failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 >> o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* Returns the result of bitwise and of o1 and o2 on success, or NULL on jpayne@69: failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 & o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* Returns the bitwise exclusive or of o1 by o2 on success, or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 ^ o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* Returns the result of bitwise or on o1 and o2 on success, or NULL on jpayne@69: failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 | o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* Returns 1 if obj is an index integer (has the nb_index slot of the jpayne@69: tp_as_number structure filled in), and 0 otherwise. */ jpayne@69: PyAPI_FUNC(int) PyIndex_Check(PyObject *); jpayne@69: jpayne@69: /* Returns the object 'o' converted to a Python int, or NULL with an exception jpayne@69: raised on failure. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o); jpayne@69: jpayne@69: /* Returns the object 'o' converted to Py_ssize_t by going through jpayne@69: PyNumber_Index() first. jpayne@69: jpayne@69: If an overflow error occurs while converting the int to Py_ssize_t, then the jpayne@69: second argument 'exc' is the error-type to return. If it is NULL, then the jpayne@69: overflow error is cleared and the value is clipped. */ jpayne@69: PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc); jpayne@69: jpayne@69: /* Returns the object 'o' converted to an integer object on success, or NULL jpayne@69: on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: int(o). */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o); jpayne@69: jpayne@69: /* Returns the object 'o' converted to a float object on success, or NULL jpayne@69: on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: float(o). */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o); jpayne@69: jpayne@69: jpayne@69: /* --- In-place variants of (some of) the above number protocol functions -- */ jpayne@69: jpayne@69: /* Returns the result of adding o2 to o1, possibly in-place, or NULL jpayne@69: on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 += o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* Returns the result of subtracting o2 from o1, possibly in-place or jpayne@69: NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 -= o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* Returns the result of multiplying o1 by o2, possibly in-place, or NULL on jpayne@69: failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 *= o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 jpayne@69: /* This is the equivalent of the Python expression: o1 @= o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2); jpayne@69: #endif jpayne@69: jpayne@69: /* Returns the result of dividing o1 by o2 giving an integral result, possibly jpayne@69: in-place, or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 /= o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1, jpayne@69: PyObject *o2); jpayne@69: jpayne@69: /* Returns the result of dividing o1 by o2 giving a float result, possibly jpayne@69: in-place, or null on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 /= o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1, jpayne@69: PyObject *o2); jpayne@69: jpayne@69: /* Returns the remainder of dividing o1 by o2, possibly in-place, or NULL on jpayne@69: failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 %= o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* Returns the result of raising o1 to the power of o2, possibly in-place, jpayne@69: or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 **= o2, jpayne@69: or o1 = pow(o1, o2, o3) if o3 is present. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2, jpayne@69: PyObject *o3); jpayne@69: jpayne@69: /* Returns the result of left shifting o1 by o2, possibly in-place, or NULL jpayne@69: on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 <<= o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* Returns the result of right shifting o1 by o2, possibly in-place or NULL jpayne@69: on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 >>= o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* Returns the result of bitwise and of o1 and o2, possibly in-place, or NULL jpayne@69: on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 &= o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* Returns the bitwise exclusive or of o1 by o2, possibly in-place, or NULL jpayne@69: on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 ^= o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* Returns the result of bitwise or of o1 and o2, possibly in-place, jpayne@69: or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 |= o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* Returns the integer n converted to a string with a base, with a base jpayne@69: marker of 0b, 0o or 0x prefixed if applicable. jpayne@69: jpayne@69: If n is not an int object, it is converted with PyNumber_Index first. */ jpayne@69: PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base); jpayne@69: jpayne@69: jpayne@69: /* === Sequence protocol ================================================ */ jpayne@69: jpayne@69: /* Return 1 if the object provides sequence protocol, and zero jpayne@69: otherwise. jpayne@69: jpayne@69: This function always succeeds. */ jpayne@69: PyAPI_FUNC(int) PySequence_Check(PyObject *o); jpayne@69: jpayne@69: /* Return the size of sequence object o, or -1 on failure. */ jpayne@69: PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o); jpayne@69: jpayne@69: /* For DLL compatibility */ jpayne@69: #undef PySequence_Length jpayne@69: PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o); jpayne@69: #define PySequence_Length PySequence_Size jpayne@69: jpayne@69: jpayne@69: /* Return the concatenation of o1 and o2 on success, and NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 + o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* Return the result of repeating sequence object 'o' 'count' times, jpayne@69: or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o * count. */ jpayne@69: PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count); jpayne@69: jpayne@69: /* Return the ith element of o, or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o[i]. */ jpayne@69: PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i); jpayne@69: jpayne@69: /* Return the slice of sequence object o between i1 and i2, or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o[i1:i2]. */ jpayne@69: PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); jpayne@69: jpayne@69: /* Assign object 'v' to the ith element of the sequence 'o'. Raise an exception jpayne@69: and return -1 on failure; return 0 on success. jpayne@69: jpayne@69: This is the equivalent of the Python statement o[i] = v. */ jpayne@69: PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v); jpayne@69: jpayne@69: /* Delete the 'i'-th element of the sequence 'v'. Returns -1 on failure. jpayne@69: jpayne@69: This is the equivalent of the Python statement: del o[i]. */ jpayne@69: PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i); jpayne@69: jpayne@69: /* Assign the sequence object 'v' to the slice in sequence object 'o', jpayne@69: from 'i1' to 'i2'. Returns -1 on failure. jpayne@69: jpayne@69: This is the equivalent of the Python statement: o[i1:i2] = v. */ jpayne@69: PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, jpayne@69: PyObject *v); jpayne@69: jpayne@69: /* Delete the slice in sequence object 'o' from 'i1' to 'i2'. jpayne@69: Returns -1 on failure. jpayne@69: jpayne@69: This is the equivalent of the Python statement: del o[i1:i2]. */ jpayne@69: PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); jpayne@69: jpayne@69: /* Returns the sequence 'o' as a tuple on success, and NULL on failure. jpayne@69: jpayne@69: This is equivalent to the Python expression: tuple(o). */ jpayne@69: PyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o); jpayne@69: jpayne@69: /* Returns the sequence 'o' as a list on success, and NULL on failure. jpayne@69: This is equivalent to the Python expression: list(o) */ jpayne@69: PyAPI_FUNC(PyObject *) PySequence_List(PyObject *o); jpayne@69: jpayne@69: /* Return the sequence 'o' as a list, unless it's already a tuple or list. jpayne@69: jpayne@69: Use PySequence_Fast_GET_ITEM to access the members of this list, and jpayne@69: PySequence_Fast_GET_SIZE to get its length. jpayne@69: jpayne@69: Returns NULL on failure. If the object does not support iteration, raises a jpayne@69: TypeError exception with 'm' as the message text. */ jpayne@69: PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m); jpayne@69: jpayne@69: /* Return the size of the sequence 'o', assuming that 'o' was returned by jpayne@69: PySequence_Fast and is not NULL. */ jpayne@69: #define PySequence_Fast_GET_SIZE(o) \ jpayne@69: (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o)) jpayne@69: jpayne@69: /* Return the 'i'-th element of the sequence 'o', assuming that o was returned jpayne@69: by PySequence_Fast, and that i is within bounds. */ jpayne@69: #define PySequence_Fast_GET_ITEM(o, i)\ jpayne@69: (PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i)) jpayne@69: jpayne@69: /* Return a pointer to the underlying item array for jpayne@69: an object retured by PySequence_Fast */ jpayne@69: #define PySequence_Fast_ITEMS(sf) \ jpayne@69: (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \ jpayne@69: : ((PyTupleObject *)(sf))->ob_item) jpayne@69: jpayne@69: /* Return the number of occurrences on value on 'o', that is, return jpayne@69: the number of keys for which o[key] == value. jpayne@69: jpayne@69: On failure, return -1. This is equivalent to the Python expression: jpayne@69: o.count(value). */ jpayne@69: PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value); jpayne@69: jpayne@69: /* Return 1 if 'ob' is in the sequence 'seq'; 0 if 'ob' is not in the sequence jpayne@69: 'seq'; -1 on error. jpayne@69: jpayne@69: Use __contains__ if possible, else _PySequence_IterSearch(). */ jpayne@69: PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob); jpayne@69: jpayne@69: /* For DLL-level backwards compatibility */ jpayne@69: #undef PySequence_In jpayne@69: /* Determine if the sequence 'o' contains 'value'. If an item in 'o' is equal jpayne@69: to 'value', return 1, otherwise return 0. On error, return -1. jpayne@69: jpayne@69: This is equivalent to the Python expression: value in o. */ jpayne@69: PyAPI_FUNC(int) PySequence_In(PyObject *o, PyObject *value); jpayne@69: jpayne@69: /* For source-level backwards compatibility */ jpayne@69: #define PySequence_In PySequence_Contains jpayne@69: jpayne@69: jpayne@69: /* Return the first index for which o[i] == value. jpayne@69: On error, return -1. jpayne@69: jpayne@69: This is equivalent to the Python expression: o.index(value). */ jpayne@69: PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value); jpayne@69: jpayne@69: jpayne@69: /* --- In-place versions of some of the above Sequence functions --- */ jpayne@69: jpayne@69: /* Append sequence 'o2' to sequence 'o1', in-place when possible. Return the jpayne@69: resulting object, which could be 'o1', or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 += o2. */ jpayne@69: PyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2); jpayne@69: jpayne@69: /* Repeat sequence 'o' by 'count', in-place when possible. Return the resulting jpayne@69: object, which could be 'o', or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o1 *= count. */ jpayne@69: PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count); jpayne@69: jpayne@69: jpayne@69: /* === Mapping protocol ================================================= */ jpayne@69: jpayne@69: /* Return 1 if the object provides mapping protocol, and 0 otherwise. jpayne@69: jpayne@69: This function always succeeds. */ jpayne@69: PyAPI_FUNC(int) PyMapping_Check(PyObject *o); jpayne@69: jpayne@69: /* Returns the number of keys in mapping object 'o' on success, and -1 on jpayne@69: failure. This is equivalent to the Python expression: len(o). */ jpayne@69: PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o); jpayne@69: jpayne@69: /* For DLL compatibility */ jpayne@69: #undef PyMapping_Length jpayne@69: PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o); jpayne@69: #define PyMapping_Length PyMapping_Size jpayne@69: jpayne@69: jpayne@69: /* Implemented as a macro: jpayne@69: jpayne@69: int PyMapping_DelItemString(PyObject *o, const char *key); jpayne@69: jpayne@69: Remove the mapping for the string 'key' from the mapping 'o'. Returns -1 on jpayne@69: failure. jpayne@69: jpayne@69: This is equivalent to the Python statement: del o[key]. */ jpayne@69: #define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K)) jpayne@69: jpayne@69: /* Implemented as a macro: jpayne@69: jpayne@69: int PyMapping_DelItem(PyObject *o, PyObject *key); jpayne@69: jpayne@69: Remove the mapping for the object 'key' from the mapping object 'o'. jpayne@69: Returns -1 on failure. jpayne@69: jpayne@69: This is equivalent to the Python statement: del o[key]. */ jpayne@69: #define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K)) jpayne@69: jpayne@69: /* On success, return 1 if the mapping object 'o' has the key 'key', jpayne@69: and 0 otherwise. jpayne@69: jpayne@69: This is equivalent to the Python expression: key in o. jpayne@69: jpayne@69: This function always succeeds. */ jpayne@69: PyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, const char *key); jpayne@69: jpayne@69: /* Return 1 if the mapping object has the key 'key', and 0 otherwise. jpayne@69: jpayne@69: This is equivalent to the Python expression: key in o. jpayne@69: jpayne@69: This function always succeeds. */ jpayne@69: PyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key); jpayne@69: jpayne@69: /* On success, return a list or tuple of the keys in mapping object 'o'. jpayne@69: On failure, return NULL. */ jpayne@69: PyAPI_FUNC(PyObject *) PyMapping_Keys(PyObject *o); jpayne@69: jpayne@69: /* On success, return a list or tuple of the values in mapping object 'o'. jpayne@69: On failure, return NULL. */ jpayne@69: PyAPI_FUNC(PyObject *) PyMapping_Values(PyObject *o); jpayne@69: jpayne@69: /* On success, return a list or tuple of the items in mapping object 'o', jpayne@69: where each item is a tuple containing a key-value pair. On failure, return jpayne@69: NULL. */ jpayne@69: PyAPI_FUNC(PyObject *) PyMapping_Items(PyObject *o); jpayne@69: jpayne@69: /* Return element of 'o' corresponding to the string 'key' or NULL on failure. jpayne@69: jpayne@69: This is the equivalent of the Python expression: o[key]. */ jpayne@69: PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o, jpayne@69: const char *key); jpayne@69: jpayne@69: /* Map the string 'key' to the value 'v' in the mapping 'o'. jpayne@69: Returns -1 on failure. jpayne@69: jpayne@69: This is the equivalent of the Python statement: o[key]=v. */ jpayne@69: PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, const char *key, jpayne@69: PyObject *value); jpayne@69: jpayne@69: /* isinstance(object, typeorclass) */ jpayne@69: PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass); jpayne@69: jpayne@69: /* issubclass(object, typeorclass) */ jpayne@69: PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass); jpayne@69: jpayne@69: #ifndef Py_LIMITED_API jpayne@69: # define Py_CPYTHON_ABSTRACTOBJECT_H jpayne@69: # include "cpython/abstract.h" jpayne@69: # undef Py_CPYTHON_ABSTRACTOBJECT_H jpayne@69: #endif jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: } jpayne@69: #endif jpayne@69: #endif /* Py_ABSTRACTOBJECT_H */