1 #ifndef Py_ABSTRACTOBJECT_H 2 #define Py_ABSTRACTOBJECT_H 3 #ifdef __cplusplus 4 extern "C" { 5 #endif 6 7 #ifdef PY_SSIZE_T_CLEAN 8 #define PyObject_CallFunction _PyObject_CallFunction_SizeT 9 #define PyObject_CallMethod _PyObject_CallMethod_SizeT 10 #ifndef Py_LIMITED_API 11 #define _PyObject_CallMethodId _PyObject_CallMethodId_SizeT 12 #endif /* !Py_LIMITED_API */ 13 #endif 14 15 /* Abstract Object Interface (many thanks to Jim Fulton) */ 16 17 /* 18 PROPOSAL: A Generic Python Object Interface for Python C Modules 19 20 Problem 21 22 Python modules written in C that must access Python objects must do 23 so through routines whose interfaces are described by a set of 24 include files. Unfortunately, these routines vary according to the 25 object accessed. To use these routines, the C programmer must check 26 the type of the object being used and must call a routine based on 27 the object type. For example, to access an element of a sequence, 28 the programmer must determine whether the sequence is a list or a 29 tuple: 30 31 if(is_tupleobject(o)) 32 e=gettupleitem(o,i) 33 else if(is_listitem(o)) 34 e=getlistitem(o,i) 35 36 If the programmer wants to get an item from another type of object 37 that provides sequence behavior, there is no clear way to do it 38 correctly. 39 40 The persistent programmer may peruse object.h and find that the 41 _typeobject structure provides a means of invoking up to (currently 42 about) 41 special operators. So, for example, a routine can get an 43 item from any object that provides sequence behavior. However, to 44 use this mechanism, the programmer must make their code dependent on 45 the current Python implementation. 46 47 Also, certain semantics, especially memory management semantics, may 48 differ by the type of object being used. Unfortunately, these 49 semantics are not clearly described in the current include files. 50 An abstract interface providing more consistent semantics is needed. 51 52 Proposal 53 54 I propose the creation of a standard interface (with an associated 55 library of routines and/or macros) for generically obtaining the 56 services of Python objects. This proposal can be viewed as one 57 components of a Python C interface consisting of several components. 58 59 From the viewpoint of C access to Python services, we have (as 60 suggested by Guido in off-line discussions): 61 62 - "Very high level layer": two or three functions that let you exec or 63 eval arbitrary Python code given as a string in a module whose name is 64 given, passing C values in and getting C values out using 65 mkvalue/getargs style format strings. This does not require the user 66 to declare any variables of type "PyObject *". This should be enough 67 to write a simple application that gets Python code from the user, 68 execs it, and returns the output or errors. (Error handling must also 69 be part of this API.) 70 71 - "Abstract objects layer": which is the subject of this proposal. 72 It has many functions operating on objects, and lest you do many 73 things from C that you can also write in Python, without going 74 through the Python parser. 75 76 - "Concrete objects layer": This is the public type-dependent 77 interface provided by the standard built-in types, such as floats, 78 strings, and lists. This interface exists and is currently 79 documented by the collection of include files provided with the 80 Python distributions. 81 82 From the point of view of Python accessing services provided by C 83 modules: 84 85 - "Python module interface": this interface consist of the basic 86 routines used to define modules and their members. Most of the 87 current extensions-writing guide deals with this interface. 88 89 - "Built-in object interface": this is the interface that a new 90 built-in type must provide and the mechanisms and rules that a 91 developer of a new built-in type must use and follow. 92 93 This proposal is a "first-cut" that is intended to spur 94 discussion. See especially the lists of notes. 95 96 The Python C object interface will provide four protocols: object, 97 numeric, sequence, and mapping. Each protocol consists of a 98 collection of related operations. If an operation that is not 99 provided by a particular type is invoked, then a standard exception, 100 NotImplementedError is raised with an operation name as an argument. 101 In addition, for convenience this interface defines a set of 102 constructors for building objects of built-in types. This is needed 103 so new objects can be returned from C functions that otherwise treat 104 objects generically. 105 106 Memory Management 107 108 For all of the functions described in this proposal, if a function 109 retains a reference to a Python object passed as an argument, then the 110 function will increase the reference count of the object. It is 111 unnecessary for the caller to increase the reference count of an 112 argument in anticipation of the object's retention. 113 114 All Python objects returned from functions should be treated as new 115 objects. Functions that return objects assume that the caller will 116 retain a reference and the reference count of the object has already 117 been incremented to account for this fact. A caller that does not 118 retain a reference to an object that is returned from a function 119 must decrement the reference count of the object (using 120 DECREF(object)) to prevent memory leaks. 121 122 Note that the behavior mentioned here is different from the current 123 behavior for some objects (e.g. lists and tuples) when certain 124 type-specific routines are called directly (e.g. setlistitem). The 125 proposed abstraction layer will provide a consistent memory 126 management interface, correcting for inconsistent behavior for some 127 built-in types. 128 129 Protocols 130 131 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ 132 133 /* Object Protocol: */ 134 135 /* Implemented elsewhere: 136 137 int PyObject_Print(PyObject *o, FILE *fp, int flags); 138 139 Print an object, o, on file, fp. Returns -1 on 140 error. The flags argument is used to enable certain printing 141 options. The only option currently supported is Py_Print_RAW. 142 143 (What should be said about Py_Print_RAW?) 144 145 */ 146 147 /* Implemented elsewhere: 148 149 int PyObject_HasAttrString(PyObject *o, const char *attr_name); 150 151 Returns 1 if o has the attribute attr_name, and 0 otherwise. 152 This is equivalent to the Python expression: 153 hasattr(o,attr_name). 154 155 This function always succeeds. 156 157 */ 158 159 /* Implemented elsewhere: 160 161 PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name); 162 163 Retrieve an attributed named attr_name form object o. 164 Returns the attribute value on success, or NULL on failure. 165 This is the equivalent of the Python expression: o.attr_name. 166 167 */ 168 169 /* Implemented elsewhere: 170 171 int PyObject_HasAttr(PyObject *o, PyObject *attr_name); 172 173 Returns 1 if o has the attribute attr_name, and 0 otherwise. 174 This is equivalent to the Python expression: 175 hasattr(o,attr_name). 176 177 This function always succeeds. 178 179 */ 180 181 /* Implemented elsewhere: 182 183 PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name); 184 185 Retrieve an attributed named attr_name form object o. 186 Returns the attribute value on success, or NULL on failure. 187 This is the equivalent of the Python expression: o.attr_name. 188 189 */ 190 191 192 /* Implemented elsewhere: 193 194 int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v); 195 196 Set the value of the attribute named attr_name, for object o, 197 to the value v. Raise an exception and return -1 on failure; return 0 on 198 success. This is the equivalent of the Python statement o.attr_name=v. 199 200 */ 201 202 /* Implemented elsewhere: 203 204 int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v); 205 206 Set the value of the attribute named attr_name, for object o, 207 to the value v. Raise an exception and return -1 on failure; return 0 on 208 success. This is the equivalent of the Python statement o.attr_name=v. 209 210 */ 211 212 /* implemented as a macro: 213 214 int PyObject_DelAttrString(PyObject *o, const char *attr_name); 215 216 Delete attribute named attr_name, for object o. Returns 217 -1 on failure. This is the equivalent of the Python 218 statement: del o.attr_name. 219 220 */ 221 #define PyObject_DelAttrString(O,A) PyObject_SetAttrString((O),(A),NULL) 222 223 /* implemented as a macro: 224 225 int PyObject_DelAttr(PyObject *o, PyObject *attr_name); 226 227 Delete attribute named attr_name, for object o. Returns -1 228 on failure. This is the equivalent of the Python 229 statement: del o.attr_name. 230 231 */ 232 #define PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A),NULL) 233 234 /* Implemented elsewhere: 235 236 PyObject *PyObject_Repr(PyObject *o); 237 238 Compute the string representation of object, o. Returns the 239 string representation on success, NULL on failure. This is 240 the equivalent of the Python expression: repr(o). 241 242 Called by the repr() built-in function. 243 244 */ 245 246 /* Implemented elsewhere: 247 248 PyObject *PyObject_Str(PyObject *o); 249 250 Compute the string representation of object, o. Returns the 251 string representation on success, NULL on failure. This is 252 the equivalent of the Python expression: str(o).) 253 254 Called by the str() and print() built-in functions. 255 256 */ 257 258 /* Declared elsewhere 259 260 PyAPI_FUNC(int) PyCallable_Check(PyObject *o); 261 262 Determine if the object, o, is callable. Return 1 if the 263 object is callable and 0 otherwise. 264 265 This function always succeeds. 266 */ 267 268 PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable_object, 269 PyObject *args, PyObject *kwargs); 270 271 /* 272 Call a callable Python object, callable_object, with 273 arguments and keywords arguments. The 'args' argument can not be 274 NULL. 275 */ 276 277 #ifndef Py_LIMITED_API 278 PyAPI_FUNC(PyObject*) _PyStack_AsTuple( 279 PyObject **stack, 280 Py_ssize_t nargs); 281 282 /* Convert keyword arguments from the (stack, kwnames) format to a Python 283 dictionary. 284 285 kwnames must only contains str strings, no subclass, and all keys must 286 be unique. kwnames is not checked, usually these checks are done before or later 287 calling _PyStack_AsDict(). For example, _PyArg_ParseStack() raises an 288 error if a key is not a string. */ 289 PyAPI_FUNC(PyObject *) _PyStack_AsDict( 290 PyObject **values, 291 PyObject *kwnames); 292 293 /* Convert (args, nargs, kwargs: dict) into (stack, nargs, kwnames: tuple). 294 295 Return 0 on success, raise an exception and return -1 on error. 296 297 Write the new stack into *p_stack. If *p_stack is differen than args, it 298 must be released by PyMem_Free(). 299 300 The stack uses borrowed references. 301 302 The type of keyword keys is not checked, these checks should be done 303 later (ex: _PyArg_ParseStackAndKeywords). */ 304 PyAPI_FUNC(int) _PyStack_UnpackDict( 305 PyObject **args, 306 Py_ssize_t nargs, 307 PyObject *kwargs, 308 PyObject ***p_stack, 309 PyObject **p_kwnames); 310 311 /* Call the callable object func with the "fast call" calling convention: 312 args is a C array for positional arguments (nargs is the number of 313 positional arguments), kwargs is a dictionary for keyword arguments. 314 315 If nargs is equal to zero, args can be NULL. kwargs can be NULL. 316 nargs must be greater or equal to zero. 317 318 Return the result on success. Raise an exception on return NULL on 319 error. */ 320 PyAPI_FUNC(PyObject *) _PyObject_FastCallDict(PyObject *func, 321 PyObject **args, Py_ssize_t nargs, 322 PyObject *kwargs); 323 324 /* Call the callable object func with the "fast call" calling convention: 325 args is a C array for positional arguments followed by values of 326 keyword arguments. Keys of keyword arguments are stored as a tuple 327 of strings in kwnames. nargs is the number of positional parameters at 328 the beginning of stack. The size of kwnames gives the number of keyword 329 values in the stack after positional arguments. 330 331 kwnames must only contains str strings, no subclass, and all keys must 332 be unique. 333 334 If nargs is equal to zero and there is no keyword argument (kwnames is 335 NULL or its size is zero), args can be NULL. 336 337 Return the result on success. Raise an exception and return NULL on 338 error. */ 339 PyAPI_FUNC(PyObject *) _PyObject_FastCallKeywords 340 (PyObject *func, 341 PyObject **args, 342 Py_ssize_t nargs, 343 PyObject *kwnames); 344 345 #define _PyObject_FastCall(func, args, nargs) \ 346 _PyObject_FastCallDict((func), (args), (nargs), NULL) 347 348 #define _PyObject_CallNoArg(func) \ 349 _PyObject_FastCall((func), NULL, 0) 350 351 #define _PyObject_CallArg1(func, arg) \ 352 _PyObject_FastCall((func), &(arg), 1) 353 354 PyAPI_FUNC(PyObject *) _PyObject_Call_Prepend(PyObject *func, 355 PyObject *obj, PyObject *args, 356 PyObject *kwargs); 357 358 PyAPI_FUNC(PyObject *) _Py_CheckFunctionResult(PyObject *func, 359 PyObject *result, 360 const char *where); 361 #endif /* Py_LIMITED_API */ 362 363 PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable_object, 364 PyObject *args); 365 366 /* 367 Call a callable Python object, callable_object, with 368 arguments given by the tuple, args. If no arguments are 369 needed, then args may be NULL. Returns the result of the 370 call on success, or NULL on failure. This is the equivalent 371 of the Python expression: o(*args). 372 */ 373 374 PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable_object, 375 const char *format, ...); 376 377 /* 378 Call a callable Python object, callable_object, with a 379 variable number of C arguments. The C arguments are described 380 using a mkvalue-style format string. The format may be NULL, 381 indicating that no arguments are provided. Returns the 382 result of the call on success, or NULL on failure. This is 383 the equivalent of the Python expression: o(*args). 384 */ 385 386 387 PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *o, 388 const char *method, 389 const char *format, ...); 390 391 /* 392 Call the method named m of object o with a variable number of 393 C arguments. The C arguments are described by a mkvalue 394 format string. The format may be NULL, indicating that no 395 arguments are provided. Returns the result of the call on 396 success, or NULL on failure. This is the equivalent of the 397 Python expression: o.method(args). 398 */ 399 400 #ifndef Py_LIMITED_API 401 PyAPI_FUNC(PyObject *) _PyObject_CallMethodId(PyObject *o, 402 _Py_Identifier *method, 403 const char *format, ...); 404 405 /* 406 Like PyObject_CallMethod, but expect a _Py_Identifier* as the 407 method name. 408 */ 409 #endif /* !Py_LIMITED_API */ 410 411 PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable, 412 const char *format, 413 ...); 414 PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *o, 415 const char *name, 416 const char *format, 417 ...); 418 #ifndef Py_LIMITED_API 419 PyAPI_FUNC(PyObject *) _PyObject_CallMethodId_SizeT(PyObject *o, 420 _Py_Identifier *name, 421 const char *format, 422 ...); 423 #endif /* !Py_LIMITED_API */ 424 425 PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable, 426 ...); 427 428 /* 429 Call a callable Python object, callable_object, with a 430 variable number of C arguments. The C arguments are provided 431 as PyObject * values, terminated by a NULL. Returns the 432 result of the call on success, or NULL on failure. This is 433 the equivalent of the Python expression: o(*args). 434 */ 435 436 437 PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs(PyObject *o, 438 PyObject *method, ...); 439 #ifndef Py_LIMITED_API 440 PyAPI_FUNC(PyObject *) _PyObject_CallMethodIdObjArgs(PyObject *o, 441 struct _Py_Identifier *method, 442 ...); 443 #endif /* !Py_LIMITED_API */ 444 445 /* 446 Call the method named m of object o with a variable number of 447 C arguments. The C arguments are provided as PyObject * 448 values, terminated by NULL. Returns the result of the call 449 on success, or NULL on failure. This is the equivalent of 450 the Python expression: o.method(args). 451 */ 452 453 454 /* Implemented elsewhere: 455 456 long PyObject_Hash(PyObject *o); 457 458 Compute and return the hash, hash_value, of an object, o. On 459 failure, return -1. This is the equivalent of the Python 460 expression: hash(o). 461 */ 462 463 464 /* Implemented elsewhere: 465 466 int PyObject_IsTrue(PyObject *o); 467 468 Returns 1 if the object, o, is considered to be true, 0 if o is 469 considered to be false and -1 on failure. This is equivalent to the 470 Python expression: not not o 471 */ 472 473 /* Implemented elsewhere: 474 475 int PyObject_Not(PyObject *o); 476 477 Returns 0 if the object, o, is considered to be true, 1 if o is 478 considered to be false and -1 on failure. This is equivalent to the 479 Python expression: not o 480 */ 481 482 PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o); 483 484 /* 485 On success, returns a type object corresponding to the object 486 type of object o. On failure, returns NULL. This is 487 equivalent to the Python expression: type(o). 488 */ 489 490 PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o); 491 492 /* 493 Return the size of object o. If the object, o, provides 494 both sequence and mapping protocols, the sequence size is 495 returned. On error, -1 is returned. This is the equivalent 496 to the Python expression: len(o). 497 */ 498 499 /* For DLL compatibility */ 500 #undef PyObject_Length 501 PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o); 502 #define PyObject_Length PyObject_Size 503 504 #ifndef Py_LIMITED_API 505 PyAPI_FUNC(int) _PyObject_HasLen(PyObject *o); 506 PyAPI_FUNC(Py_ssize_t) PyObject_LengthHint(PyObject *o, Py_ssize_t); 507 #endif 508 509 /* 510 Guess the size of object o using len(o) or o.__length_hint__(). 511 If neither of those return a non-negative value, then return the 512 default value. If one of the calls fails, this function returns -1. 513 */ 514 515 PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key); 516 517 /* 518 Return element of o corresponding to the object, key, or NULL 519 on failure. This is the equivalent of the Python expression: 520 o[key]. 521 */ 522 523 PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v); 524 525 /* 526 Map the object key to the value v. Raise an exception and return -1 527 on failure; return 0 on success. This is the equivalent of the Python 528 statement o[key]=v. 529 */ 530 531 PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, const char *key); 532 533 /* 534 Remove the mapping for object, key, from the object *o. 535 Returns -1 on failure. This is equivalent to 536 the Python statement: del o[key]. 537 */ 538 539 PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key); 540 541 /* 542 Delete the mapping for key from *o. Returns -1 on failure. 543 This is the equivalent of the Python statement: del o[key]. 544 */ 545 546 /* old buffer API 547 FIXME: usage of these should all be replaced in Python itself 548 but for backwards compatibility we will implement them. 549 Their usage without a corresponding "unlock" mechanism 550 may create issues (but they would already be there). */ 551 552 PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj, 553 const char **buffer, 554 Py_ssize_t *buffer_len); 555 556 /* 557 Takes an arbitrary object which must support the (character, 558 single segment) buffer interface and returns a pointer to a 559 read-only memory location useable as character based input 560 for subsequent processing. 561 562 0 is returned on success. buffer and buffer_len are only 563 set in case no error occurs. Otherwise, -1 is returned and 564 an exception set. 565 */ 566 567 PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj); 568 569 /* 570 Checks whether an arbitrary object supports the (character, 571 single segment) buffer interface. Returns 1 on success, 0 572 on failure. 573 */ 574 575 PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj, 576 const void **buffer, 577 Py_ssize_t *buffer_len); 578 579 /* 580 Same as PyObject_AsCharBuffer() except that this API expects 581 (readable, single segment) buffer interface and returns a 582 pointer to a read-only memory location which can contain 583 arbitrary data. 584 585 0 is returned on success. buffer and buffer_len are only 586 set in case no error occurs. Otherwise, -1 is returned and 587 an exception set. 588 */ 589 590 PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj, 591 void **buffer, 592 Py_ssize_t *buffer_len); 593 594 /* 595 Takes an arbitrary object which must support the (writable, 596 single segment) buffer interface and returns a pointer to a 597 writable memory location in buffer of size buffer_len. 598 599 0 is returned on success. buffer and buffer_len are only 600 set in case no error occurs. Otherwise, -1 is returned and 601 an exception set. 602 */ 603 604 /* new buffer API */ 605 606 #ifndef Py_LIMITED_API 607 #define PyObject_CheckBuffer(obj) \ 608 (((obj)->ob_type->tp_as_buffer != NULL) && \ 609 ((obj)->ob_type->tp_as_buffer->bf_getbuffer != NULL)) 610 611 /* Return 1 if the getbuffer function is available, otherwise 612 return 0 */ 613 614 PyAPI_FUNC(int) PyObject_GetBuffer(PyObject *obj, Py_buffer *view, 615 int flags); 616 617 /* This is a C-API version of the getbuffer function call. It checks 618 to make sure object has the required function pointer and issues the 619 call. Returns -1 and raises an error on failure and returns 0 on 620 success 621 */ 622 623 624 PyAPI_FUNC(void *) PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices); 625 626 /* Get the memory area pointed to by the indices for the buffer given. 627 Note that view->ndim is the assumed size of indices 628 */ 629 630 PyAPI_FUNC(int) PyBuffer_SizeFromFormat(const char *); 631 632 /* Return the implied itemsize of the data-format area from a 633 struct-style description */ 634 635 636 637 /* Implementation in memoryobject.c */ 638 PyAPI_FUNC(int) PyBuffer_ToContiguous(void *buf, Py_buffer *view, 639 Py_ssize_t len, char order); 640 641 PyAPI_FUNC(int) PyBuffer_FromContiguous(Py_buffer *view, void *buf, 642 Py_ssize_t len, char order); 643 644 645 /* Copy len bytes of data from the contiguous chunk of memory 646 pointed to by buf into the buffer exported by obj. Return 647 0 on success and return -1 and raise a PyBuffer_Error on 648 error (i.e. the object does not have a buffer interface or 649 it is not working). 650 651 If fort is 'F', then if the object is multi-dimensional, 652 then the data will be copied into the array in 653 Fortran-style (first dimension varies the fastest). If 654 fort is 'C', then the data will be copied into the array 655 in C-style (last dimension varies the fastest). If fort 656 is 'A', then it does not matter and the copy will be made 657 in whatever way is more efficient. 658 659 */ 660 661 PyAPI_FUNC(int) PyObject_CopyData(PyObject *dest, PyObject *src); 662 663 /* Copy the data from the src buffer to the buffer of destination 664 */ 665 666 PyAPI_FUNC(int) PyBuffer_IsContiguous(const Py_buffer *view, char fort); 667 668 669 PyAPI_FUNC(void) PyBuffer_FillContiguousStrides(int ndims, 670 Py_ssize_t *shape, 671 Py_ssize_t *strides, 672 int itemsize, 673 char fort); 674 675 /* Fill the strides array with byte-strides of a contiguous 676 (Fortran-style if fort is 'F' or C-style otherwise) 677 array of the given shape with the given number of bytes 678 per element. 679 */ 680 681 PyAPI_FUNC(int) PyBuffer_FillInfo(Py_buffer *view, PyObject *o, void *buf, 682 Py_ssize_t len, int readonly, 683 int flags); 684 685 /* Fills in a buffer-info structure correctly for an exporter 686 that can only share a contiguous chunk of memory of 687 "unsigned bytes" of the given length. Returns 0 on success 688 and -1 (with raising an error) on error. 689 */ 690 691 PyAPI_FUNC(void) PyBuffer_Release(Py_buffer *view); 692 693 /* Releases a Py_buffer obtained from getbuffer ParseTuple's s*. 694 */ 695 #endif /* Py_LIMITED_API */ 696 697 PyAPI_FUNC(PyObject *) PyObject_Format(PyObject* obj, 698 PyObject *format_spec); 699 /* 700 Takes an arbitrary object and returns the result of 701 calling obj.__format__(format_spec). 702 */ 703 704 /* Iterators */ 705 706 PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *); 707 /* Takes an object and returns an iterator for it. 708 This is typically a new iterator but if the argument 709 is an iterator, this returns itself. */ 710 711 #define PyIter_Check(obj) \ 712 ((obj)->ob_type->tp_iternext != NULL && \ 713 (obj)->ob_type->tp_iternext != &_PyObject_NextNotImplemented) 714 715 PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *); 716 /* Takes an iterator object and calls its tp_iternext slot, 717 returning the next value. If the iterator is exhausted, 718 this returns NULL without setting an exception. 719 NULL with an exception means an error occurred. */ 720 721 /* Number Protocol:*/ 722 723 PyAPI_FUNC(int) PyNumber_Check(PyObject *o); 724 725 /* 726 Returns 1 if the object, o, provides numeric protocols, and 727 false otherwise. 728 729 This function always succeeds. 730 */ 731 732 PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2); 733 734 /* 735 Returns the result of adding o1 and o2, or null on failure. 736 This is the equivalent of the Python expression: o1+o2. 737 */ 738 739 PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2); 740 741 /* 742 Returns the result of subtracting o2 from o1, or null on 743 failure. This is the equivalent of the Python expression: 744 o1-o2. 745 */ 746 747 PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2); 748 749 /* 750 Returns the result of multiplying o1 and o2, or null on 751 failure. This is the equivalent of the Python expression: 752 o1*o2. 753 */ 754 755 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 756 PyAPI_FUNC(PyObject *) PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2); 757 758 /* 759 This is the equivalent of the Python expression: o1 @ o2. 760 */ 761 #endif 762 763 PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2); 764 765 /* 766 Returns the result of dividing o1 by o2 giving an integral result, 767 or null on failure. 768 This is the equivalent of the Python expression: o1//o2. 769 */ 770 771 PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2); 772 773 /* 774 Returns the result of dividing o1 by o2 giving a float result, 775 or null on failure. 776 This is the equivalent of the Python expression: o1/o2. 777 */ 778 779 PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2); 780 781 /* 782 Returns the remainder of dividing o1 by o2, or null on 783 failure. This is the equivalent of the Python expression: 784 o1%o2. 785 */ 786 787 PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2); 788 789 /* 790 See the built-in function divmod. Returns NULL on failure. 791 This is the equivalent of the Python expression: 792 divmod(o1,o2). 793 */ 794 795 PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2, 796 PyObject *o3); 797 798 /* 799 See the built-in function pow. Returns NULL on failure. 800 This is the equivalent of the Python expression: 801 pow(o1,o2,o3), where o3 is optional. 802 */ 803 804 PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o); 805 806 /* 807 Returns the negation of o on success, or null on failure. 808 This is the equivalent of the Python expression: -o. 809 */ 810 811 PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o); 812 813 /* 814 Returns the (what?) of o on success, or NULL on failure. 815 This is the equivalent of the Python expression: +o. 816 */ 817 818 PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o); 819 820 /* 821 Returns the absolute value of o, or null on failure. This is 822 the equivalent of the Python expression: abs(o). 823 */ 824 825 PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o); 826 827 /* 828 Returns the bitwise negation of o on success, or NULL on 829 failure. This is the equivalent of the Python expression: 830 ~o. 831 */ 832 833 PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2); 834 835 /* 836 Returns the result of left shifting o1 by o2 on success, or 837 NULL on failure. This is the equivalent of the Python 838 expression: o1 << o2. 839 */ 840 841 PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2); 842 843 /* 844 Returns the result of right shifting o1 by o2 on success, or 845 NULL on failure. This is the equivalent of the Python 846 expression: o1 >> o2. 847 */ 848 849 PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2); 850 851 /* 852 Returns the result of bitwise and of o1 and o2 on success, or 853 NULL on failure. This is the equivalent of the Python 854 expression: o1&o2. 855 856 */ 857 858 PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2); 859 860 /* 861 Returns the bitwise exclusive or of o1 by o2 on success, or 862 NULL on failure. This is the equivalent of the Python 863 expression: o1^o2. 864 */ 865 866 PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2); 867 868 /* 869 Returns the result of bitwise or on o1 and o2 on success, or 870 NULL on failure. This is the equivalent of the Python 871 expression: o1|o2. 872 */ 873 874 #define PyIndex_Check(obj) \ 875 ((obj)->ob_type->tp_as_number != NULL && \ 876 (obj)->ob_type->tp_as_number->nb_index != NULL) 877 878 PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o); 879 880 /* 881 Returns the object converted to a Python int 882 or NULL with an error raised on failure. 883 */ 884 885 PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc); 886 887 /* 888 Returns the object converted to Py_ssize_t by going through 889 PyNumber_Index first. If an overflow error occurs while 890 converting the int to Py_ssize_t, then the second argument 891 is the error-type to return. If it is NULL, then the overflow error 892 is cleared and the value is clipped. 893 */ 894 895 PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o); 896 897 /* 898 Returns the o converted to an integer object on success, or 899 NULL on failure. This is the equivalent of the Python 900 expression: int(o). 901 */ 902 903 PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o); 904 905 /* 906 Returns the o converted to a float object on success, or NULL 907 on failure. This is the equivalent of the Python expression: 908 float(o). 909 */ 910 911 /* In-place variants of (some of) the above number protocol functions */ 912 913 PyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2); 914 915 /* 916 Returns the result of adding o2 to o1, possibly in-place, or null 917 on failure. This is the equivalent of the Python expression: 918 o1 += o2. 919 */ 920 921 PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2); 922 923 /* 924 Returns the result of subtracting o2 from o1, possibly in-place or 925 null on failure. This is the equivalent of the Python expression: 926 o1 -= o2. 927 */ 928 929 PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2); 930 931 /* 932 Returns the result of multiplying o1 by o2, possibly in-place, or 933 null on failure. This is the equivalent of the Python expression: 934 o1 *= o2. 935 */ 936 937 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 938 PyAPI_FUNC(PyObject *) PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2); 939 940 /* 941 This is the equivalent of the Python expression: o1 @= o2. 942 */ 943 #endif 944 945 PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1, 946 PyObject *o2); 947 948 /* 949 Returns the result of dividing o1 by o2 giving an integral result, 950 possibly in-place, or null on failure. 951 This is the equivalent of the Python expression: 952 o1 /= o2. 953 */ 954 955 PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1, 956 PyObject *o2); 957 958 /* 959 Returns the result of dividing o1 by o2 giving a float result, 960 possibly in-place, or null on failure. 961 This is the equivalent of the Python expression: 962 o1 /= o2. 963 */ 964 965 PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2); 966 967 /* 968 Returns the remainder of dividing o1 by o2, possibly in-place, or 969 null on failure. This is the equivalent of the Python expression: 970 o1 %= o2. 971 */ 972 973 PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2, 974 PyObject *o3); 975 976 /* 977 Returns the result of raising o1 to the power of o2, possibly 978 in-place, or null on failure. This is the equivalent of the Python 979 expression: o1 **= o2, or pow(o1, o2, o3) if o3 is present. 980 */ 981 982 PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2); 983 984 /* 985 Returns the result of left shifting o1 by o2, possibly in-place, or 986 null on failure. This is the equivalent of the Python expression: 987 o1 <<= o2. 988 */ 989 990 PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2); 991 992 /* 993 Returns the result of right shifting o1 by o2, possibly in-place or 994 null on failure. This is the equivalent of the Python expression: 995 o1 >>= o2. 996 */ 997 998 PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2); 999 1000 /* 1001 Returns the result of bitwise and of o1 and o2, possibly in-place, 1002 or null on failure. This is the equivalent of the Python 1003 expression: o1 &= o2. 1004 */ 1005 1006 PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2); 1007 1008 /* 1009 Returns the bitwise exclusive or of o1 by o2, possibly in-place, or 1010 null on failure. This is the equivalent of the Python expression: 1011 o1 ^= o2. 1012 */ 1013 1014 PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2); 1015 1016 /* 1017 Returns the result of bitwise or of o1 and o2, possibly in-place, 1018 or null on failure. This is the equivalent of the Python 1019 expression: o1 |= o2. 1020 */ 1021 1022 PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base); 1023 1024 /* 1025 Returns the integer n converted to a string with a base, with a base 1026 marker of 0b, 0o or 0x prefixed if applicable. 1027 If n is not an int object, it is converted with PyNumber_Index first. 1028 */ 1029 1030 1031 /* Sequence protocol:*/ 1032 1033 PyAPI_FUNC(int) PySequence_Check(PyObject *o); 1034 1035 /* 1036 Return 1 if the object provides sequence protocol, and zero 1037 otherwise. 1038 1039 This function always succeeds. 1040 */ 1041 1042 PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o); 1043 1044 /* 1045 Return the size of sequence object o, or -1 on failure. 1046 */ 1047 1048 /* For DLL compatibility */ 1049 #undef PySequence_Length 1050 PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o); 1051 #define PySequence_Length PySequence_Size 1052 1053 1054 PyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2); 1055 1056 /* 1057 Return the concatenation of o1 and o2 on success, and NULL on 1058 failure. This is the equivalent of the Python 1059 expression: o1+o2. 1060 */ 1061 1062 PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count); 1063 1064 /* 1065 Return the result of repeating sequence object o count times, 1066 or NULL on failure. This is the equivalent of the Python 1067 expression: o1*count. 1068 */ 1069 1070 PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i); 1071 1072 /* 1073 Return the ith element of o, or NULL on failure. This is the 1074 equivalent of the Python expression: o[i]. 1075 */ 1076 1077 PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); 1078 1079 /* 1080 Return the slice of sequence object o between i1 and i2, or 1081 NULL on failure. This is the equivalent of the Python 1082 expression: o[i1:i2]. 1083 */ 1084 1085 PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v); 1086 1087 /* 1088 Assign object v to the ith element of o. Raise an exception and return 1089 -1 on failure; return 0 on success. This is the equivalent of the 1090 Python statement o[i]=v. 1091 */ 1092 1093 PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i); 1094 1095 /* 1096 Delete the ith element of object v. Returns 1097 -1 on failure. This is the equivalent of the Python 1098 statement: del o[i]. 1099 */ 1100 1101 PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, 1102 PyObject *v); 1103 1104 /* 1105 Assign the sequence object, v, to the slice in sequence 1106 object, o, from i1 to i2. Returns -1 on failure. This is the 1107 equivalent of the Python statement: o[i1:i2]=v. 1108 */ 1109 1110 PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); 1111 1112 /* 1113 Delete the slice in sequence object, o, from i1 to i2. 1114 Returns -1 on failure. This is the equivalent of the Python 1115 statement: del o[i1:i2]. 1116 */ 1117 1118 PyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o); 1119 1120 /* 1121 Returns the sequence, o, as a tuple on success, and NULL on failure. 1122 This is equivalent to the Python expression: tuple(o) 1123 */ 1124 1125 1126 PyAPI_FUNC(PyObject *) PySequence_List(PyObject *o); 1127 /* 1128 Returns the sequence, o, as a list on success, and NULL on failure. 1129 This is equivalent to the Python expression: list(o) 1130 */ 1131 1132 PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m); 1133 /* 1134 Return the sequence, o, as a list, unless it's already a 1135 tuple or list. Use PySequence_Fast_GET_ITEM to access the 1136 members of this list, and PySequence_Fast_GET_SIZE to get its length. 1137 1138 Returns NULL on failure. If the object does not support iteration, 1139 raises a TypeError exception with m as the message text. 1140 */ 1141 1142 #define PySequence_Fast_GET_SIZE(o) \ 1143 (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o)) 1144 /* 1145 Return the size of o, assuming that o was returned by 1146 PySequence_Fast and is not NULL. 1147 */ 1148 1149 #define PySequence_Fast_GET_ITEM(o, i)\ 1150 (PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i)) 1151 /* 1152 Return the ith element of o, assuming that o was returned by 1153 PySequence_Fast, and that i is within bounds. 1154 */ 1155 1156 #define PySequence_ITEM(o, i)\ 1157 ( Py_TYPE(o)->tp_as_sequence->sq_item(o, i) ) 1158 /* Assume tp_as_sequence and sq_item exist and that i does not 1159 need to be corrected for a negative index 1160 */ 1161 1162 #define PySequence_Fast_ITEMS(sf) \ 1163 (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \ 1164 : ((PyTupleObject *)(sf))->ob_item) 1165 /* Return a pointer to the underlying item array for 1166 an object retured by PySequence_Fast */ 1167 1168 PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value); 1169 1170 /* 1171 Return the number of occurrences on value on o, that is, 1172 return the number of keys for which o[key]==value. On 1173 failure, return -1. This is equivalent to the Python 1174 expression: o.count(value). 1175 */ 1176 1177 PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob); 1178 /* 1179 Return -1 if error; 1 if ob in seq; 0 if ob not in seq. 1180 Use __contains__ if possible, else _PySequence_IterSearch(). 1181 */ 1182 1183 #ifndef Py_LIMITED_API 1184 #define PY_ITERSEARCH_COUNT 1 1185 #define PY_ITERSEARCH_INDEX 2 1186 #define PY_ITERSEARCH_CONTAINS 3 1187 PyAPI_FUNC(Py_ssize_t) _PySequence_IterSearch(PyObject *seq, 1188 PyObject *obj, int operation); 1189 #endif 1190 /* 1191 Iterate over seq. Result depends on the operation: 1192 PY_ITERSEARCH_COUNT: return # of times obj appears in seq; -1 if 1193 error. 1194 PY_ITERSEARCH_INDEX: return 0-based index of first occurrence of 1195 obj in seq; set ValueError and return -1 if none found; 1196 also return -1 on error. 1197 PY_ITERSEARCH_CONTAINS: return 1 if obj in seq, else 0; -1 on 1198 error. 1199 */ 1200 1201 /* For DLL-level backwards compatibility */ 1202 #undef PySequence_In 1203 PyAPI_FUNC(int) PySequence_In(PyObject *o, PyObject *value); 1204 1205 /* For source-level backwards compatibility */ 1206 #define PySequence_In PySequence_Contains 1207 1208 /* 1209 Determine if o contains value. If an item in o is equal to 1210 X, return 1, otherwise return 0. On error, return -1. This 1211 is equivalent to the Python expression: value in o. 1212 */ 1213 1214 PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value); 1215 1216 /* 1217 Return the first index for which o[i]=value. On error, 1218 return -1. This is equivalent to the Python 1219 expression: o.index(value). 1220 */ 1221 1222 /* In-place versions of some of the above Sequence functions. */ 1223 1224 PyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2); 1225 1226 /* 1227 Append o2 to o1, in-place when possible. Return the resulting 1228 object, which could be o1, or NULL on failure. This is the 1229 equivalent of the Python expression: o1 += o2. 1230 1231 */ 1232 1233 PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count); 1234 1235 /* 1236 Repeat o1 by count, in-place when possible. Return the resulting 1237 object, which could be o1, or NULL on failure. This is the 1238 equivalent of the Python expression: o1 *= count. 1239 1240 */ 1241 1242 /* Mapping protocol:*/ 1243 1244 PyAPI_FUNC(int) PyMapping_Check(PyObject *o); 1245 1246 /* 1247 Return 1 if the object provides mapping protocol, and zero 1248 otherwise. 1249 1250 This function always succeeds. 1251 */ 1252 1253 PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o); 1254 1255 /* 1256 Returns the number of keys in object o on success, and -1 on 1257 failure. For objects that do not provide sequence protocol, 1258 this is equivalent to the Python expression: len(o). 1259 */ 1260 1261 /* For DLL compatibility */ 1262 #undef PyMapping_Length 1263 PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o); 1264 #define PyMapping_Length PyMapping_Size 1265 1266 1267 /* implemented as a macro: 1268 1269 int PyMapping_DelItemString(PyObject *o, const char *key); 1270 1271 Remove the mapping for object, key, from the object *o. 1272 Returns -1 on failure. This is equivalent to 1273 the Python statement: del o[key]. 1274 */ 1275 #define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K)) 1276 1277 /* implemented as a macro: 1278 1279 int PyMapping_DelItem(PyObject *o, PyObject *key); 1280 1281 Remove the mapping for object, key, from the object *o. 1282 Returns -1 on failure. This is equivalent to 1283 the Python statement: del o[key]. 1284 */ 1285 #define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K)) 1286 1287 PyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, const char *key); 1288 1289 /* 1290 On success, return 1 if the mapping object has the key, key, 1291 and 0 otherwise. This is equivalent to the Python expression: 1292 key in o. 1293 1294 This function always succeeds. 1295 */ 1296 1297 PyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key); 1298 1299 /* 1300 Return 1 if the mapping object has the key, key, 1301 and 0 otherwise. This is equivalent to the Python expression: 1302 key in o. 1303 1304 This function always succeeds. 1305 1306 */ 1307 1308 PyAPI_FUNC(PyObject *) PyMapping_Keys(PyObject *o); 1309 1310 /* 1311 On success, return a list or tuple of the keys in object o. 1312 On failure, return NULL. 1313 */ 1314 1315 PyAPI_FUNC(PyObject *) PyMapping_Values(PyObject *o); 1316 1317 /* 1318 On success, return a list or tuple of the values in object o. 1319 On failure, return NULL. 1320 */ 1321 1322 PyAPI_FUNC(PyObject *) PyMapping_Items(PyObject *o); 1323 1324 /* 1325 On success, return a list or tuple of the items in object o, 1326 where each item is a tuple containing a key-value pair. 1327 On failure, return NULL. 1328 1329 */ 1330 1331 PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o, 1332 const char *key); 1333 1334 /* 1335 Return element of o corresponding to the object, key, or NULL 1336 on failure. This is the equivalent of the Python expression: 1337 o[key]. 1338 */ 1339 1340 PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, const char *key, 1341 PyObject *value); 1342 1343 /* 1344 Map the object, key, to the value, v. Returns 1345 -1 on failure. This is the equivalent of the Python 1346 statement: o[key]=v. 1347 */ 1348 1349 1350 PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass); 1351 /* isinstance(object, typeorclass) */ 1352 1353 PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass); 1354 /* issubclass(object, typeorclass) */ 1355 1356 1357 #ifndef Py_LIMITED_API 1358 PyAPI_FUNC(int) _PyObject_RealIsInstance(PyObject *inst, PyObject *cls); 1359 1360 PyAPI_FUNC(int) _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls); 1361 1362 PyAPI_FUNC(char *const *) _PySequence_BytesToCharpArray(PyObject* self); 1363 1364 PyAPI_FUNC(void) _Py_FreeCharPArray(char *const array[]); 1365 1366 /* For internal use by buffer API functions */ 1367 PyAPI_FUNC(void) _Py_add_one_to_index_F(int nd, Py_ssize_t *index, 1368 const Py_ssize_t *shape); 1369 PyAPI_FUNC(void) _Py_add_one_to_index_C(int nd, Py_ssize_t *index, 1370 const Py_ssize_t *shape); 1371 #endif /* !Py_LIMITED_API */ 1372 1373 1374 #ifdef __cplusplus 1375 } 1376 #endif 1377 #endif /* Py_ABSTRACTOBJECT_H */ 1378