Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/python3.14/abstract.h
1 /* Abstract Object Interface (many thanks to Jim Fulton) */ 2 3 #ifndef Py_ABSTRACTOBJECT_H 4 #define Py_ABSTRACTOBJECT_H 5 #ifdef __cplusplus 6 extern "C" { 7 #endif 8 9 /* === Object Protocol ================================================== */ 10 11 /* Implemented elsewhere: 12 13 int PyObject_Print(PyObject *o, FILE *fp, int flags); 14 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. By default (flags=0), PyObject_Print() formats 18 the object by calling PyObject_Repr(). If flags equals to Py_PRINT_RAW, it 19 formats the object by calling PyObject_Str(). */ 20 21 22 /* Implemented elsewhere: 23 24 int PyObject_HasAttrString(PyObject *o, const char *attr_name); 25 26 Returns 1 if object 'o' has the attribute attr_name, and 0 otherwise. 27 28 This is equivalent to the Python expression: hasattr(o,attr_name). 29 30 This function always succeeds. */ 31 32 33 /* Implemented elsewhere: 34 35 PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name); 36 37 Retrieve an attributed named attr_name form object o. 38 Returns the attribute value on success, or NULL on failure. 39 40 This is the equivalent of the Python expression: o.attr_name. */ 41 42 43 /* Implemented elsewhere: 44 45 int PyObject_HasAttr(PyObject *o, PyObject *attr_name); 46 47 Returns 1 if o has the attribute attr_name, and 0 otherwise. 48 49 This is equivalent to the Python expression: hasattr(o,attr_name). 50 51 This function always succeeds. */ 52 53 54 /* Implemented elsewhere: 55 56 int PyObject_HasAttrStringWithError(PyObject *o, const char *attr_name); 57 58 Returns 1 if object 'o' has the attribute attr_name, and 0 otherwise. 59 This is equivalent to the Python expression: hasattr(o,attr_name). 60 Returns -1 on failure. */ 61 62 63 /* Implemented elsewhere: 64 65 int PyObject_HasAttrWithError(PyObject *o, PyObject *attr_name); 66 67 Returns 1 if o has the attribute attr_name, and 0 otherwise. 68 This is equivalent to the Python expression: hasattr(o,attr_name). 69 Returns -1 on failure. */ 70 71 72 /* Implemented elsewhere: 73 74 PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name); 75 76 Retrieve an attributed named 'attr_name' form object 'o'. 77 Returns the attribute value on success, or NULL on failure. 78 79 This is the equivalent of the Python expression: o.attr_name. */ 80 81 82 /* Implemented elsewhere: 83 84 int PyObject_GetOptionalAttr(PyObject *obj, PyObject *attr_name, PyObject **result); 85 86 Variant of PyObject_GetAttr() which doesn't raise AttributeError 87 if the attribute is not found. 88 89 If the attribute is found, return 1 and set *result to a new strong 90 reference to the attribute. 91 If the attribute is not found, return 0 and set *result to NULL; 92 the AttributeError is silenced. 93 If an error other than AttributeError is raised, return -1 and 94 set *result to NULL. 95 */ 96 97 98 /* Implemented elsewhere: 99 100 int PyObject_GetOptionalAttrString(PyObject *obj, const char *attr_name, PyObject **result); 101 102 Variant of PyObject_GetAttrString() which doesn't raise AttributeError 103 if the attribute is not found. 104 105 If the attribute is found, return 1 and set *result to a new strong 106 reference to the attribute. 107 If the attribute is not found, return 0 and set *result to NULL; 108 the AttributeError is silenced. 109 If an error other than AttributeError is raised, return -1 and 110 set *result to NULL. 111 */ 112 113 114 /* Implemented elsewhere: 115 116 int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v); 117 118 Set the value of the attribute named attr_name, for object 'o', 119 to the value 'v'. Raise an exception and return -1 on failure; return 0 on 120 success. 121 122 This is the equivalent of the Python statement o.attr_name=v. */ 123 124 125 /* Implemented elsewhere: 126 127 int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v); 128 129 Set the value of the attribute named attr_name, for object 'o', to the value 130 'v'. an exception and return -1 on failure; return 0 on success. 131 132 This is the equivalent of the Python statement o.attr_name=v. */ 133 134 /* Implemented elsewhere: 135 136 int PyObject_DelAttrString(PyObject *o, const char *attr_name); 137 138 Delete attribute named attr_name, for object o. Returns 139 -1 on failure. 140 141 This is the equivalent of the Python statement: del o.attr_name. 142 143 Implemented as a macro in the limited C API 3.12 and older. */ 144 #if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030d0000 145 # define PyObject_DelAttrString(O, A) PyObject_SetAttrString((O), (A), NULL) 146 #endif 147 148 149 /* Implemented elsewhere: 150 151 int PyObject_DelAttr(PyObject *o, PyObject *attr_name); 152 153 Delete attribute named attr_name, for object o. Returns -1 154 on failure. This is the equivalent of the Python 155 statement: del o.attr_name. 156 157 Implemented as a macro in the limited C API 3.12 and older. */ 158 #if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030d0000 159 # define PyObject_DelAttr(O, A) PyObject_SetAttr((O), (A), NULL) 160 #endif 161 162 163 /* Implemented elsewhere: 164 165 PyObject *PyObject_Repr(PyObject *o); 166 167 Compute the string representation of object 'o'. Returns the 168 string representation on success, NULL on failure. 169 170 This is the equivalent of the Python expression: repr(o). 171 172 Called by the repr() built-in function. */ 173 174 175 /* Implemented elsewhere: 176 177 PyObject *PyObject_Str(PyObject *o); 178 179 Compute the string representation of object, o. Returns the 180 string representation on success, NULL on failure. 181 182 This is the equivalent of the Python expression: str(o). 183 184 Called by the str() and print() built-in functions. */ 185 186 187 /* Declared elsewhere 188 189 PyAPI_FUNC(int) PyCallable_Check(PyObject *o); 190 191 Determine if the object, o, is callable. Return 1 if the object is callable 192 and 0 otherwise. 193 194 This function always succeeds. */ 195 196 197 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000 198 /* Call a callable Python object without any arguments */ 199 PyAPI_FUNC(PyObject *) PyObject_CallNoArgs(PyObject *func); 200 #endif 201 202 203 /* Call a callable Python object 'callable' with arguments given by the 204 tuple 'args' and keywords arguments given by the dictionary 'kwargs'. 205 206 'args' must not be NULL, use an empty tuple if no arguments are 207 needed. If no named arguments are needed, 'kwargs' can be NULL. 208 209 This is the equivalent of the Python expression: 210 callable(*args, **kwargs). */ 211 PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable, 212 PyObject *args, PyObject *kwargs); 213 214 215 /* Call a callable Python object 'callable', with arguments given by the 216 tuple 'args'. If no arguments are needed, then 'args' can be NULL. 217 218 Returns the result of the call on success, or NULL on failure. 219 220 This is the equivalent of the Python expression: 221 callable(*args). */ 222 PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable, 223 PyObject *args); 224 225 /* Call a callable Python object, callable, with a variable number of C 226 arguments. The C arguments are described using a mkvalue-style format 227 string. 228 229 The format may be NULL, indicating that no arguments are provided. 230 231 Returns the result of the call on success, or NULL on failure. 232 233 This is the equivalent of the Python expression: 234 callable(arg1, arg2, ...). */ 235 PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable, 236 const char *format, ...); 237 238 /* Call the method named 'name' of object 'obj' with a variable number of 239 C arguments. The C arguments are described by a mkvalue format string. 240 241 The format can be NULL, indicating that no arguments are provided. 242 243 Returns the result of the call on success, or NULL on failure. 244 245 This is the equivalent of the Python expression: 246 obj.name(arg1, arg2, ...). */ 247 PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *obj, 248 const char *name, 249 const char *format, ...); 250 251 /* Call a callable Python object 'callable' with a variable number of C 252 arguments. The C arguments are provided as PyObject* values, terminated 253 by a NULL. 254 255 Returns the result of the call on success, or NULL on failure. 256 257 This is the equivalent of the Python expression: 258 callable(arg1, arg2, ...). */ 259 PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable, 260 ...); 261 262 /* Call the method named 'name' of object 'obj' with a variable number of 263 C arguments. The C arguments are provided as PyObject* values, terminated 264 by NULL. 265 266 Returns the result of the call on success, or NULL on failure. 267 268 This is the equivalent of the Python expression: obj.name(*args). */ 269 270 PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs( 271 PyObject *obj, 272 PyObject *name, 273 ...); 274 275 /* Given a vectorcall nargsf argument, return the actual number of arguments. 276 * (For use outside the limited API, this is re-defined as a static inline 277 * function in cpython/abstract.h) 278 */ 279 PyAPI_FUNC(Py_ssize_t) PyVectorcall_NARGS(size_t nargsf); 280 281 /* Call "callable" (which must support vectorcall) with positional arguments 282 "tuple" and keyword arguments "dict". "dict" may also be NULL */ 283 PyAPI_FUNC(PyObject *) PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *dict); 284 285 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030C0000 286 #define PY_VECTORCALL_ARGUMENTS_OFFSET \ 287 (_Py_STATIC_CAST(size_t, 1) << (8 * sizeof(size_t) - 1)) 288 289 /* Perform a PEP 590-style vector call on 'callable' */ 290 PyAPI_FUNC(PyObject *) PyObject_Vectorcall( 291 PyObject *callable, 292 PyObject *const *args, 293 size_t nargsf, 294 PyObject *kwnames); 295 296 /* Call the method 'name' on args[0] with arguments in args[1..nargsf-1]. */ 297 PyAPI_FUNC(PyObject *) PyObject_VectorcallMethod( 298 PyObject *name, PyObject *const *args, 299 size_t nargsf, PyObject *kwnames); 300 #endif 301 302 /* Implemented elsewhere: 303 304 Py_hash_t PyObject_Hash(PyObject *o); 305 306 Compute and return the hash, hash_value, of an object, o. On 307 failure, return -1. 308 309 This is the equivalent of the Python expression: hash(o). */ 310 311 312 /* Implemented elsewhere: 313 314 int PyObject_IsTrue(PyObject *o); 315 316 Returns 1 if the object, o, is considered to be true, 0 if o is 317 considered to be false and -1 on failure. 318 319 This is equivalent to the Python expression: not not o. */ 320 321 322 /* Implemented elsewhere: 323 324 int PyObject_Not(PyObject *o); 325 326 Returns 0 if the object, o, is considered to be true, 1 if o is 327 considered to be false and -1 on failure. 328 329 This is equivalent to the Python expression: not o. */ 330 331 332 /* Get the type of an object. 333 334 On success, returns a type object corresponding to the object type of object 335 'o'. On failure, returns NULL. 336 337 This is equivalent to the Python expression: type(o) */ 338 PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o); 339 340 341 /* Return the size of object 'o'. If the object 'o' provides both sequence and 342 mapping protocols, the sequence size is returned. 343 344 On error, -1 is returned. 345 346 This is the equivalent to the Python expression: len(o) */ 347 PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o); 348 349 350 /* For DLL compatibility */ 351 #undef PyObject_Length 352 PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o); 353 #define PyObject_Length PyObject_Size 354 355 /* Return element of 'o' corresponding to the object 'key'. Return NULL 356 on failure. 357 358 This is the equivalent of the Python expression: o[key] */ 359 PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key); 360 361 362 /* Map the object 'key' to the value 'v' into 'o'. 363 364 Raise an exception and return -1 on failure; return 0 on success. 365 366 This is the equivalent of the Python statement: o[key]=v. */ 367 PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v); 368 369 /* Remove the mapping for the string 'key' from the object 'o'. 370 Returns -1 on failure. 371 372 This is equivalent to the Python statement: del o[key]. */ 373 PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, const char *key); 374 375 /* Delete the mapping for the object 'key' from the object 'o'. 376 Returns -1 on failure. 377 378 This is the equivalent of the Python statement: del o[key]. */ 379 PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key); 380 381 382 /* Takes an arbitrary object and returns the result of calling 383 obj.__format__(format_spec). */ 384 PyAPI_FUNC(PyObject *) PyObject_Format(PyObject *obj, 385 PyObject *format_spec); 386 387 388 /* ==== Iterators ================================================ */ 389 390 /* Takes an object and returns an iterator for it. 391 This is typically a new iterator but if the argument is an iterator, this 392 returns itself. */ 393 PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *); 394 395 /* Takes an AsyncIterable object and returns an AsyncIterator for it. 396 This is typically a new iterator but if the argument is an AsyncIterator, 397 this returns itself. */ 398 PyAPI_FUNC(PyObject *) PyObject_GetAIter(PyObject *); 399 400 /* Returns non-zero if the object 'obj' provides iterator protocols, and 0 otherwise. 401 402 This function always succeeds. */ 403 PyAPI_FUNC(int) PyIter_Check(PyObject *); 404 405 /* Returns non-zero if the object 'obj' provides AsyncIterator protocols, and 0 otherwise. 406 407 This function always succeeds. */ 408 PyAPI_FUNC(int) PyAIter_Check(PyObject *); 409 410 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030e0000 411 /* Return 1 and set 'item' to the next item of 'iter' on success. 412 * Return 0 and set 'item' to NULL when there are no remaining values. 413 * Return -1, set 'item' to NULL and set an exception on error. 414 */ 415 PyAPI_FUNC(int) PyIter_NextItem(PyObject *iter, PyObject **item); 416 #endif 417 418 /* Takes an iterator object and calls its tp_iternext slot, 419 returning the next value. 420 421 If the iterator is exhausted, this returns NULL without setting an 422 exception. 423 424 NULL with an exception means an error occurred. 425 426 Prefer PyIter_NextItem() instead. */ 427 PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *); 428 429 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000 430 431 /* Takes generator, coroutine or iterator object and sends the value into it. 432 Returns: 433 - PYGEN_RETURN (0) if generator has returned. 434 'result' parameter is filled with return value 435 - PYGEN_ERROR (-1) if exception was raised. 436 'result' parameter is NULL 437 - PYGEN_NEXT (1) if generator has yielded. 438 'result' parameter is filled with yielded value. */ 439 PyAPI_FUNC(PySendResult) PyIter_Send(PyObject *, PyObject *, PyObject **); 440 #endif 441 442 443 /* === Number Protocol ================================================== */ 444 445 /* Returns 1 if the object 'o' provides numeric protocols, and 0 otherwise. 446 447 This function always succeeds. */ 448 PyAPI_FUNC(int) PyNumber_Check(PyObject *o); 449 450 /* Returns the result of adding o1 and o2, or NULL on failure. 451 452 This is the equivalent of the Python expression: o1 + o2. */ 453 PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2); 454 455 /* Returns the result of subtracting o2 from o1, or NULL on failure. 456 457 This is the equivalent of the Python expression: o1 - o2. */ 458 PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2); 459 460 /* Returns the result of multiplying o1 and o2, or NULL on failure. 461 462 This is the equivalent of the Python expression: o1 * o2. */ 463 PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2); 464 465 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 466 /* This is the equivalent of the Python expression: o1 @ o2. */ 467 PyAPI_FUNC(PyObject *) PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2); 468 #endif 469 470 /* Returns the result of dividing o1 by o2 giving an integral result, 471 or NULL on failure. 472 473 This is the equivalent of the Python expression: o1 // o2. */ 474 PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2); 475 476 /* Returns the result of dividing o1 by o2 giving a float result, or NULL on 477 failure. 478 479 This is the equivalent of the Python expression: o1 / o2. */ 480 PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2); 481 482 /* Returns the remainder of dividing o1 by o2, or NULL on failure. 483 484 This is the equivalent of the Python expression: o1 % o2. */ 485 PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2); 486 487 /* See the built-in function divmod. 488 489 Returns NULL on failure. 490 491 This is the equivalent of the Python expression: divmod(o1, o2). */ 492 PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2); 493 494 /* See the built-in function pow. Returns NULL on failure. 495 496 This is the equivalent of the Python expression: pow(o1, o2, o3), 497 where o3 is optional. */ 498 PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2, 499 PyObject *o3); 500 501 /* Returns the negation of o on success, or NULL on failure. 502 503 This is the equivalent of the Python expression: -o. */ 504 PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o); 505 506 /* Returns the positive of o on success, or NULL on failure. 507 508 This is the equivalent of the Python expression: +o. */ 509 PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o); 510 511 /* Returns the absolute value of 'o', or NULL on failure. 512 513 This is the equivalent of the Python expression: abs(o). */ 514 PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o); 515 516 /* Returns the bitwise negation of 'o' on success, or NULL on failure. 517 518 This is the equivalent of the Python expression: ~o. */ 519 PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o); 520 521 /* Returns the result of left shifting o1 by o2 on success, or NULL on failure. 522 523 This is the equivalent of the Python expression: o1 << o2. */ 524 PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2); 525 526 /* Returns the result of right shifting o1 by o2 on success, or NULL on 527 failure. 528 529 This is the equivalent of the Python expression: o1 >> o2. */ 530 PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2); 531 532 /* Returns the result of bitwise and of o1 and o2 on success, or NULL on 533 failure. 534 535 This is the equivalent of the Python expression: o1 & o2. */ 536 PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2); 537 538 /* Returns the bitwise exclusive or of o1 by o2 on success, or NULL on failure. 539 540 This is the equivalent of the Python expression: o1 ^ o2. */ 541 PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2); 542 543 /* Returns the result of bitwise or on o1 and o2 on success, or NULL on 544 failure. 545 546 This is the equivalent of the Python expression: o1 | o2. */ 547 PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2); 548 549 /* Returns 1 if obj is an index integer (has the nb_index slot of the 550 tp_as_number structure filled in), and 0 otherwise. */ 551 PyAPI_FUNC(int) PyIndex_Check(PyObject *); 552 553 /* Returns the object 'o' converted to a Python int, or NULL with an exception 554 raised on failure. */ 555 PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o); 556 557 /* Returns the object 'o' converted to Py_ssize_t by going through 558 PyNumber_Index() first. 559 560 If an overflow error occurs while converting the int to Py_ssize_t, then the 561 second argument 'exc' is the error-type to return. If it is NULL, then the 562 overflow error is cleared and the value is clipped. */ 563 PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc); 564 565 /* Returns the object 'o' converted to an integer object on success, or NULL 566 on failure. 567 568 This is the equivalent of the Python expression: int(o). */ 569 PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o); 570 571 /* Returns the object 'o' converted to a float object on success, or NULL 572 on failure. 573 574 This is the equivalent of the Python expression: float(o). */ 575 PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o); 576 577 578 /* --- In-place variants of (some of) the above number protocol functions -- */ 579 580 /* Returns the result of adding o2 to o1, possibly in-place, or NULL 581 on failure. 582 583 This is the equivalent of the Python expression: o1 += o2. */ 584 PyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2); 585 586 /* Returns the result of subtracting o2 from o1, possibly in-place or 587 NULL on failure. 588 589 This is the equivalent of the Python expression: o1 -= o2. */ 590 PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2); 591 592 /* Returns the result of multiplying o1 by o2, possibly in-place, or NULL on 593 failure. 594 595 This is the equivalent of the Python expression: o1 *= o2. */ 596 PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2); 597 598 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 599 /* This is the equivalent of the Python expression: o1 @= o2. */ 600 PyAPI_FUNC(PyObject *) PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2); 601 #endif 602 603 /* Returns the result of dividing o1 by o2 giving an integral result, possibly 604 in-place, or NULL on failure. 605 606 This is the equivalent of the Python expression: o1 /= o2. */ 607 PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1, 608 PyObject *o2); 609 610 /* Returns the result of dividing o1 by o2 giving a float result, possibly 611 in-place, or null on failure. 612 613 This is the equivalent of the Python expression: o1 /= o2. */ 614 PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1, 615 PyObject *o2); 616 617 /* Returns the remainder of dividing o1 by o2, possibly in-place, or NULL on 618 failure. 619 620 This is the equivalent of the Python expression: o1 %= o2. */ 621 PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2); 622 623 /* Returns the result of raising o1 to the power of o2, possibly in-place, 624 or NULL on failure. 625 626 This is the equivalent of the Python expression: o1 **= o2, 627 or o1 = pow(o1, o2, o3) if o3 is present. */ 628 PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2, 629 PyObject *o3); 630 631 /* Returns the result of left shifting o1 by o2, possibly in-place, or NULL 632 on failure. 633 634 This is the equivalent of the Python expression: o1 <<= o2. */ 635 PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2); 636 637 /* Returns the result of right shifting o1 by o2, possibly in-place or NULL 638 on failure. 639 640 This is the equivalent of the Python expression: o1 >>= o2. */ 641 PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2); 642 643 /* Returns the result of bitwise and of o1 and o2, possibly in-place, or NULL 644 on failure. 645 646 This is the equivalent of the Python expression: o1 &= o2. */ 647 PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2); 648 649 /* Returns the bitwise exclusive or of o1 by o2, possibly in-place, or NULL 650 on failure. 651 652 This is the equivalent of the Python expression: o1 ^= o2. */ 653 PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2); 654 655 /* Returns the result of bitwise or of o1 and o2, possibly in-place, 656 or NULL on failure. 657 658 This is the equivalent of the Python expression: o1 |= o2. */ 659 PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2); 660 661 /* Returns the integer n converted to a string with a base, with a base 662 marker of 0b, 0o or 0x prefixed if applicable. 663 664 If n is not an int object, it is converted with PyNumber_Index first. */ 665 PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base); 666 667 668 /* === Sequence protocol ================================================ */ 669 670 /* Return 1 if the object provides sequence protocol, and zero 671 otherwise. 672 673 This function always succeeds. */ 674 PyAPI_FUNC(int) PySequence_Check(PyObject *o); 675 676 /* Return the size of sequence object o, or -1 on failure. */ 677 PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o); 678 679 /* For DLL compatibility */ 680 #undef PySequence_Length 681 PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o); 682 #define PySequence_Length PySequence_Size 683 684 685 /* Return the concatenation of o1 and o2 on success, and NULL on failure. 686 687 This is the equivalent of the Python expression: o1 + o2. */ 688 PyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2); 689 690 /* Return the result of repeating sequence object 'o' 'count' times, 691 or NULL on failure. 692 693 This is the equivalent of the Python expression: o * count. */ 694 PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count); 695 696 /* Return the ith element of o, or NULL on failure. 697 698 This is the equivalent of the Python expression: o[i]. */ 699 PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i); 700 701 /* Return the slice of sequence object o between i1 and i2, or NULL on failure. 702 703 This is the equivalent of the Python expression: o[i1:i2]. */ 704 PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); 705 706 /* Assign object 'v' to the ith element of the sequence 'o'. Raise an exception 707 and return -1 on failure; return 0 on success. 708 709 This is the equivalent of the Python statement o[i] = v. */ 710 PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v); 711 712 /* Delete the 'i'-th element of the sequence 'v'. Returns -1 on failure. 713 714 This is the equivalent of the Python statement: del o[i]. */ 715 PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i); 716 717 /* Assign the sequence object 'v' to the slice in sequence object 'o', 718 from 'i1' to 'i2'. Returns -1 on failure. 719 720 This is the equivalent of the Python statement: o[i1:i2] = v. */ 721 PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, 722 PyObject *v); 723 724 /* Delete the slice in sequence object 'o' from 'i1' to 'i2'. 725 Returns -1 on failure. 726 727 This is the equivalent of the Python statement: del o[i1:i2]. */ 728 PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); 729 730 /* Returns the sequence 'o' as a tuple on success, and NULL on failure. 731 732 This is equivalent to the Python expression: tuple(o). */ 733 PyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o); 734 735 /* Returns the sequence 'o' as a list on success, and NULL on failure. 736 This is equivalent to the Python expression: list(o) */ 737 PyAPI_FUNC(PyObject *) PySequence_List(PyObject *o); 738 739 /* Return the sequence 'o' as a list, unless it's already a tuple or list. 740 741 Use PySequence_Fast_GET_ITEM to access the members of this list, and 742 PySequence_Fast_GET_SIZE to get its length. 743 744 Returns NULL on failure. If the object does not support iteration, raises a 745 TypeError exception with 'm' as the message text. */ 746 PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m); 747 748 /* Return the number of occurrences on value on 'o', that is, return 749 the number of keys for which o[key] == value. 750 751 On failure, return -1. This is equivalent to the Python expression: 752 o.count(value). */ 753 PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value); 754 755 /* Return 1 if 'ob' is in the sequence 'seq'; 0 if 'ob' is not in the sequence 756 'seq'; -1 on error. 757 758 Use __contains__ if possible, else _PySequence_IterSearch(). */ 759 PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob); 760 761 /* For DLL-level backwards compatibility */ 762 #undef PySequence_In 763 /* Determine if the sequence 'o' contains 'value'. If an item in 'o' is equal 764 to 'value', return 1, otherwise return 0. On error, return -1. 765 766 This is equivalent to the Python expression: value in o. */ 767 PyAPI_FUNC(int) PySequence_In(PyObject *o, PyObject *value); 768 769 /* For source-level backwards compatibility */ 770 #define PySequence_In PySequence_Contains 771 772 773 /* Return the first index for which o[i] == value. 774 On error, return -1. 775 776 This is equivalent to the Python expression: o.index(value). */ 777 PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value); 778 779 780 /* --- In-place versions of some of the above Sequence functions --- */ 781 782 /* Append sequence 'o2' to sequence 'o1', in-place when possible. Return the 783 resulting object, which could be 'o1', or NULL on failure. 784 785 This is the equivalent of the Python expression: o1 += o2. */ 786 PyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2); 787 788 /* Repeat sequence 'o' by 'count', in-place when possible. Return the resulting 789 object, which could be 'o', or NULL on failure. 790 791 This is the equivalent of the Python expression: o1 *= count. */ 792 PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count); 793 794 795 /* === Mapping protocol ================================================= */ 796 797 /* Return 1 if the object provides mapping protocol, and 0 otherwise. 798 799 This function always succeeds. */ 800 PyAPI_FUNC(int) PyMapping_Check(PyObject *o); 801 802 /* Returns the number of keys in mapping object 'o' on success, and -1 on 803 failure. This is equivalent to the Python expression: len(o). */ 804 PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o); 805 806 /* For DLL compatibility */ 807 #undef PyMapping_Length 808 PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o); 809 #define PyMapping_Length PyMapping_Size 810 811 812 /* Implemented as a macro: 813 814 int PyMapping_DelItemString(PyObject *o, const char *key); 815 816 Remove the mapping for the string 'key' from the mapping 'o'. Returns -1 on 817 failure. 818 819 This is equivalent to the Python statement: del o[key]. */ 820 #define PyMapping_DelItemString(O, K) PyObject_DelItemString((O), (K)) 821 822 /* Implemented as a macro: 823 824 int PyMapping_DelItem(PyObject *o, PyObject *key); 825 826 Remove the mapping for the object 'key' from the mapping object 'o'. 827 Returns -1 on failure. 828 829 This is equivalent to the Python statement: del o[key]. */ 830 #define PyMapping_DelItem(O, K) PyObject_DelItem((O), (K)) 831 832 /* On success, return 1 if the mapping object 'o' has the key 'key', 833 and 0 otherwise. 834 835 This is equivalent to the Python expression: key in o. 836 837 This function always succeeds. */ 838 PyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, const char *key); 839 840 /* Return 1 if the mapping object has the key 'key', and 0 otherwise. 841 842 This is equivalent to the Python expression: key in o. 843 844 This function always succeeds. */ 845 PyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key); 846 847 /* Return 1 if the mapping object has the key 'key', and 0 otherwise. 848 This is equivalent to the Python expression: key in o. 849 On failure, return -1. */ 850 851 PyAPI_FUNC(int) PyMapping_HasKeyWithError(PyObject *o, PyObject *key); 852 853 /* Return 1 if the mapping object has the key 'key', and 0 otherwise. 854 This is equivalent to the Python expression: key in o. 855 On failure, return -1. */ 856 857 PyAPI_FUNC(int) PyMapping_HasKeyStringWithError(PyObject *o, const char *key); 858 859 /* On success, return a list of the keys in mapping object 'o'. 860 On failure, return NULL. */ 861 PyAPI_FUNC(PyObject *) PyMapping_Keys(PyObject *o); 862 863 /* On success, return a list of the values in mapping object 'o'. 864 On failure, return NULL. */ 865 PyAPI_FUNC(PyObject *) PyMapping_Values(PyObject *o); 866 867 /* On success, return a list of the items in mapping object 'o', 868 where each item is a tuple containing a key-value pair. On failure, return 869 NULL. */ 870 PyAPI_FUNC(PyObject *) PyMapping_Items(PyObject *o); 871 872 /* Return element of 'o' corresponding to the string 'key' or NULL on failure. 873 874 This is the equivalent of the Python expression: o[key]. */ 875 PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o, 876 const char *key); 877 878 /* Variants of PyObject_GetItem() and PyMapping_GetItemString() which don't 879 raise KeyError if the key is not found. 880 881 If the key is found, return 1 and set *result to a new strong 882 reference to the corresponding value. 883 If the key is not found, return 0 and set *result to NULL; 884 the KeyError is silenced. 885 If an error other than KeyError is raised, return -1 and 886 set *result to NULL. 887 */ 888 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000 889 PyAPI_FUNC(int) PyMapping_GetOptionalItem(PyObject *, PyObject *, PyObject **); 890 PyAPI_FUNC(int) PyMapping_GetOptionalItemString(PyObject *, const char *, PyObject **); 891 #endif 892 893 /* Map the string 'key' to the value 'v' in the mapping 'o'. 894 Returns -1 on failure. 895 896 This is the equivalent of the Python statement: o[key]=v. */ 897 PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, const char *key, 898 PyObject *value); 899 900 /* isinstance(object, typeorclass) */ 901 PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass); 902 903 /* issubclass(object, typeorclass) */ 904 PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass); 905 906 #ifndef Py_LIMITED_API 907 # define Py_CPYTHON_ABSTRACTOBJECT_H 908 # include "cpython/abstract.h" 909 # undef Py_CPYTHON_ABSTRACTOBJECT_H 910 #endif 911 912 #ifdef __cplusplus 913 } 914 #endif 915 #endif /* Py_ABSTRACTOBJECT_H */