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. 18 19 (What should be said about Py_Print_RAW?). */ 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 /* Implemented elsewhere: 54 55 PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name); 56 57 Retrieve an attributed named 'attr_name' form object 'o'. 58 Returns the attribute value on success, or NULL on failure. 59 60 This is the equivalent of the Python expression: o.attr_name. */ 61 62 63 /* Implemented elsewhere: 64 65 int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v); 66 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. 70 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 141 #endif 142 143 144 /* Call a callable Python object 'callable' with arguments given by the 145 tuple 'args' and keywords arguments given by the dictionary 'kwargs'. 146 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. 149 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 155 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. 158 159 Returns the result of the call on success, or NULL on failure. 160 161 This is the equivalent of the Python expression: 162 callable(*args). */ 163 PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable, 164 PyObject *args); 165 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. 169 170 The format may be NULL, indicating that no arguments are provided. 171 172 Returns the result of the call on success, or NULL on failure. 173 174 This is the equivalent of the Python expression: 175 callable(arg1, arg2, ...). */ 176 PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable, 177 const char *format, ...); 178 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. 181 182 The format can be NULL, indicating that no arguments are provided. 183 184 Returns the result of the call on success, or NULL on failure. 185 186 This is the equivalent of the Python expression: 187 obj.name(arg1, arg2, ...). */ 188 PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *obj, 189 const char *name, 190 const char *format, ...); 191 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 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. 204 205 Returns the result of the call on success, or NULL on failure. 206 207 This is the equivalent of the Python expression: 208 callable(arg1, arg2, ...). */ 209 PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable, 210 ...); 211 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). */ 219 220 PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs( 221 PyObject *obj, 222 PyObject *name, 223 ...); 224 225 226 /* Implemented elsewhere: 227 228 Py_hash_t PyObject_Hash(PyObject *o); 229 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). */ 234 235 236 /* Implemented elsewhere: 237 238 int PyObject_IsTrue(PyObject *o); 239 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 245 246 /* Implemented elsewhere: 247 248 int PyObject_Not(PyObject *o); 249 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. 252 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) */ 262 PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o); 263 264 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) */ 271 PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o); 272 273 274 /* For DLL compatibility */ 275 #undef PyObject_Length 276 PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o); 277 #define PyObject_Length PyObject_Size 278 279 /* Return element of 'o' corresponding to the object 'key'. Return NULL 280 on failure. 281 282 This is the equivalent of the Python expression: o[key] */ 283 PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key); 284 285 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. */ 291 PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v); 292 293 /* Remove the mapping for the string 'key' from the object 'o'. 294 Returns -1 on failure. 295 296 This is equivalent to the Python statement: del o[key]. */ 297 PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, const char *key); 298 299 /* Delete the mapping for the object 'key' from the object 'o'. 300 Returns -1 on failure. 301 302 This is the equivalent of the Python statement: del o[key]. */ 303 PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key); 304 305 306 /* === Old Buffer API ============================================ */ 307 308 /* FIXME: usage of these should all be replaced in Python itself 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). */ 312 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. */ 319 Py_DEPRECATED(3.0) 320 PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj, 321 const char **buffer, 322 Py_ssize_t *buffer_len); 323 324 /* Checks whether an arbitrary object supports the (character, single segment) 325 buffer interface. 326 327 Returns 1 on success, 0 on failure. */ 328 Py_DEPRECATED(3.0) PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj); 329 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. 333 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. */ 336 Py_DEPRECATED(3.0) 337 PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj, 338 const void **buffer, 339 Py_ssize_t *buffer_len); 340 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'. 344 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. */ 347 Py_DEPRECATED(3.0) 348 PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj, 349 void **buffer, 350 Py_ssize_t *buffer_len); 351 352 353 /* === New Buffer API ============================================ */ 354 355 /* Takes an arbitrary object and returns the result of calling 356 obj.__format__(format_spec). */ 357 PyAPI_FUNC(PyObject *) PyObject_Format(PyObject *obj, 358 PyObject *format_spec); 359 360 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. */ 366 PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *); 367 368 /* Returns 1 if the object 'obj' provides iterator protocols, and 0 otherwise. 369 370 This function always succeeds. */ 371 PyAPI_FUNC(int) PyIter_Check(PyObject *); 372 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. */ 380 PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *); 381 382 383 /* === Number Protocol ================================================== */ 384 385 /* Returns 1 if the object 'o' provides numeric protocols, and 0 otherwise. 386 387 This function always succeeds. */ 388 PyAPI_FUNC(int) PyNumber_Check(PyObject *o); 389 390 /* Returns the result of adding o1 and o2, or NULL on failure. 391 392 This is the equivalent of the Python expression: o1 + o2. */ 393 PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2); 394 395 /* Returns the result of subtracting o2 from o1, or NULL on failure. 396 397 This is the equivalent of the Python expression: o1 - o2. */ 398 PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2); 399 400 /* Returns the result of multiplying o1 and o2, or NULL on failure. 401 402 This is the equivalent of the Python expression: o1 * o2. */ 403 PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2); 404 405 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 406 /* This is the equivalent of the Python expression: o1 @ o2. */ 407 PyAPI_FUNC(PyObject *) PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2); 408 #endif 409 410 /* Returns the result of dividing o1 by o2 giving an integral result, 411 or NULL on failure. 412 413 This is the equivalent of the Python expression: o1 // o2. */ 414 PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2); 415 416 /* Returns the result of dividing o1 by o2 giving a float result, or NULL on 417 failure. 418 419 This is the equivalent of the Python expression: o1 / o2. */ 420 PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2); 421 422 /* Returns the remainder of dividing o1 by o2, or NULL on failure. 423 424 This is the equivalent of the Python expression: o1 % o2. */ 425 PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2); 426 427 /* See the built-in function divmod. 428 429 Returns NULL on failure. 430 431 This is the equivalent of the Python expression: divmod(o1, o2). */ 432 PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2); 433 434 /* See the built-in function pow. Returns NULL on failure. 435 436 This is the equivalent of the Python expression: pow(o1, o2, o3), 437 where o3 is optional. */ 438 PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2, 439 PyObject *o3); 440 441 /* Returns the negation of o on success, or NULL on failure. 442 443 This is the equivalent of the Python expression: -o. */ 444 PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o); 445 446 /* Returns the positive of o on success, or NULL on failure. 447 448 This is the equivalent of the Python expression: +o. */ 449 PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o); 450 451 /* Returns the absolute value of 'o', or NULL on failure. 452 453 This is the equivalent of the Python expression: abs(o). */ 454 PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o); 455 456 /* Returns the bitwise negation of 'o' on success, or NULL on failure. 457 458 This is the equivalent of the Python expression: ~o. */ 459 PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o); 460 461 /* Returns the result of left shifting o1 by o2 on success, or NULL on failure. 462 463 This is the equivalent of the Python expression: o1 << o2. */ 464 PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2); 465 466 /* Returns the result of right shifting o1 by o2 on success, or NULL on 467 failure. 468 469 This is the equivalent of the Python expression: o1 >> o2. */ 470 PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2); 471 472 /* Returns the result of bitwise and of o1 and o2 on success, or NULL on 473 failure. 474 475 This is the equivalent of the Python expression: o1 & o2. */ 476 PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2); 477 478 /* Returns the bitwise exclusive or of o1 by o2 on success, or NULL on failure. 479 480 This is the equivalent of the Python expression: o1 ^ o2. */ 481 PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2); 482 483 /* Returns the result of bitwise or on o1 and o2 on success, or NULL on 484 failure. 485 486 This is the equivalent of the Python expression: o1 | o2. */ 487 PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2); 488 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. */ 491 PyAPI_FUNC(int) PyIndex_Check(PyObject *); 492 493 /* Returns the object 'o' converted to a Python int, or NULL with an exception 494 raised on failure. */ 495 PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o); 496 497 /* Returns the object 'o' converted to Py_ssize_t by going through 498 PyNumber_Index() first. 499 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. */ 503 PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc); 504 505 /* Returns the object 'o' converted to an integer object on success, or NULL 506 on failure. 507 508 This is the equivalent of the Python expression: int(o). */ 509 PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o); 510 511 /* Returns the object 'o' converted to a float object on success, or NULL 512 on failure. 513 514 This is the equivalent of the Python expression: float(o). */ 515 PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o); 516 517 518 /* --- In-place variants of (some of) the above number protocol functions -- */ 519 520 /* Returns the result of adding o2 to o1, possibly in-place, or NULL 521 on failure. 522 523 This is the equivalent of the Python expression: o1 += o2. */ 524 PyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2); 525 526 /* Returns the result of subtracting o2 from o1, possibly in-place or 527 NULL on failure. 528 529 This is the equivalent of the Python expression: o1 -= o2. */ 530 PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2); 531 532 /* Returns the result of multiplying o1 by o2, possibly in-place, or NULL on 533 failure. 534 535 This is the equivalent of the Python expression: o1 *= o2. */ 536 PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2); 537 538 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 539 /* This is the equivalent of the Python expression: o1 @= o2. */ 540 PyAPI_FUNC(PyObject *) PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2); 541 #endif 542 543 /* Returns the result of dividing o1 by o2 giving an integral result, possibly 544 in-place, or NULL on failure. 545 546 This is the equivalent of the Python expression: o1 /= o2. */ 547 PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1, 548 PyObject *o2); 549 550 /* Returns the result of dividing o1 by o2 giving a float result, possibly 551 in-place, or null on failure. 552 553 This is the equivalent of the Python expression: o1 /= o2. */ 554 PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1, 555 PyObject *o2); 556 557 /* Returns the remainder of dividing o1 by o2, possibly in-place, or NULL on 558 failure. 559 560 This is the equivalent of the Python expression: o1 %= o2. */ 561 PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2); 562 563 /* Returns the result of raising o1 to the power of o2, possibly in-place, 564 or NULL on failure. 565 566 This is the equivalent of the Python expression: o1 **= o2, 567 or o1 = pow(o1, o2, o3) if o3 is present. */ 568 PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2, 569 PyObject *o3); 570 571 /* Returns the result of left shifting o1 by o2, possibly in-place, or NULL 572 on failure. 573 574 This is the equivalent of the Python expression: o1 <<= o2. */ 575 PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2); 576 577 /* Returns the result of right shifting o1 by o2, possibly in-place or NULL 578 on failure. 579 580 This is the equivalent of the Python expression: o1 >>= o2. */ 581 PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2); 582 583 /* Returns the result of bitwise and of o1 and o2, possibly in-place, or NULL 584 on failure. 585 586 This is the equivalent of the Python expression: o1 &= o2. */ 587 PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2); 588 589 /* Returns the bitwise exclusive or of o1 by o2, possibly in-place, or NULL 590 on failure. 591 592 This is the equivalent of the Python expression: o1 ^= o2. */ 593 PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2); 594 595 /* Returns the result of bitwise or of o1 and o2, possibly in-place, 596 or NULL on failure. 597 598 This is the equivalent of the Python expression: o1 |= o2. */ 599 PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2); 600 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. 603 604 If n is not an int object, it is converted with PyNumber_Index first. */ 605 PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base); 606 607 608 /* === Sequence protocol ================================================ */ 609 610 /* Return 1 if the object provides sequence protocol, and zero 611 otherwise. 612 613 This function always succeeds. */ 614 PyAPI_FUNC(int) PySequence_Check(PyObject *o); 615 616 /* Return the size of sequence object o, or -1 on failure. */ 617 PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o); 618 619 /* For DLL compatibility */ 620 #undef PySequence_Length 621 PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o); 622 #define PySequence_Length PySequence_Size 623 624 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. */ 628 PyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2); 629 630 /* Return the result of repeating sequence object 'o' 'count' times, 631 or NULL on failure. 632 633 This is the equivalent of the Python expression: o * count. */ 634 PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count); 635 636 /* Return the ith element of o, or NULL on failure. 637 638 This is the equivalent of the Python expression: o[i]. */ 639 PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i); 640 641 /* Return the slice of sequence object o between i1 and i2, or NULL on failure. 642 643 This is the equivalent of the Python expression: o[i1:i2]. */ 644 PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); 645 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. 648 649 This is the equivalent of the Python statement o[i] = v. */ 650 PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v); 651 652 /* Delete the 'i'-th element of the sequence 'v'. Returns -1 on failure. 653 654 This is the equivalent of the Python statement: del o[i]. */ 655 PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i); 656 657 /* Assign the sequence object 'v' to the slice in sequence object 'o', 658 from 'i1' to 'i2'. Returns -1 on failure. 659 660 This is the equivalent of the Python statement: o[i1:i2] = v. */ 661 PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, 662 PyObject *v); 663 664 /* Delete the slice in sequence object 'o' from 'i1' to 'i2'. 665 Returns -1 on failure. 666 667 This is the equivalent of the Python statement: del o[i1:i2]. */ 668 PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); 669 670 /* Returns the sequence 'o' as a tuple on success, and NULL on failure. 671 672 This is equivalent to the Python expression: tuple(o). */ 673 PyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o); 674 675 /* Returns the sequence 'o' as a list on success, and NULL on failure. 676 This is equivalent to the Python expression: list(o) */ 677 PyAPI_FUNC(PyObject *) PySequence_List(PyObject *o); 678 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. */ 686 PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m); 687 688 /* Return the size of the sequence 'o', assuming that 'o' was returned by 689 PySequence_Fast and is not NULL. */ 690 #define PySequence_Fast_GET_SIZE(o) \ 691 (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o)) 692 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. */ 695 #define PySequence_Fast_GET_ITEM(o, i)\ 696 (PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i)) 697 698 /* Return a pointer to the underlying item array for 699 an object retured by PySequence_Fast */ 700 #define PySequence_Fast_ITEMS(sf) \ 701 (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \ 702 : ((PyTupleObject *)(sf))->ob_item) 703 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). */ 709 PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value); 710 711 /* Return 1 if 'ob' is in the sequence 'seq'; 0 if 'ob' is not in the sequence 712 'seq'; -1 on error. 713 714 Use __contains__ if possible, else _PySequence_IterSearch(). */ 715 PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob); 716 717 /* For DLL-level backwards compatibility */ 718 #undef PySequence_In 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. */ 723 PyAPI_FUNC(int) PySequence_In(PyObject *o, PyObject *value); 724 725 /* For source-level backwards compatibility */ 726 #define PySequence_In PySequence_Contains 727 728 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). */ 733 PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value); 734 735 736 /* --- In-place versions of some of the above Sequence functions --- */ 737 738 /* Append sequence 'o2' to sequence 'o1', in-place when possible. Return the 739 resulting object, which could be 'o1', or NULL on failure. 740 741 This is the equivalent of the Python expression: o1 += o2. */ 742 PyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2); 743 744 /* Repeat sequence 'o' by 'count', in-place when possible. Return the resulting 745 object, which could be 'o', or NULL on failure. 746 747 This is the equivalent of the Python expression: o1 *= count. */ 748 PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count); 749 750 751 /* === Mapping protocol ================================================= */ 752 753 /* Return 1 if the object provides mapping protocol, and 0 otherwise. 754 755 This function always succeeds. */ 756 PyAPI_FUNC(int) PyMapping_Check(PyObject *o); 757 758 /* Returns the number of keys in mapping object 'o' on success, and -1 on 759 failure. This is equivalent to the Python expression: len(o). */ 760 PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o); 761 762 /* For DLL compatibility */ 763 #undef PyMapping_Length 764 PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o); 765 #define PyMapping_Length PyMapping_Size 766 767 768 /* Implemented as a macro: 769 770 int PyMapping_DelItemString(PyObject *o, const char *key); 771 772 Remove the mapping for the string 'key' from the mapping 'o'. Returns -1 on 773 failure. 774 775 This is equivalent to the Python statement: del o[key]. */ 776 #define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K)) 777 778 /* Implemented as a macro: 779 780 int PyMapping_DelItem(PyObject *o, PyObject *key); 781 782 Remove the mapping for the object 'key' from the mapping object 'o'. 783 Returns -1 on failure. 784 785 This is equivalent to the Python statement: del o[key]. */ 786 #define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K)) 787 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. */ 794 PyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, const char *key); 795 796 /* Return 1 if the mapping object has the key 'key', and 0 otherwise. 797 798 This is equivalent to the Python expression: key in o. 799 800 This function always succeeds. */ 801 PyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key); 802 803 /* On success, return a list or tuple of the keys in mapping object 'o'. 804 On failure, return NULL. */ 805 PyAPI_FUNC(PyObject *) PyMapping_Keys(PyObject *o); 806 807 /* On success, return a list or tuple of the values in mapping object 'o'. 808 On failure, return NULL. */ 809 PyAPI_FUNC(PyObject *) PyMapping_Values(PyObject *o); 810 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. */ 814 PyAPI_FUNC(PyObject *) PyMapping_Items(PyObject *o); 815 816 /* Return element of 'o' corresponding to the string 'key' or NULL on failure. 817 818 This is the equivalent of the Python expression: o[key]. */ 819 PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o, 820 const char *key); 821 822 /* Map the string 'key' to the value 'v' in the mapping 'o'. 823 Returns -1 on failure. 824 825 This is the equivalent of the Python statement: o[key]=v. */ 826 PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, const char *key, 827 PyObject *value); 828 829 /* isinstance(object, typeorclass) */ 830 PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass); 831 832 /* issubclass(object, typeorclass) */ 833 PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass); 834 835 #ifndef Py_LIMITED_API 836 # define Py_CPYTHON_ABSTRACTOBJECT_H 837 # include "cpython/abstract.h" 838 # undef Py_CPYTHON_ABSTRACTOBJECT_H 839 #endif 840 841 #ifdef __cplusplus 842 } 843 #endif 844 #endif /* Py_ABSTRACTOBJECT_H */ 845