| 1 | #ifndef Py_ABSTRACTOBJECT_H |
| 2 | #define Py_ABSTRACTOBJECT_H |
| 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
| 6 | |
| 7 | /* === Object Protocol ================================================== */ |
| 8 | |
| 9 | /* Implemented elsewhere: |
| 10 | |
| 11 | int PyObject_Print(PyObject *o, FILE *fp, int flags); |
| 12 | |
| 13 | Print an object 'o' on file 'fp'. Returns -1 on error. The flags argument |
| 14 | is used to enable certain printing options. The only option currently |
| 15 | supported is Py_Print_RAW. |
| 16 | |
| 17 | (What should be said about Py_Print_RAW?). */ |
| 18 | |
| 19 | |
| 20 | /* Implemented elsewhere: |
| 21 | |
| 22 | int PyObject_HasAttrString(PyObject *o, const char *attr_name); |
| 23 | |
| 24 | Returns 1 if object 'o' has the attribute attr_name, and 0 otherwise. |
| 25 | |
| 26 | This is equivalent to the Python expression: hasattr(o,attr_name). |
| 27 | |
| 28 | This function always succeeds. */ |
| 29 | |
| 30 | |
| 31 | /* Implemented elsewhere: |
| 32 | |
| 33 | PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name); |
| 34 | |
| 35 | Retrieve an attributed named attr_name form object o. |
| 36 | Returns the attribute value on success, or NULL on failure. |
| 37 | |
| 38 | This is the equivalent of the Python expression: o.attr_name. */ |
| 39 | |
| 40 | |
| 41 | /* Implemented elsewhere: |
| 42 | |
| 43 | int PyObject_HasAttr(PyObject *o, PyObject *attr_name); |
| 44 | |
| 45 | Returns 1 if o has the attribute attr_name, and 0 otherwise. |
| 46 | |
| 47 | This is equivalent to the Python expression: hasattr(o,attr_name). |
| 48 | |
| 49 | This function always succeeds. */ |
| 50 | |
| 51 | /* Implemented elsewhere: |
| 52 | |
| 53 | PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name); |
| 54 | |
| 55 | Retrieve an attributed named 'attr_name' form object 'o'. |
| 56 | Returns the attribute value on success, or NULL on failure. |
| 57 | |
| 58 | This is the equivalent of the Python expression: o.attr_name. */ |
| 59 | |
| 60 | |
| 61 | /* Implemented elsewhere: |
| 62 | |
| 63 | int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v); |
| 64 | |
| 65 | Set the value of the attribute named attr_name, for object 'o', |
| 66 | to the value 'v'. Raise an exception and return -1 on failure; return 0 on |
| 67 | success. |
| 68 | |
| 69 | This is the equivalent of the Python statement o.attr_name=v. */ |
| 70 | |
| 71 | |
| 72 | /* Implemented elsewhere: |
| 73 | |
| 74 | int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v); |
| 75 | |
| 76 | Set the value of the attribute named attr_name, for object 'o', to the value |
| 77 | 'v'. an exception and return -1 on failure; return 0 on success. |
| 78 | |
| 79 | This is the equivalent of the Python statement o.attr_name=v. */ |
| 80 | |
| 81 | /* Implemented as a macro: |
| 82 | |
| 83 | int PyObject_DelAttrString(PyObject *o, const char *attr_name); |
| 84 | |
| 85 | Delete attribute named attr_name, for object o. Returns |
| 86 | -1 on failure. |
| 87 | |
| 88 | This is the equivalent of the Python statement: del o.attr_name. */ |
| 89 | #define PyObject_DelAttrString(O,A) PyObject_SetAttrString((O),(A), NULL) |
| 90 | |
| 91 | |
| 92 | /* Implemented as a macro: |
| 93 | |
| 94 | int PyObject_DelAttr(PyObject *o, PyObject *attr_name); |
| 95 | |
| 96 | Delete attribute named attr_name, for object o. Returns -1 |
| 97 | on failure. This is the equivalent of the Python |
| 98 | statement: del o.attr_name. */ |
| 99 | #define PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A), NULL) |
| 100 | |
| 101 | |
| 102 | /* Implemented elsewhere: |
| 103 | |
| 104 | PyObject *PyObject_Repr(PyObject *o); |
| 105 | |
| 106 | Compute the string representation of object 'o'. Returns the |
| 107 | string representation on success, NULL on failure. |
| 108 | |
| 109 | This is the equivalent of the Python expression: repr(o). |
| 110 | |
| 111 | Called by the repr() built-in function. */ |
| 112 | |
| 113 | |
| 114 | /* Implemented elsewhere: |
| 115 | |
| 116 | PyObject *PyObject_Str(PyObject *o); |
| 117 | |
| 118 | Compute the string representation of object, o. Returns the |
| 119 | string representation on success, NULL on failure. |
| 120 | |
| 121 | This is the equivalent of the Python expression: str(o). |
| 122 | |
| 123 | Called by the str() and print() built-in functions. */ |
| 124 | |
| 125 | |
| 126 | /* Declared elsewhere |
| 127 | |
| 128 | PyAPI_FUNC(int) PyCallable_Check(PyObject *o); |
| 129 | |
| 130 | Determine if the object, o, is callable. Return 1 if the object is callable |
| 131 | and 0 otherwise. |
| 132 | |
| 133 | This function always succeeds. */ |
| 134 | |
| 135 | |
| 136 | #ifdef PY_SSIZE_T_CLEAN |
| 137 | #undef PyObject_CallFunction |
| 138 | #undef PyObject_CallMethod |
| 139 | #define PyObject_CallFunction _PyObject_CallFunction_SizeT |
| 140 | #define PyObject_CallMethod _PyObject_CallMethod_SizeT |
| 141 | #endif |
| 142 | |
| 143 | |
| 144 | #ifndef PYPY_VERSION |
| 145 | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000 |
| 146 | /* Call a callable Python object without any arguments */ |
| 147 | PyAPI_FUNC(PyObject *) PyObject_CallNoArgs(PyObject *func); |
| 148 | #endif |
| 149 | #endif |
| 150 | |
| 151 | /* Call a callable Python object 'callable' with arguments given by the |
| 152 | tuple 'args' and keywords arguments given by the dictionary 'kwargs'. |
| 153 | |
| 154 | 'args' must not be NULL, use an empty tuple if no arguments are |
| 155 | needed. If no named arguments are needed, 'kwargs' can be NULL. |
| 156 | |
| 157 | This is the equivalent of the Python expression: |
| 158 | callable(*args, **kwargs). */ |
| 159 | #ifndef PYPY_VERSION |
| 160 | PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable, |
| 161 | PyObject *args, PyObject *kwargs); |
| 162 | #endif |
| 163 | |
| 164 | /* Call a callable Python object 'callable', with arguments given by the |
| 165 | tuple 'args'. If no arguments are needed, then 'args' can be NULL. |
| 166 | |
| 167 | Returns the result of the call on success, or NULL on failure. |
| 168 | |
| 169 | This is the equivalent of the Python expression: |
| 170 | callable(*args). */ |
| 171 | #ifndef PYPY_VERSION |
| 172 | PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable, |
| 173 | PyObject *args); |
| 174 | #endif |
| 175 | |
| 176 | /* Call a callable Python object, callable, with a variable number of C |
| 177 | arguments. The C arguments are described using a mkvalue-style format |
| 178 | string. |
| 179 | |
| 180 | The format may be NULL, indicating that no arguments are provided. |
| 181 | |
| 182 | Returns the result of the call on success, or NULL on failure. |
| 183 | |
| 184 | This is the equivalent of the Python expression: |
| 185 | callable(arg1, arg2, ...). */ |
| 186 | PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable, |
| 187 | const char *format, ...); |
| 188 | |
| 189 | /* Call the method named 'name' of object 'obj' with a variable number of |
| 190 | C arguments. The C arguments are described by a mkvalue format string. |
| 191 | |
| 192 | The format can be NULL, indicating that no arguments are provided. |
| 193 | |
| 194 | Returns the result of the call on success, or NULL on failure. |
| 195 | |
| 196 | This is the equivalent of the Python expression: |
| 197 | obj.name(arg1, arg2, ...). */ |
| 198 | PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *obj, |
| 199 | const char *name, |
| 200 | const char *format, ...); |
| 201 | |
| 202 | PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable, |
| 203 | const char *format, |
| 204 | ...); |
| 205 | |
| 206 | PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *obj, |
| 207 | const char *name, |
| 208 | const char *format, |
| 209 | ...); |
| 210 | |
| 211 | /* Call a callable Python object 'callable' with a variable number of C |
| 212 | arguments. The C arguments are provided as PyObject* values, terminated |
| 213 | by a NULL. |
| 214 | |
| 215 | Returns the result of the call on success, or NULL on failure. |
| 216 | |
| 217 | This is the equivalent of the Python expression: |
| 218 | callable(arg1, arg2, ...). */ |
| 219 | PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable, |
| 220 | ...); |
| 221 | |
| 222 | /* Call the method named 'name' of object 'obj' with a variable number of |
| 223 | C arguments. The C arguments are provided as PyObject* values, terminated |
| 224 | by NULL. |
| 225 | |
| 226 | Returns the result of the call on success, or NULL on failure. |
| 227 | |
| 228 | This is the equivalent of the Python expression: obj.name(*args). */ |
| 229 | |
| 230 | PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs( |
| 231 | PyObject *obj, |
| 232 | PyObject *name, |
| 233 | ...); |
| 234 | |
| 235 | |
| 236 | /* Implemented elsewhere: |
| 237 | |
| 238 | Py_hash_t PyObject_Hash(PyObject *o); |
| 239 | |
| 240 | Compute and return the hash, hash_value, of an object, o. On |
| 241 | failure, return -1. |
| 242 | |
| 243 | This is the equivalent of the Python expression: hash(o). */ |
| 244 | |
| 245 | |
| 246 | /* Implemented elsewhere: |
| 247 | |
| 248 | int PyObject_IsTrue(PyObject *o); |
| 249 | |
| 250 | Returns 1 if the object, o, is considered to be true, 0 if o is |
| 251 | considered to be false and -1 on failure. |
| 252 | |
| 253 | This is equivalent to the Python expression: not not o. */ |
| 254 | |
| 255 | |
| 256 | /* Implemented elsewhere: |
| 257 | |
| 258 | int PyObject_Not(PyObject *o); |
| 259 | |
| 260 | Returns 0 if the object, o, is considered to be true, 1 if o is |
| 261 | considered to be false and -1 on failure. |
| 262 | |
| 263 | This is equivalent to the Python expression: not o. */ |
| 264 | |
| 265 | |
| 266 | /* Get the type of an object. |
| 267 | |
| 268 | On success, returns a type object corresponding to the object type of object |
| 269 | 'o'. On failure, returns NULL. |
| 270 | |
| 271 | This is equivalent to the Python expression: type(o) */ |
| 272 | #ifndef PYPY_VERSION |
| 273 | PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o); |
| 274 | #endif |
| 275 | |
| 276 | |
| 277 | /* Return the size of object 'o'. If the object 'o' provides both sequence and |
| 278 | mapping protocols, the sequence size is returned. |
| 279 | |
| 280 | On error, -1 is returned. |
| 281 | |
| 282 | This is the equivalent to the Python expression: len(o) */ |
| 283 | #ifndef PYPY_VERSION |
| 284 | PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o); |
| 285 | #endif |
| 286 | |
| 287 | |
| 288 | /* For DLL compatibility */ |
| 289 | #undef PyObject_Length |
| 290 | PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o); |
| 291 | #define PyObject_Length PyObject_Size |
| 292 | |
| 293 | |
| 294 | PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, char *key); |
| 295 | |
| 296 | /* === Number Protocol ================================================== */ |
| 297 | |
| 298 | /* Returns 1 if the object 'o' provides numeric protocols, and 0 otherwise. |
| 299 | |
| 300 | This function always succeeds. */ |
| 301 | PyAPI_FUNC(int) PyNumber_Check(PyObject *o); |
| 302 | |
| 303 | |
| 304 | /* Returns 1 if obj is an index integer (has the nb_index slot of the |
| 305 | tp_as_number structure filled in), and 0 otherwise. */ |
| 306 | PyAPI_FUNC(int) PyIndex_Check(PyObject *); |
| 307 | |
| 308 | |
| 309 | /* CPython has these in Include/cpython/abstract.h */ |
| 310 | |
| 311 | #define PY_VECTORCALL_ARGUMENTS_OFFSET ((size_t)1 << (8 * sizeof(size_t) - 1)) |
| 312 | |
| 313 | static inline Py_ssize_t |
| 314 | PyVectorcall_NARGS(size_t n) |
| 315 | { |
| 316 | return n & ~PY_VECTORCALL_ARGUMENTS_OFFSET; |
| 317 | } |
| 318 | |
| 319 | /* Call "callable" (which must support vectorcall) with positional arguments |
| 320 | "tuple" and keyword arguments "dict". "dict" may also be NULL */ |
| 321 | PyAPI_FUNC(PyObject *) PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *dict); |
| 322 | |
| 323 | // Backwards compatibility aliases for API that was provisional in Python 3.8 |
| 324 | #define _PyObject_Vectorcall PyObject_Vectorcall |
| 325 | #define _PyObject_VectorcallMethod PyObject_VectorcallMethod |
| 326 | #define _PyObject_FastCallDict PyObject_VectorcallDict |
| 327 | #define _PyVectorcall_Function PyVectorcall_Function |
| 328 | #define _PyObject_CallOneArg PyObject_CallOneArg |
| 329 | #define _PyObject_CallNoArg PyObject_CallNoArgs |
| 330 | #define _PyObject_CallMethodNoArgs PyObject_CallMethodNoArgs |
| 331 | #define _PyObject_CallMethodOneArg PyObject_CallMethodOneArg |
| 332 | |
| 333 | /* new buffer API */ |
| 334 | |
| 335 | /* Return 1 if the getbuffer function is available, otherwise |
| 336 | return 0 */ |
| 337 | #define PyObject_CheckBuffer(obj) \ |
| 338 | (((obj)->ob_type->tp_as_buffer != NULL) && \ |
| 339 | ((obj)->ob_type->tp_as_buffer->bf_getbuffer != NULL)) |
| 340 | |
| 341 | |
| 342 | /* This is a C-API version of the getbuffer function call. It checks |
| 343 | to make sure object has the required function pointer and issues the |
| 344 | call. Returns -1 and raises an error on failure and returns 0 on |
| 345 | success |
| 346 | */ |
| 347 | PyAPI_FUNC(int) PyObject_GetBuffer(PyObject *obj, Py_buffer *view, |
| 348 | int flags); |
| 349 | |
| 350 | /* Releases a Py_buffer obtained from getbuffer ParseTuple's s*. |
| 351 | */ |
| 352 | PyAPI_FUNC(void) PyBuffer_Release(Py_buffer *view); |
| 353 | |
| 354 | |
| 355 | /* Mapping protocol:*/ |
| 356 | |
| 357 | /* implemented as a macro: |
| 358 | |
| 359 | int PyMapping_DelItemString(PyObject *o, char *key); |
| 360 | |
| 361 | Remove the mapping for object, key, from the object *o. |
| 362 | Returns -1 on failure. This is equivalent to |
| 363 | the Python statement: del o[key]. |
| 364 | */ |
| 365 | #define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K)) |
| 366 | |
| 367 | /* implemented as a macro: |
| 368 | |
| 369 | int PyMapping_DelItem(PyObject *o, PyObject *key); |
| 370 | |
| 371 | Remove the mapping for object, key, from the object *o. |
| 372 | Returns -1 on failure. This is equivalent to |
| 373 | the Python statement: del o[key]. |
| 374 | */ |
| 375 | #define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K)) |
| 376 | |
| 377 | #ifdef __cplusplus |
| 378 | } |
| 379 | #endif |
| 380 | #endif /* Py_ABSTRACTOBJECT_H */ |