Victor Stinner | b6522d0 | 2016-12-19 13:12:08 +0100 | [diff] [blame] | 1 | /* Abstract Object Interface (many thanks to Jim Fulton) */ |
| 2 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 3 | #ifndef Py_ABSTRACTOBJECT_H |
| 4 | #define Py_ABSTRACTOBJECT_H |
| 5 | #ifdef __cplusplus |
| 6 | extern "C" { |
| 7 | #endif |
| 8 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 9 | /* === Object Protocol ================================================== */ |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 10 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 11 | /* Implemented elsewhere: |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 12 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 13 | int PyObject_Print(PyObject *o, FILE *fp, int flags); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 14 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 15 | Print an object 'o' on file 'fp'. Returns -1 on error. The flags argument |
| 16 | is used to enable certain printing options. The only option currently |
| 17 | supported is Py_Print_RAW. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 18 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 19 | (What should be said about Py_Print_RAW?). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 20 | |
| 21 | |
| 22 | /* Implemented elsewhere: |
| 23 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 24 | int PyObject_HasAttrString(PyObject *o, const char *attr_name); |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 25 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 26 | Returns 1 if object 'o' has the attribute attr_name, and 0 otherwise. |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 27 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 28 | This is equivalent to the Python expression: hasattr(o,attr_name). |
| 29 | |
| 30 | This function always succeeds. */ |
| 31 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 32 | |
| 33 | /* Implemented elsewhere: |
| 34 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 35 | PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name); |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 36 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 37 | Retrieve an attributed named attr_name form object o. |
| 38 | Returns the attribute value on success, or NULL on failure. |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 39 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 40 | This is the equivalent of the Python expression: o.attr_name. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 41 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 42 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 43 | /* Implemented elsewhere: |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 44 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 45 | int PyObject_HasAttr(PyObject *o, PyObject *attr_name); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 46 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 47 | Returns 1 if o has the attribute attr_name, and 0 otherwise. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 48 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 49 | This is equivalent to the Python expression: hasattr(o,attr_name). |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 50 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 51 | This function always succeeds. */ |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 52 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 53 | /* Implemented elsewhere: |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 54 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 55 | PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 56 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 57 | Retrieve an attributed named 'attr_name' form object 'o'. |
| 58 | Returns the attribute value on success, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 59 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 60 | This is the equivalent of the Python expression: o.attr_name. */ |
Marc-André Lemburg | ad7c98e | 2001-01-17 17:09:53 +0000 | [diff] [blame] | 61 | |
Marc-André Lemburg | ad7c98e | 2001-01-17 17:09:53 +0000 | [diff] [blame] | 62 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 63 | /* Implemented elsewhere: |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 64 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 65 | int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 66 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 67 | Set the value of the attribute named attr_name, for object 'o', |
| 68 | to the value 'v'. Raise an exception and return -1 on failure; return 0 on |
| 69 | success. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 70 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 71 | This is the equivalent of the Python statement o.attr_name=v. */ |
| 72 | |
| 73 | |
| 74 | /* Implemented elsewhere: |
| 75 | |
| 76 | int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v); |
| 77 | |
| 78 | Set the value of the attribute named attr_name, for object 'o', to the value |
| 79 | 'v'. an exception and return -1 on failure; return 0 on success. |
| 80 | |
| 81 | This is the equivalent of the Python statement o.attr_name=v. */ |
| 82 | |
| 83 | /* Implemented as a macro: |
| 84 | |
| 85 | int PyObject_DelAttrString(PyObject *o, const char *attr_name); |
| 86 | |
| 87 | Delete attribute named attr_name, for object o. Returns |
| 88 | -1 on failure. |
| 89 | |
| 90 | This is the equivalent of the Python statement: del o.attr_name. */ |
| 91 | #define PyObject_DelAttrString(O,A) PyObject_SetAttrString((O),(A), NULL) |
| 92 | |
| 93 | |
| 94 | /* Implemented as a macro: |
| 95 | |
| 96 | int PyObject_DelAttr(PyObject *o, PyObject *attr_name); |
| 97 | |
| 98 | Delete attribute named attr_name, for object o. Returns -1 |
| 99 | on failure. This is the equivalent of the Python |
| 100 | statement: del o.attr_name. */ |
| 101 | #define PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A), NULL) |
| 102 | |
| 103 | |
| 104 | /* Implemented elsewhere: |
| 105 | |
| 106 | PyObject *PyObject_Repr(PyObject *o); |
| 107 | |
| 108 | Compute the string representation of object 'o'. Returns the |
| 109 | string representation on success, NULL on failure. |
| 110 | |
| 111 | This is the equivalent of the Python expression: repr(o). |
| 112 | |
| 113 | Called by the repr() built-in function. */ |
| 114 | |
| 115 | |
| 116 | /* Implemented elsewhere: |
| 117 | |
| 118 | PyObject *PyObject_Str(PyObject *o); |
| 119 | |
| 120 | Compute the string representation of object, o. Returns the |
| 121 | string representation on success, NULL on failure. |
| 122 | |
| 123 | This is the equivalent of the Python expression: str(o). |
| 124 | |
| 125 | Called by the str() and print() built-in functions. */ |
| 126 | |
| 127 | |
| 128 | /* Declared elsewhere |
| 129 | |
| 130 | PyAPI_FUNC(int) PyCallable_Check(PyObject *o); |
| 131 | |
| 132 | Determine if the object, o, is callable. Return 1 if the object is callable |
| 133 | and 0 otherwise. |
| 134 | |
| 135 | This function always succeeds. */ |
| 136 | |
| 137 | |
| 138 | #ifdef PY_SSIZE_T_CLEAN |
| 139 | # define PyObject_CallFunction _PyObject_CallFunction_SizeT |
| 140 | # define PyObject_CallMethod _PyObject_CallMethod_SizeT |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 141 | #endif |
| 142 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 143 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 144 | /* Call a callable Python object 'callable' with arguments given by the |
| 145 | tuple 'args' and keywords arguments given by the dictionary 'kwargs'. |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 146 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 147 | 'args' must not be *NULL*, use an empty tuple if no arguments are |
| 148 | needed. If no named arguments are needed, 'kwargs' can be NULL. |
Victor Stinner | 2d0eb65 | 2016-12-06 16:27:24 +0100 | [diff] [blame] | 149 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 150 | This is the equivalent of the Python expression: |
| 151 | callable(*args, **kwargs). */ |
| 152 | PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable, |
| 153 | PyObject *args, PyObject *kwargs); |
| 154 | |
Victor Stinner | 2d0eb65 | 2016-12-06 16:27:24 +0100 | [diff] [blame] | 155 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 156 | /* Call a callable Python object 'callable', with arguments given by the |
| 157 | tuple 'args'. If no arguments are needed, then 'args' can be *NULL*. |
Victor Stinner | 2d0eb65 | 2016-12-06 16:27:24 +0100 | [diff] [blame] | 158 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 159 | Returns the result of the call on success, or *NULL* on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 160 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 161 | This is the equivalent of the Python expression: |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 162 | callable(*args). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 163 | PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable, |
| 164 | PyObject *args); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 165 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 166 | /* Call a callable Python object, callable, with a variable number of C |
| 167 | arguments. The C arguments are described using a mkvalue-style format |
| 168 | string. |
Victor Stinner | 2d0eb65 | 2016-12-06 16:27:24 +0100 | [diff] [blame] | 169 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 170 | The format may be NULL, indicating that no arguments are provided. |
Victor Stinner | 2d0eb65 | 2016-12-06 16:27:24 +0100 | [diff] [blame] | 171 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 172 | Returns the result of the call on success, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 173 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 174 | This is the equivalent of the Python expression: |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 175 | callable(arg1, arg2, ...). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 176 | PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable, |
| 177 | const char *format, ...); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 178 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 179 | /* Call the method named 'name' of object 'obj' with a variable number of |
| 180 | C arguments. The C arguments are described by a mkvalue format string. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 181 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 182 | The format can be NULL, indicating that no arguments are provided. |
Victor Stinner | 2d0eb65 | 2016-12-06 16:27:24 +0100 | [diff] [blame] | 183 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 184 | Returns the result of the call on success, or NULL on failure. |
| 185 | |
| 186 | This is the equivalent of the Python expression: |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 187 | obj.name(arg1, arg2, ...). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 188 | PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *obj, |
| 189 | const char *name, |
| 190 | const char *format, ...); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 191 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 192 | PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable, |
| 193 | const char *format, |
| 194 | ...); |
| 195 | |
| 196 | PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *obj, |
| 197 | const char *name, |
| 198 | const char *format, |
| 199 | ...); |
| 200 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 201 | /* Call a callable Python object 'callable' with a variable number of C |
| 202 | arguments. The C arguments are provided as PyObject* values, terminated |
| 203 | by a NULL. |
Victor Stinner | 2d0eb65 | 2016-12-06 16:27:24 +0100 | [diff] [blame] | 204 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 205 | Returns the result of the call on success, or NULL on failure. |
Victor Stinner | 2d0eb65 | 2016-12-06 16:27:24 +0100 | [diff] [blame] | 206 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 207 | This is the equivalent of the Python expression: |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 208 | callable(arg1, arg2, ...). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 209 | PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable, |
| 210 | ...); |
Fred Drake | b421b8c | 2001-10-26 16:21:32 +0000 | [diff] [blame] | 211 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 212 | /* Call the method named 'name' of object 'obj' with a variable number of |
| 213 | C arguments. The C arguments are provided as PyObject* values, terminated |
| 214 | by NULL. |
| 215 | |
| 216 | Returns the result of the call on success, or NULL on failure. |
| 217 | |
| 218 | This is the equivalent of the Python expression: obj.name(*args). */ |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 219 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 220 | PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs( |
| 221 | PyObject *obj, |
| 222 | PyObject *name, |
| 223 | ...); |
| 224 | |
Victor Stinner | 2d0eb65 | 2016-12-06 16:27:24 +0100 | [diff] [blame] | 225 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 226 | /* Implemented elsewhere: |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 227 | |
Andrew Svetlov | 9508402 | 2017-12-16 21:08:05 +0200 | [diff] [blame] | 228 | Py_hash_t PyObject_Hash(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 229 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 230 | Compute and return the hash, hash_value, of an object, o. On |
| 231 | failure, return -1. |
| 232 | |
| 233 | This is the equivalent of the Python expression: hash(o). */ |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 234 | |
| 235 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 236 | /* Implemented elsewhere: |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 237 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 238 | int PyObject_IsTrue(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 239 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 240 | Returns 1 if the object, o, is considered to be true, 0 if o is |
| 241 | considered to be false and -1 on failure. |
| 242 | |
| 243 | This is equivalent to the Python expression: not not o. */ |
| 244 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 245 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 246 | /* Implemented elsewhere: |
Guido van Rossum | c3d3f96 | 1998-04-09 17:53:59 +0000 | [diff] [blame] | 247 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 248 | int PyObject_Not(PyObject *o); |
Guido van Rossum | c3d3f96 | 1998-04-09 17:53:59 +0000 | [diff] [blame] | 249 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 250 | Returns 0 if the object, o, is considered to be true, 1 if o is |
| 251 | considered to be false and -1 on failure. |
Guido van Rossum | c3d3f96 | 1998-04-09 17:53:59 +0000 | [diff] [blame] | 252 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 253 | This is equivalent to the Python expression: not o. */ |
| 254 | |
| 255 | |
| 256 | /* Get the type of an object. |
| 257 | |
| 258 | On success, returns a type object corresponding to the object type of object |
| 259 | 'o'. On failure, returns NULL. |
| 260 | |
| 261 | This is equivalent to the Python expression: type(o) */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 262 | PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 263 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 264 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 265 | /* Return the size of object 'o'. If the object 'o' provides both sequence and |
| 266 | mapping protocols, the sequence size is returned. |
| 267 | |
| 268 | On error, -1 is returned. |
| 269 | |
| 270 | This is the equivalent to the Python expression: len(o) */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 271 | PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o); |
Jeremy Hylton | 6253f83 | 2000-07-12 12:56:19 +0000 | [diff] [blame] | 272 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 273 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 274 | /* For DLL compatibility */ |
Marc-André Lemburg | cf5f358 | 2000-07-17 09:22:55 +0000 | [diff] [blame] | 275 | #undef PyObject_Length |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 276 | PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o); |
Marc-André Lemburg | cf5f358 | 2000-07-17 09:22:55 +0000 | [diff] [blame] | 277 | #define PyObject_Length PyObject_Size |
| 278 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 279 | /* Return element of 'o' corresponding to the object 'key'. Return NULL |
| 280 | on failure. |
Marc-André Lemburg | cf5f358 | 2000-07-17 09:22:55 +0000 | [diff] [blame] | 281 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 282 | This is the equivalent of the Python expression: o[key] */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 283 | PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 284 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 285 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 286 | /* Map the object 'key' to the value 'v' into 'o'. |
| 287 | |
| 288 | Raise an exception and return -1 on failure; return 0 on success. |
| 289 | |
| 290 | This is the equivalent of the Python statement: o[key]=v. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 291 | PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 292 | |
Serhiy Storchaka | f5b1183 | 2018-05-22 11:02:44 +0300 | [diff] [blame] | 293 | /* Remove the mapping for the string 'key' from the object 'o'. |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 294 | Returns -1 on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 295 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 296 | This is equivalent to the Python statement: del o[key]. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 297 | PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, const char *key); |
Martin v. Löwis | b0d71d0 | 2002-01-05 10:50:30 +0000 | [diff] [blame] | 298 | |
Serhiy Storchaka | f5b1183 | 2018-05-22 11:02:44 +0300 | [diff] [blame] | 299 | /* Delete the mapping for the object 'key' from the object 'o'. |
| 300 | Returns -1 on failure. |
Martin v. Löwis | b0d71d0 | 2002-01-05 10:50:30 +0000 | [diff] [blame] | 301 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 302 | This is the equivalent of the Python statement: del o[key]. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 303 | PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key); |
Guido van Rossum | 6cdc6f4 | 1996-08-21 17:41:54 +0000 | [diff] [blame] | 304 | |
Guido van Rossum | 6cdc6f4 | 1996-08-21 17:41:54 +0000 | [diff] [blame] | 305 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 306 | /* === Old Buffer API ============================================ */ |
| 307 | |
| 308 | /* FIXME: usage of these should all be replaced in Python itself |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 309 | but for backwards compatibility we will implement them. |
| 310 | Their usage without a corresponding "unlock" mechanism |
| 311 | may create issues (but they would already be there). */ |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 312 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 313 | /* Takes an arbitrary object which must support the (character, single segment) |
| 314 | buffer interface and returns a pointer to a read-only memory location |
| 315 | useable as character based input for subsequent processing. |
| 316 | |
| 317 | Return 0 on success. buffer and buffer_len are only set in case no error |
| 318 | occurs. Otherwise, -1 is returned and an exception set. */ |
Zackery Spytz | 3c8724f | 2019-05-28 09:16:33 -0600 | [diff] [blame] | 319 | Py_DEPRECATED(3.0) |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 320 | PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj, |
| 321 | const char **buffer, |
Zackery Spytz | 3c8724f | 2019-05-28 09:16:33 -0600 | [diff] [blame] | 322 | Py_ssize_t *buffer_len); |
Guido van Rossum | fd9eed3 | 2000-03-10 22:35:06 +0000 | [diff] [blame] | 323 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 324 | /* Checks whether an arbitrary object supports the (character, single segment) |
| 325 | buffer interface. |
Guido van Rossum | fd9eed3 | 2000-03-10 22:35:06 +0000 | [diff] [blame] | 326 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 327 | Returns 1 on success, 0 on failure. */ |
Zackery Spytz | 3c8724f | 2019-05-28 09:16:33 -0600 | [diff] [blame] | 328 | Py_DEPRECATED(3.0) PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj); |
Jeremy Hylton | 89c3a22 | 2001-11-09 21:59:42 +0000 | [diff] [blame] | 329 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 330 | /* Same as PyObject_AsCharBuffer() except that this API expects (readable, |
| 331 | single segment) buffer interface and returns a pointer to a read-only memory |
| 332 | location which can contain arbitrary data. |
Jeremy Hylton | 89c3a22 | 2001-11-09 21:59:42 +0000 | [diff] [blame] | 333 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 334 | 0 is returned on success. buffer and buffer_len are only set in case no |
| 335 | error occurs. Otherwise, -1 is returned and an exception set. */ |
Zackery Spytz | 3c8724f | 2019-05-28 09:16:33 -0600 | [diff] [blame] | 336 | Py_DEPRECATED(3.0) |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 337 | PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj, |
| 338 | const void **buffer, |
Zackery Spytz | 3c8724f | 2019-05-28 09:16:33 -0600 | [diff] [blame] | 339 | Py_ssize_t *buffer_len); |
Guido van Rossum | fd9eed3 | 2000-03-10 22:35:06 +0000 | [diff] [blame] | 340 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 341 | /* Takes an arbitrary object which must support the (writable, single segment) |
| 342 | buffer interface and returns a pointer to a writable memory location in |
| 343 | buffer of size 'buffer_len'. |
Guido van Rossum | fd9eed3 | 2000-03-10 22:35:06 +0000 | [diff] [blame] | 344 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 345 | Return 0 on success. buffer and buffer_len are only set in case no error |
| 346 | occurs. Otherwise, -1 is returned and an exception set. */ |
Zackery Spytz | 3c8724f | 2019-05-28 09:16:33 -0600 | [diff] [blame] | 347 | Py_DEPRECATED(3.0) |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 348 | PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj, |
| 349 | void **buffer, |
Zackery Spytz | 3c8724f | 2019-05-28 09:16:33 -0600 | [diff] [blame] | 350 | Py_ssize_t *buffer_len); |
Guido van Rossum | fd9eed3 | 2000-03-10 22:35:06 +0000 | [diff] [blame] | 351 | |
Guido van Rossum | fd9eed3 | 2000-03-10 22:35:06 +0000 | [diff] [blame] | 352 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 353 | /* === New Buffer API ============================================ */ |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 354 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 355 | /* Takes an arbitrary object and returns the result of calling |
| 356 | obj.__format__(format_spec). */ |
| 357 | PyAPI_FUNC(PyObject *) PyObject_Format(PyObject *obj, |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 358 | PyObject *format_spec); |
Eric Smith | 8fd3eba | 2008-02-17 19:48:00 +0000 | [diff] [blame] | 359 | |
Guido van Rossum | 213c7a6 | 2001-04-23 14:08:49 +0000 | [diff] [blame] | 360 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 361 | /* ==== Iterators ================================================ */ |
| 362 | |
| 363 | /* Takes an object and returns an iterator for it. |
| 364 | This is typically a new iterator but if the argument is an iterator, this |
| 365 | returns itself. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 366 | PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *); |
Guido van Rossum | 59d1d2b | 2001-04-20 19:13:02 +0000 | [diff] [blame] | 367 | |
Christian Tismer | ea62ce7 | 2018-06-09 20:32:25 +0200 | [diff] [blame] | 368 | /* Returns 1 if the object 'obj' provides iterator protocols, and 0 otherwise. |
| 369 | |
| 370 | This function always succeeds. */ |
Serhiy Storchaka | 5cbefa9 | 2018-06-11 15:01:47 +0300 | [diff] [blame] | 371 | PyAPI_FUNC(int) PyIter_Check(PyObject *); |
Guido van Rossum | 213c7a6 | 2001-04-23 14:08:49 +0000 | [diff] [blame] | 372 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 373 | /* Takes an iterator object and calls its tp_iternext slot, |
| 374 | returning the next value. |
| 375 | |
| 376 | If the iterator is exhausted, this returns NULL without setting an |
| 377 | exception. |
| 378 | |
| 379 | NULL with an exception means an error occurred. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 380 | PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *); |
Guido van Rossum | 213c7a6 | 2001-04-23 14:08:49 +0000 | [diff] [blame] | 381 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 382 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 383 | /* === Number Protocol ================================================== */ |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 384 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 385 | /* Returns 1 if the object 'o' provides numeric protocols, and 0 otherwise. |
| 386 | |
| 387 | This function always succeeds. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 388 | PyAPI_FUNC(int) PyNumber_Check(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 389 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 390 | /* Returns the result of adding o1 and o2, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 391 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 392 | This is the equivalent of the Python expression: o1 + o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 393 | PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 394 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 395 | /* Returns the result of subtracting o2 from o1, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 396 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 397 | This is the equivalent of the Python expression: o1 - o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 398 | PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 399 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 400 | /* Returns the result of multiplying o1 and o2, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 401 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 402 | This is the equivalent of the Python expression: o1 * o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 403 | PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 404 | |
Serhiy Storchaka | 34d0ac8 | 2016-12-27 14:57:39 +0200 | [diff] [blame] | 405 | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 406 | /* This is the equivalent of the Python expression: o1 @ o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 407 | PyAPI_FUNC(PyObject *) PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2); |
Serhiy Storchaka | 34d0ac8 | 2016-12-27 14:57:39 +0200 | [diff] [blame] | 408 | #endif |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 409 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 410 | /* Returns the result of dividing o1 by o2 giving an integral result, |
| 411 | or NULL on failure. |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 412 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 413 | This is the equivalent of the Python expression: o1 // o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 414 | PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2); |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 415 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 416 | /* Returns the result of dividing o1 by o2 giving a float result, or NULL on |
| 417 | failure. |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 418 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 419 | This is the equivalent of the Python expression: o1 / o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 420 | PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2); |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 421 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 422 | /* Returns the remainder of dividing o1 by o2, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 423 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 424 | This is the equivalent of the Python expression: o1 % o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 425 | PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 426 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 427 | /* See the built-in function divmod. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 428 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 429 | Returns NULL on failure. |
| 430 | |
| 431 | This is the equivalent of the Python expression: divmod(o1, o2). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 432 | PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 433 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 434 | /* See the built-in function pow. Returns NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 435 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 436 | This is the equivalent of the Python expression: pow(o1, o2, o3), |
| 437 | where o3 is optional. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 438 | PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2, |
| 439 | PyObject *o3); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 440 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 441 | /* Returns the negation of o on success, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 442 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 443 | This is the equivalent of the Python expression: -o. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 444 | PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 445 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 446 | /* Returns the positive of o on success, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 447 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 448 | This is the equivalent of the Python expression: +o. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 449 | PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 450 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 451 | /* Returns the absolute value of 'o', or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 452 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 453 | This is the equivalent of the Python expression: abs(o). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 454 | PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 455 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 456 | /* Returns the bitwise negation of 'o' on success, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 457 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 458 | This is the equivalent of the Python expression: ~o. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 459 | PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 460 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 461 | /* Returns the result of left shifting o1 by o2 on success, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 462 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 463 | This is the equivalent of the Python expression: o1 << o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 464 | PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 465 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 466 | /* Returns the result of right shifting o1 by o2 on success, or NULL on |
| 467 | failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 468 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 469 | This is the equivalent of the Python expression: o1 >> o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 470 | PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 471 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 472 | /* Returns the result of bitwise and of o1 and o2 on success, or NULL on |
| 473 | failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 474 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 475 | This is the equivalent of the Python expression: o1 & o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 476 | PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 477 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 478 | /* Returns the bitwise exclusive or of o1 by o2 on success, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 479 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 480 | This is the equivalent of the Python expression: o1 ^ o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 481 | PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 482 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 483 | /* Returns the result of bitwise or on o1 and o2 on success, or NULL on |
| 484 | failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 485 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 486 | This is the equivalent of the Python expression: o1 | o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 487 | PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2); |
| 488 | |
Christian Tismer | ea62ce7 | 2018-06-09 20:32:25 +0200 | [diff] [blame] | 489 | /* Returns 1 if obj is an index integer (has the nb_index slot of the |
| 490 | tp_as_number structure filled in), and 0 otherwise. */ |
Serhiy Storchaka | 5cbefa9 | 2018-06-11 15:01:47 +0300 | [diff] [blame] | 491 | PyAPI_FUNC(int) PyIndex_Check(PyObject *); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 492 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 493 | /* Returns the object 'o' converted to a Python int, or NULL with an exception |
| 494 | raised on failure. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 495 | PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o); |
Guido van Rossum | 38fff8c | 2006-03-07 18:50:55 +0000 | [diff] [blame] | 496 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 497 | /* Returns the object 'o' converted to Py_ssize_t by going through |
| 498 | PyNumber_Index() first. |
Guido van Rossum | 38fff8c | 2006-03-07 18:50:55 +0000 | [diff] [blame] | 499 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 500 | If an overflow error occurs while converting the int to Py_ssize_t, then the |
| 501 | second argument 'exc' is the error-type to return. If it is NULL, then the |
| 502 | overflow error is cleared and the value is clipped. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 503 | PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc); |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 504 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 505 | /* Returns the object 'o' converted to an integer object on success, or NULL |
| 506 | on failure. |
Guido van Rossum | 38fff8c | 2006-03-07 18:50:55 +0000 | [diff] [blame] | 507 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 508 | This is the equivalent of the Python expression: int(o). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 509 | PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o); |
Mark Dickinson | d746768 | 2009-01-10 22:14:33 +0000 | [diff] [blame] | 510 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 511 | /* Returns the object 'o' converted to a float object on success, or NULL |
| 512 | on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 513 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 514 | This is the equivalent of the Python expression: float(o). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 515 | PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 516 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 517 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 518 | /* --- In-place variants of (some of) the above number protocol functions -- */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 519 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 520 | /* Returns the result of adding o2 to o1, possibly in-place, or NULL |
| 521 | on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 522 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 523 | This is the equivalent of the Python expression: o1 += o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 524 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 525 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 526 | /* Returns the result of subtracting o2 from o1, possibly in-place or |
| 527 | NULL on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 528 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 529 | This is the equivalent of the Python expression: o1 -= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 530 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 531 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 532 | /* Returns the result of multiplying o1 by o2, possibly in-place, or NULL on |
| 533 | failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 534 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 535 | This is the equivalent of the Python expression: o1 *= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 536 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 537 | |
Serhiy Storchaka | 34d0ac8 | 2016-12-27 14:57:39 +0200 | [diff] [blame] | 538 | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 539 | /* This is the equivalent of the Python expression: o1 @= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 540 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2); |
Serhiy Storchaka | 34d0ac8 | 2016-12-27 14:57:39 +0200 | [diff] [blame] | 541 | #endif |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 542 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 543 | /* Returns the result of dividing o1 by o2 giving an integral result, possibly |
| 544 | in-place, or NULL on failure. |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 545 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 546 | This is the equivalent of the Python expression: o1 /= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 547 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1, |
| 548 | PyObject *o2); |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 549 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 550 | /* Returns the result of dividing o1 by o2 giving a float result, possibly |
| 551 | in-place, or null on failure. |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 552 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 553 | This is the equivalent of the Python expression: o1 /= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 554 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1, |
| 555 | PyObject *o2); |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 556 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 557 | /* Returns the remainder of dividing o1 by o2, possibly in-place, or NULL on |
| 558 | failure. |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 559 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 560 | This is the equivalent of the Python expression: o1 %= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 561 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 562 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 563 | /* Returns the result of raising o1 to the power of o2, possibly in-place, |
| 564 | or NULL on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 565 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 566 | This is the equivalent of the Python expression: o1 **= o2, |
| 567 | or o1 = pow(o1, o2, o3) if o3 is present. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 568 | PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2, |
| 569 | PyObject *o3); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 570 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 571 | /* Returns the result of left shifting o1 by o2, possibly in-place, or NULL |
| 572 | on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 573 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 574 | This is the equivalent of the Python expression: o1 <<= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 575 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 576 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 577 | /* Returns the result of right shifting o1 by o2, possibly in-place or NULL |
| 578 | on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 579 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 580 | This is the equivalent of the Python expression: o1 >>= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 581 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 582 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 583 | /* Returns the result of bitwise and of o1 and o2, possibly in-place, or NULL |
| 584 | on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 585 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 586 | This is the equivalent of the Python expression: o1 &= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 587 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 588 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 589 | /* Returns the bitwise exclusive or of o1 by o2, possibly in-place, or NULL |
| 590 | on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 591 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 592 | This is the equivalent of the Python expression: o1 ^= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 593 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 594 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 595 | /* Returns the result of bitwise or of o1 and o2, possibly in-place, |
| 596 | or NULL on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 597 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 598 | This is the equivalent of the Python expression: o1 |= o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 599 | PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 600 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 601 | /* Returns the integer n converted to a string with a base, with a base |
| 602 | marker of 0b, 0o or 0x prefixed if applicable. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 603 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 604 | If n is not an int object, it is converted with PyNumber_Index first. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 605 | PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base); |
Guido van Rossum | cd16bf6 | 2007-06-13 18:07:49 +0000 | [diff] [blame] | 606 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 607 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 608 | /* === Sequence protocol ================================================ */ |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 609 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 610 | /* Return 1 if the object provides sequence protocol, and zero |
| 611 | otherwise. |
| 612 | |
| 613 | This function always succeeds. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 614 | PyAPI_FUNC(int) PySequence_Check(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 615 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 616 | /* Return the size of sequence object o, or -1 on failure. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 617 | PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o); |
Jeremy Hylton | 6253f83 | 2000-07-12 12:56:19 +0000 | [diff] [blame] | 618 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 619 | /* For DLL compatibility */ |
Marc-André Lemburg | cf5f358 | 2000-07-17 09:22:55 +0000 | [diff] [blame] | 620 | #undef PySequence_Length |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 621 | PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o); |
Marc-André Lemburg | cf5f358 | 2000-07-17 09:22:55 +0000 | [diff] [blame] | 622 | #define PySequence_Length PySequence_Size |
| 623 | |
| 624 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 625 | /* Return the concatenation of o1 and o2 on success, and NULL on failure. |
| 626 | |
| 627 | This is the equivalent of the Python expression: o1 + o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 628 | PyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 629 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 630 | /* Return the result of repeating sequence object 'o' 'count' times, |
| 631 | or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 632 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 633 | This is the equivalent of the Python expression: o * count. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 634 | PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 635 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 636 | /* Return the ith element of o, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 637 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 638 | This is the equivalent of the Python expression: o[i]. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 639 | PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 640 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 641 | /* Return the slice of sequence object o between i1 and i2, or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 642 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 643 | This is the equivalent of the Python expression: o[i1:i2]. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 644 | PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 645 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 646 | /* Assign object 'v' to the ith element of the sequence 'o'. Raise an exception |
| 647 | and return -1 on failure; return 0 on success. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 648 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 649 | This is the equivalent of the Python statement o[i] = v. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 650 | PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 651 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 652 | /* Delete the 'i'-th element of the sequence 'v'. Returns -1 on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 653 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 654 | This is the equivalent of the Python statement: del o[i]. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 655 | PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i); |
Guido van Rossum | 6cdc6f4 | 1996-08-21 17:41:54 +0000 | [diff] [blame] | 656 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 657 | /* Assign the sequence object 'v' to the slice in sequence object 'o', |
| 658 | from 'i1' to 'i2'. Returns -1 on failure. |
Guido van Rossum | 6cdc6f4 | 1996-08-21 17:41:54 +0000 | [diff] [blame] | 659 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 660 | This is the equivalent of the Python statement: o[i1:i2] = v. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 661 | PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, |
| 662 | PyObject *v); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 663 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 664 | /* Delete the slice in sequence object 'o' from 'i1' to 'i2'. |
| 665 | Returns -1 on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 666 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 667 | This is the equivalent of the Python statement: del o[i1:i2]. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 668 | PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); |
Guido van Rossum | 6cdc6f4 | 1996-08-21 17:41:54 +0000 | [diff] [blame] | 669 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 670 | /* Returns the sequence 'o' as a tuple on success, and NULL on failure. |
Guido van Rossum | 6cdc6f4 | 1996-08-21 17:41:54 +0000 | [diff] [blame] | 671 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 672 | This is equivalent to the Python expression: tuple(o). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 673 | PyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 674 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 675 | /* Returns the sequence 'o' as a list on success, and NULL on failure. |
| 676 | This is equivalent to the Python expression: list(o) */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 677 | PyAPI_FUNC(PyObject *) PySequence_List(PyObject *o); |
Guido van Rossum | f39fc43 | 1997-03-04 18:31:47 +0000 | [diff] [blame] | 678 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 679 | /* Return the sequence 'o' as a list, unless it's already a tuple or list. |
| 680 | |
| 681 | Use PySequence_Fast_GET_ITEM to access the members of this list, and |
| 682 | PySequence_Fast_GET_SIZE to get its length. |
| 683 | |
| 684 | Returns NULL on failure. If the object does not support iteration, raises a |
| 685 | TypeError exception with 'm' as the message text. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 686 | PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m); |
Andrew M. Kuchling | 74042d6 | 2000-06-18 18:43:14 +0000 | [diff] [blame] | 687 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 688 | /* Return the size of the sequence 'o', assuming that 'o' was returned by |
| 689 | PySequence_Fast and is not NULL. */ |
Tim Peters | 1fc240e | 2001-10-26 05:06:50 +0000 | [diff] [blame] | 690 | #define PySequence_Fast_GET_SIZE(o) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 691 | (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o)) |
Tim Peters | 1fc240e | 2001-10-26 05:06:50 +0000 | [diff] [blame] | 692 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 693 | /* Return the 'i'-th element of the sequence 'o', assuming that o was returned |
| 694 | by PySequence_Fast, and that i is within bounds. */ |
Andrew M. Kuchling | 74042d6 | 2000-06-18 18:43:14 +0000 | [diff] [blame] | 695 | #define PySequence_Fast_GET_ITEM(o, i)\ |
| 696 | (PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i)) |
Andrew M. Kuchling | 74042d6 | 2000-06-18 18:43:14 +0000 | [diff] [blame] | 697 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 698 | /* Return a pointer to the underlying item array for |
| 699 | an object retured by PySequence_Fast */ |
Raymond Hettinger | 42bec93 | 2004-03-12 16:38:17 +0000 | [diff] [blame] | 700 | #define PySequence_Fast_ITEMS(sf) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 701 | (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \ |
| 702 | : ((PyTupleObject *)(sf))->ob_item) |
Raymond Hettinger | c1e4f9d | 2004-03-12 08:04:00 +0000 | [diff] [blame] | 703 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 704 | /* Return the number of occurrences on value on 'o', that is, return |
| 705 | the number of keys for which o[key] == value. |
| 706 | |
| 707 | On failure, return -1. This is equivalent to the Python expression: |
| 708 | o.count(value). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 709 | PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 710 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 711 | /* Return 1 if 'ob' is in the sequence 'seq'; 0 if 'ob' is not in the sequence |
| 712 | 'seq'; -1 on error. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 713 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 714 | Use __contains__ if possible, else _PySequence_IterSearch(). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 715 | PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob); |
Tim Peters | cb8d368 | 2001-05-05 21:05:01 +0000 | [diff] [blame] | 716 | |
Guido van Rossum | 8368453 | 1999-03-17 18:44:39 +0000 | [diff] [blame] | 717 | /* For DLL-level backwards compatibility */ |
| 718 | #undef PySequence_In |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 719 | /* Determine if the sequence 'o' contains 'value'. If an item in 'o' is equal |
| 720 | to 'value', return 1, otherwise return 0. On error, return -1. |
| 721 | |
| 722 | This is equivalent to the Python expression: value in o. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 723 | PyAPI_FUNC(int) PySequence_In(PyObject *o, PyObject *value); |
Guido van Rossum | 8368453 | 1999-03-17 18:44:39 +0000 | [diff] [blame] | 724 | |
| 725 | /* For source-level backwards compatibility */ |
Guido van Rossum | f1536db | 1998-08-23 22:06:59 +0000 | [diff] [blame] | 726 | #define PySequence_In PySequence_Contains |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 727 | |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 728 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 729 | /* Return the first index for which o[i] == value. |
| 730 | On error, return -1. |
| 731 | |
| 732 | This is equivalent to the Python expression: o.index(value). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 733 | PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 734 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 735 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 736 | /* --- In-place versions of some of the above Sequence functions --- */ |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 737 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 738 | /* Append sequence 'o2' to sequence 'o1', in-place when possible. Return the |
| 739 | resulting object, which could be 'o1', or NULL on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 740 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 741 | This is the equivalent of the Python expression: o1 += o2. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 742 | PyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 743 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 744 | /* Repeat sequence 'o' by 'count', in-place when possible. Return the resulting |
| 745 | object, which could be 'o', or NULL on failure. |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 746 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 747 | This is the equivalent of the Python expression: o1 *= count. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 748 | PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count); |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 749 | |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 750 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 751 | /* === Mapping protocol ================================================= */ |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 752 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 753 | /* Return 1 if the object provides mapping protocol, and 0 otherwise. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 754 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 755 | This function always succeeds. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 756 | PyAPI_FUNC(int) PyMapping_Check(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 757 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 758 | /* Returns the number of keys in mapping object 'o' on success, and -1 on |
Serhiy Storchaka | f5b1183 | 2018-05-22 11:02:44 +0300 | [diff] [blame] | 759 | failure. This is equivalent to the Python expression: len(o). */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 760 | PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o); |
Jeremy Hylton | 6253f83 | 2000-07-12 12:56:19 +0000 | [diff] [blame] | 761 | |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 762 | /* For DLL compatibility */ |
Marc-André Lemburg | cf5f358 | 2000-07-17 09:22:55 +0000 | [diff] [blame] | 763 | #undef PyMapping_Length |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 764 | PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o); |
Marc-André Lemburg | cf5f358 | 2000-07-17 09:22:55 +0000 | [diff] [blame] | 765 | #define PyMapping_Length PyMapping_Size |
| 766 | |
| 767 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 768 | /* Implemented as a macro: |
Guido van Rossum | a25e5e9 | 1996-09-06 13:48:38 +0000 | [diff] [blame] | 769 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 770 | int PyMapping_DelItemString(PyObject *o, const char *key); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 771 | |
Serhiy Storchaka | f5b1183 | 2018-05-22 11:02:44 +0300 | [diff] [blame] | 772 | Remove the mapping for the string 'key' from the mapping 'o'. Returns -1 on |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 773 | failure. |
| 774 | |
| 775 | This is equivalent to the Python statement: del o[key]. */ |
Jeremy Hylton | 7c7ee5f | 2001-11-28 16:20:07 +0000 | [diff] [blame] | 776 | #define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K)) |
Guido van Rossum | a25e5e9 | 1996-09-06 13:48:38 +0000 | [diff] [blame] | 777 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 778 | /* Implemented as a macro: |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 779 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 780 | int PyMapping_DelItem(PyObject *o, PyObject *key); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 781 | |
Serhiy Storchaka | f5b1183 | 2018-05-22 11:02:44 +0300 | [diff] [blame] | 782 | Remove the mapping for the object 'key' from the mapping object 'o'. |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 783 | Returns -1 on failure. |
| 784 | |
| 785 | This is equivalent to the Python statement: del o[key]. */ |
Jeremy Hylton | 7c7ee5f | 2001-11-28 16:20:07 +0000 | [diff] [blame] | 786 | #define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K)) |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 787 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 788 | /* On success, return 1 if the mapping object 'o' has the key 'key', |
| 789 | and 0 otherwise. |
| 790 | |
| 791 | This is equivalent to the Python expression: key in o. |
| 792 | |
| 793 | This function always succeeds. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 794 | PyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, const char *key); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 795 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 796 | /* Return 1 if the mapping object has the key 'key', and 0 otherwise. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 797 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 798 | This is equivalent to the Python expression: key in o. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 799 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 800 | This function always succeeds. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 801 | PyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 802 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 803 | /* On success, return a list or tuple of the keys in mapping object 'o'. |
| 804 | On failure, return NULL. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 805 | PyAPI_FUNC(PyObject *) PyMapping_Keys(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 806 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 807 | /* On success, return a list or tuple of the values in mapping object 'o'. |
| 808 | On failure, return NULL. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 809 | PyAPI_FUNC(PyObject *) PyMapping_Values(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 810 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 811 | /* On success, return a list or tuple of the items in mapping object 'o', |
| 812 | where each item is a tuple containing a key-value pair. On failure, return |
| 813 | NULL. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 814 | PyAPI_FUNC(PyObject *) PyMapping_Items(PyObject *o); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 815 | |
Serhiy Storchaka | f5b1183 | 2018-05-22 11:02:44 +0300 | [diff] [blame] | 816 | /* Return element of 'o' corresponding to the string 'key' or NULL on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 817 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 818 | This is the equivalent of the Python expression: o[key]. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 819 | PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o, |
| 820 | const char *key); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 821 | |
Serhiy Storchaka | f5b1183 | 2018-05-22 11:02:44 +0300 | [diff] [blame] | 822 | /* Map the string 'key' to the value 'v' in the mapping 'o'. |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 823 | Returns -1 on failure. |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 824 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 825 | This is the equivalent of the Python statement: o[key]=v. */ |
Victor Stinner | 2a358f8 | 2016-12-06 16:55:39 +0100 | [diff] [blame] | 826 | PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, const char *key, |
| 827 | PyObject *value); |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 828 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 829 | /* isinstance(object, typeorclass) */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 830 | PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass); |
Guido van Rossum | 823649d | 2001-03-21 18:40:58 +0000 | [diff] [blame] | 831 | |
Victor Stinner | 5bef7cd | 2016-12-15 09:14:25 +0100 | [diff] [blame] | 832 | /* issubclass(object, typeorclass) */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 833 | PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass); |
Guido van Rossum | 823649d | 2001-03-21 18:40:58 +0000 | [diff] [blame] | 834 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 835 | #ifndef Py_LIMITED_API |
Victor Stinner | 4060283 | 2018-11-26 22:42:04 +0100 | [diff] [blame] | 836 | # define Py_CPYTHON_ABSTRACTOBJECT_H |
| 837 | # include "cpython/abstract.h" |
| 838 | # undef Py_CPYTHON_ABSTRACTOBJECT_H |
| 839 | #endif |
Antoine Pitrou | f68c2a7 | 2010-09-01 12:58:21 +0000 | [diff] [blame] | 840 | |
Guido van Rossum | 8ca687a | 1995-09-18 21:20:02 +0000 | [diff] [blame] | 841 | #ifdef __cplusplus |
| 842 | } |
| 843 | #endif |
Guido van Rossum | a827537 | 1995-07-18 14:07:00 +0000 | [diff] [blame] | 844 | #endif /* Py_ABSTRACTOBJECT_H */ |