|
|
|||
File indexing completed on 2025-11-19 09:50:53
0001 /* Abstract Object Interface (many thanks to Jim Fulton) */ 0002 0003 #ifndef Py_ABSTRACTOBJECT_H 0004 #define Py_ABSTRACTOBJECT_H 0005 #ifdef __cplusplus 0006 extern "C" { 0007 #endif 0008 0009 /* === Object Protocol ================================================== */ 0010 0011 /* Implemented elsewhere: 0012 0013 int PyObject_Print(PyObject *o, FILE *fp, int flags); 0014 0015 Print an object 'o' on file 'fp'. Returns -1 on error. The flags argument 0016 is used to enable certain printing options. The only option currently 0017 supported is Py_PRINT_RAW. By default (flags=0), PyObject_Print() formats 0018 the object by calling PyObject_Repr(). If flags equals to Py_PRINT_RAW, it 0019 formats the object by calling PyObject_Str(). */ 0020 0021 0022 /* Implemented elsewhere: 0023 0024 int PyObject_HasAttrString(PyObject *o, const char *attr_name); 0025 0026 Returns 1 if object 'o' has the attribute attr_name, and 0 otherwise. 0027 0028 This is equivalent to the Python expression: hasattr(o,attr_name). 0029 0030 This function always succeeds. */ 0031 0032 0033 /* Implemented elsewhere: 0034 0035 PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name); 0036 0037 Retrieve an attributed named attr_name form object o. 0038 Returns the attribute value on success, or NULL on failure. 0039 0040 This is the equivalent of the Python expression: o.attr_name. */ 0041 0042 0043 /* Implemented elsewhere: 0044 0045 int PyObject_HasAttr(PyObject *o, PyObject *attr_name); 0046 0047 Returns 1 if o has the attribute attr_name, and 0 otherwise. 0048 0049 This is equivalent to the Python expression: hasattr(o,attr_name). 0050 0051 This function always succeeds. */ 0052 0053 0054 /* Implemented elsewhere: 0055 0056 int PyObject_HasAttrStringWithError(PyObject *o, const char *attr_name); 0057 0058 Returns 1 if object 'o' has the attribute attr_name, and 0 otherwise. 0059 This is equivalent to the Python expression: hasattr(o,attr_name). 0060 Returns -1 on failure. */ 0061 0062 0063 /* Implemented elsewhere: 0064 0065 int PyObject_HasAttrWithError(PyObject *o, PyObject *attr_name); 0066 0067 Returns 1 if o has the attribute attr_name, and 0 otherwise. 0068 This is equivalent to the Python expression: hasattr(o,attr_name). 0069 Returns -1 on failure. */ 0070 0071 0072 /* Implemented elsewhere: 0073 0074 PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name); 0075 0076 Retrieve an attributed named 'attr_name' form object 'o'. 0077 Returns the attribute value on success, or NULL on failure. 0078 0079 This is the equivalent of the Python expression: o.attr_name. */ 0080 0081 0082 /* Implemented elsewhere: 0083 0084 int PyObject_GetOptionalAttr(PyObject *obj, PyObject *attr_name, PyObject **result); 0085 0086 Variant of PyObject_GetAttr() which doesn't raise AttributeError 0087 if the attribute is not found. 0088 0089 If the attribute is found, return 1 and set *result to a new strong 0090 reference to the attribute. 0091 If the attribute is not found, return 0 and set *result to NULL; 0092 the AttributeError is silenced. 0093 If an error other than AttributeError is raised, return -1 and 0094 set *result to NULL. 0095 */ 0096 0097 0098 /* Implemented elsewhere: 0099 0100 int PyObject_GetOptionalAttrString(PyObject *obj, const char *attr_name, PyObject **result); 0101 0102 Variant of PyObject_GetAttrString() which doesn't raise AttributeError 0103 if the attribute is not found. 0104 0105 If the attribute is found, return 1 and set *result to a new strong 0106 reference to the attribute. 0107 If the attribute is not found, return 0 and set *result to NULL; 0108 the AttributeError is silenced. 0109 If an error other than AttributeError is raised, return -1 and 0110 set *result to NULL. 0111 */ 0112 0113 0114 /* Implemented elsewhere: 0115 0116 int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v); 0117 0118 Set the value of the attribute named attr_name, for object 'o', 0119 to the value 'v'. Raise an exception and return -1 on failure; return 0 on 0120 success. 0121 0122 This is the equivalent of the Python statement o.attr_name=v. */ 0123 0124 0125 /* Implemented elsewhere: 0126 0127 int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v); 0128 0129 Set the value of the attribute named attr_name, for object 'o', to the value 0130 'v'. an exception and return -1 on failure; return 0 on success. 0131 0132 This is the equivalent of the Python statement o.attr_name=v. */ 0133 0134 /* Implemented elsewhere: 0135 0136 int PyObject_DelAttrString(PyObject *o, const char *attr_name); 0137 0138 Delete attribute named attr_name, for object o. Returns 0139 -1 on failure. 0140 0141 This is the equivalent of the Python statement: del o.attr_name. 0142 0143 Implemented as a macro in the limited C API 3.12 and older. */ 0144 #if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030d0000 0145 # define PyObject_DelAttrString(O, A) PyObject_SetAttrString((O), (A), NULL) 0146 #endif 0147 0148 0149 /* Implemented elsewhere: 0150 0151 int PyObject_DelAttr(PyObject *o, PyObject *attr_name); 0152 0153 Delete attribute named attr_name, for object o. Returns -1 0154 on failure. This is the equivalent of the Python 0155 statement: del o.attr_name. 0156 0157 Implemented as a macro in the limited C API 3.12 and older. */ 0158 #if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030d0000 0159 # define PyObject_DelAttr(O, A) PyObject_SetAttr((O), (A), NULL) 0160 #endif 0161 0162 0163 /* Implemented elsewhere: 0164 0165 PyObject *PyObject_Repr(PyObject *o); 0166 0167 Compute the string representation of object 'o'. Returns the 0168 string representation on success, NULL on failure. 0169 0170 This is the equivalent of the Python expression: repr(o). 0171 0172 Called by the repr() built-in function. */ 0173 0174 0175 /* Implemented elsewhere: 0176 0177 PyObject *PyObject_Str(PyObject *o); 0178 0179 Compute the string representation of object, o. Returns the 0180 string representation on success, NULL on failure. 0181 0182 This is the equivalent of the Python expression: str(o). 0183 0184 Called by the str() and print() built-in functions. */ 0185 0186 0187 /* Declared elsewhere 0188 0189 PyAPI_FUNC(int) PyCallable_Check(PyObject *o); 0190 0191 Determine if the object, o, is callable. Return 1 if the object is callable 0192 and 0 otherwise. 0193 0194 This function always succeeds. */ 0195 0196 0197 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000 0198 /* Call a callable Python object without any arguments */ 0199 PyAPI_FUNC(PyObject *) PyObject_CallNoArgs(PyObject *func); 0200 #endif 0201 0202 0203 /* Call a callable Python object 'callable' with arguments given by the 0204 tuple 'args' and keywords arguments given by the dictionary 'kwargs'. 0205 0206 'args' must not be NULL, use an empty tuple if no arguments are 0207 needed. If no named arguments are needed, 'kwargs' can be NULL. 0208 0209 This is the equivalent of the Python expression: 0210 callable(*args, **kwargs). */ 0211 PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable, 0212 PyObject *args, PyObject *kwargs); 0213 0214 0215 /* Call a callable Python object 'callable', with arguments given by the 0216 tuple 'args'. If no arguments are needed, then 'args' can be NULL. 0217 0218 Returns the result of the call on success, or NULL on failure. 0219 0220 This is the equivalent of the Python expression: 0221 callable(*args). */ 0222 PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable, 0223 PyObject *args); 0224 0225 /* Call a callable Python object, callable, with a variable number of C 0226 arguments. The C arguments are described using a mkvalue-style format 0227 string. 0228 0229 The format may be NULL, indicating that no arguments are provided. 0230 0231 Returns the result of the call on success, or NULL on failure. 0232 0233 This is the equivalent of the Python expression: 0234 callable(arg1, arg2, ...). */ 0235 PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable, 0236 const char *format, ...); 0237 0238 /* Call the method named 'name' of object 'obj' with a variable number of 0239 C arguments. The C arguments are described by a mkvalue format string. 0240 0241 The format can be NULL, indicating that no arguments are provided. 0242 0243 Returns the result of the call on success, or NULL on failure. 0244 0245 This is the equivalent of the Python expression: 0246 obj.name(arg1, arg2, ...). */ 0247 PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *obj, 0248 const char *name, 0249 const char *format, ...); 0250 0251 /* Call a callable Python object 'callable' with a variable number of C 0252 arguments. The C arguments are provided as PyObject* values, terminated 0253 by a NULL. 0254 0255 Returns the result of the call on success, or NULL on failure. 0256 0257 This is the equivalent of the Python expression: 0258 callable(arg1, arg2, ...). */ 0259 PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable, 0260 ...); 0261 0262 /* Call the method named 'name' of object 'obj' with a variable number of 0263 C arguments. The C arguments are provided as PyObject* values, terminated 0264 by NULL. 0265 0266 Returns the result of the call on success, or NULL on failure. 0267 0268 This is the equivalent of the Python expression: obj.name(*args). */ 0269 0270 PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs( 0271 PyObject *obj, 0272 PyObject *name, 0273 ...); 0274 0275 /* Given a vectorcall nargsf argument, return the actual number of arguments. 0276 * (For use outside the limited API, this is re-defined as a static inline 0277 * function in cpython/abstract.h) 0278 */ 0279 PyAPI_FUNC(Py_ssize_t) PyVectorcall_NARGS(size_t nargsf); 0280 0281 /* Call "callable" (which must support vectorcall) with positional arguments 0282 "tuple" and keyword arguments "dict". "dict" may also be NULL */ 0283 PyAPI_FUNC(PyObject *) PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *dict); 0284 0285 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030C0000 0286 #define PY_VECTORCALL_ARGUMENTS_OFFSET \ 0287 (_Py_STATIC_CAST(size_t, 1) << (8 * sizeof(size_t) - 1)) 0288 0289 /* Perform a PEP 590-style vector call on 'callable' */ 0290 PyAPI_FUNC(PyObject *) PyObject_Vectorcall( 0291 PyObject *callable, 0292 PyObject *const *args, 0293 size_t nargsf, 0294 PyObject *kwnames); 0295 0296 /* Call the method 'name' on args[0] with arguments in args[1..nargsf-1]. */ 0297 PyAPI_FUNC(PyObject *) PyObject_VectorcallMethod( 0298 PyObject *name, PyObject *const *args, 0299 size_t nargsf, PyObject *kwnames); 0300 #endif 0301 0302 /* Implemented elsewhere: 0303 0304 Py_hash_t PyObject_Hash(PyObject *o); 0305 0306 Compute and return the hash, hash_value, of an object, o. On 0307 failure, return -1. 0308 0309 This is the equivalent of the Python expression: hash(o). */ 0310 0311 0312 /* Implemented elsewhere: 0313 0314 int PyObject_IsTrue(PyObject *o); 0315 0316 Returns 1 if the object, o, is considered to be true, 0 if o is 0317 considered to be false and -1 on failure. 0318 0319 This is equivalent to the Python expression: not not o. */ 0320 0321 0322 /* Implemented elsewhere: 0323 0324 int PyObject_Not(PyObject *o); 0325 0326 Returns 0 if the object, o, is considered to be true, 1 if o is 0327 considered to be false and -1 on failure. 0328 0329 This is equivalent to the Python expression: not o. */ 0330 0331 0332 /* Get the type of an object. 0333 0334 On success, returns a type object corresponding to the object type of object 0335 'o'. On failure, returns NULL. 0336 0337 This is equivalent to the Python expression: type(o) */ 0338 PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o); 0339 0340 0341 /* Return the size of object 'o'. If the object 'o' provides both sequence and 0342 mapping protocols, the sequence size is returned. 0343 0344 On error, -1 is returned. 0345 0346 This is the equivalent to the Python expression: len(o) */ 0347 PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o); 0348 0349 0350 /* For DLL compatibility */ 0351 #undef PyObject_Length 0352 PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o); 0353 #define PyObject_Length PyObject_Size 0354 0355 /* Return element of 'o' corresponding to the object 'key'. Return NULL 0356 on failure. 0357 0358 This is the equivalent of the Python expression: o[key] */ 0359 PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key); 0360 0361 0362 /* Map the object 'key' to the value 'v' into 'o'. 0363 0364 Raise an exception and return -1 on failure; return 0 on success. 0365 0366 This is the equivalent of the Python statement: o[key]=v. */ 0367 PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v); 0368 0369 /* Remove the mapping for the string 'key' from the object 'o'. 0370 Returns -1 on failure. 0371 0372 This is equivalent to the Python statement: del o[key]. */ 0373 PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, const char *key); 0374 0375 /* Delete the mapping for the object 'key' from the object 'o'. 0376 Returns -1 on failure. 0377 0378 This is the equivalent of the Python statement: del o[key]. */ 0379 PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key); 0380 0381 0382 /* Takes an arbitrary object and returns the result of calling 0383 obj.__format__(format_spec). */ 0384 PyAPI_FUNC(PyObject *) PyObject_Format(PyObject *obj, 0385 PyObject *format_spec); 0386 0387 0388 /* ==== Iterators ================================================ */ 0389 0390 /* Takes an object and returns an iterator for it. 0391 This is typically a new iterator but if the argument is an iterator, this 0392 returns itself. */ 0393 PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *); 0394 0395 /* Takes an AsyncIterable object and returns an AsyncIterator for it. 0396 This is typically a new iterator but if the argument is an AsyncIterator, 0397 this returns itself. */ 0398 PyAPI_FUNC(PyObject *) PyObject_GetAIter(PyObject *); 0399 0400 /* Returns non-zero if the object 'obj' provides iterator protocols, and 0 otherwise. 0401 0402 This function always succeeds. */ 0403 PyAPI_FUNC(int) PyIter_Check(PyObject *); 0404 0405 /* Returns non-zero if the object 'obj' provides AsyncIterator protocols, and 0 otherwise. 0406 0407 This function always succeeds. */ 0408 PyAPI_FUNC(int) PyAIter_Check(PyObject *); 0409 0410 /* Takes an iterator object and calls its tp_iternext slot, 0411 returning the next value. 0412 0413 If the iterator is exhausted, this returns NULL without setting an 0414 exception. 0415 0416 NULL with an exception means an error occurred. */ 0417 PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *); 0418 0419 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000 0420 0421 /* Takes generator, coroutine or iterator object and sends the value into it. 0422 Returns: 0423 - PYGEN_RETURN (0) if generator has returned. 0424 'result' parameter is filled with return value 0425 - PYGEN_ERROR (-1) if exception was raised. 0426 'result' parameter is NULL 0427 - PYGEN_NEXT (1) if generator has yielded. 0428 'result' parameter is filled with yielded value. */ 0429 PyAPI_FUNC(PySendResult) PyIter_Send(PyObject *, PyObject *, PyObject **); 0430 #endif 0431 0432 0433 /* === Number Protocol ================================================== */ 0434 0435 /* Returns 1 if the object 'o' provides numeric protocols, and 0 otherwise. 0436 0437 This function always succeeds. */ 0438 PyAPI_FUNC(int) PyNumber_Check(PyObject *o); 0439 0440 /* Returns the result of adding o1 and o2, or NULL on failure. 0441 0442 This is the equivalent of the Python expression: o1 + o2. */ 0443 PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2); 0444 0445 /* Returns the result of subtracting o2 from o1, or NULL on failure. 0446 0447 This is the equivalent of the Python expression: o1 - o2. */ 0448 PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2); 0449 0450 /* Returns the result of multiplying o1 and o2, or NULL on failure. 0451 0452 This is the equivalent of the Python expression: o1 * o2. */ 0453 PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2); 0454 0455 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 0456 /* This is the equivalent of the Python expression: o1 @ o2. */ 0457 PyAPI_FUNC(PyObject *) PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2); 0458 #endif 0459 0460 /* Returns the result of dividing o1 by o2 giving an integral result, 0461 or NULL on failure. 0462 0463 This is the equivalent of the Python expression: o1 // o2. */ 0464 PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2); 0465 0466 /* Returns the result of dividing o1 by o2 giving a float result, or NULL on 0467 failure. 0468 0469 This is the equivalent of the Python expression: o1 / o2. */ 0470 PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2); 0471 0472 /* Returns the remainder of dividing o1 by o2, or NULL on failure. 0473 0474 This is the equivalent of the Python expression: o1 % o2. */ 0475 PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2); 0476 0477 /* See the built-in function divmod. 0478 0479 Returns NULL on failure. 0480 0481 This is the equivalent of the Python expression: divmod(o1, o2). */ 0482 PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2); 0483 0484 /* See the built-in function pow. Returns NULL on failure. 0485 0486 This is the equivalent of the Python expression: pow(o1, o2, o3), 0487 where o3 is optional. */ 0488 PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2, 0489 PyObject *o3); 0490 0491 /* Returns the negation of o on success, or NULL on failure. 0492 0493 This is the equivalent of the Python expression: -o. */ 0494 PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o); 0495 0496 /* Returns the positive of o on success, or NULL on failure. 0497 0498 This is the equivalent of the Python expression: +o. */ 0499 PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o); 0500 0501 /* Returns the absolute value of 'o', or NULL on failure. 0502 0503 This is the equivalent of the Python expression: abs(o). */ 0504 PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o); 0505 0506 /* Returns the bitwise negation of 'o' on success, or NULL on failure. 0507 0508 This is the equivalent of the Python expression: ~o. */ 0509 PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o); 0510 0511 /* Returns the result of left shifting o1 by o2 on success, or NULL on failure. 0512 0513 This is the equivalent of the Python expression: o1 << o2. */ 0514 PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2); 0515 0516 /* Returns the result of right shifting o1 by o2 on success, or NULL on 0517 failure. 0518 0519 This is the equivalent of the Python expression: o1 >> o2. */ 0520 PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2); 0521 0522 /* Returns the result of bitwise and of o1 and o2 on success, or NULL on 0523 failure. 0524 0525 This is the equivalent of the Python expression: o1 & o2. */ 0526 PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2); 0527 0528 /* Returns the bitwise exclusive or of o1 by o2 on success, or NULL on failure. 0529 0530 This is the equivalent of the Python expression: o1 ^ o2. */ 0531 PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2); 0532 0533 /* Returns the result of bitwise or on o1 and o2 on success, or NULL on 0534 failure. 0535 0536 This is the equivalent of the Python expression: o1 | o2. */ 0537 PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2); 0538 0539 /* Returns 1 if obj is an index integer (has the nb_index slot of the 0540 tp_as_number structure filled in), and 0 otherwise. */ 0541 PyAPI_FUNC(int) PyIndex_Check(PyObject *); 0542 0543 /* Returns the object 'o' converted to a Python int, or NULL with an exception 0544 raised on failure. */ 0545 PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o); 0546 0547 /* Returns the object 'o' converted to Py_ssize_t by going through 0548 PyNumber_Index() first. 0549 0550 If an overflow error occurs while converting the int to Py_ssize_t, then the 0551 second argument 'exc' is the error-type to return. If it is NULL, then the 0552 overflow error is cleared and the value is clipped. */ 0553 PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc); 0554 0555 /* Returns the object 'o' converted to an integer object on success, or NULL 0556 on failure. 0557 0558 This is the equivalent of the Python expression: int(o). */ 0559 PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o); 0560 0561 /* Returns the object 'o' converted to a float object on success, or NULL 0562 on failure. 0563 0564 This is the equivalent of the Python expression: float(o). */ 0565 PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o); 0566 0567 0568 /* --- In-place variants of (some of) the above number protocol functions -- */ 0569 0570 /* Returns the result of adding o2 to o1, possibly in-place, or NULL 0571 on failure. 0572 0573 This is the equivalent of the Python expression: o1 += o2. */ 0574 PyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2); 0575 0576 /* Returns the result of subtracting o2 from o1, possibly in-place or 0577 NULL on failure. 0578 0579 This is the equivalent of the Python expression: o1 -= o2. */ 0580 PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2); 0581 0582 /* Returns the result of multiplying o1 by o2, possibly in-place, or NULL on 0583 failure. 0584 0585 This is the equivalent of the Python expression: o1 *= o2. */ 0586 PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2); 0587 0588 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 0589 /* This is the equivalent of the Python expression: o1 @= o2. */ 0590 PyAPI_FUNC(PyObject *) PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2); 0591 #endif 0592 0593 /* Returns the result of dividing o1 by o2 giving an integral result, possibly 0594 in-place, or NULL on failure. 0595 0596 This is the equivalent of the Python expression: o1 /= o2. */ 0597 PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1, 0598 PyObject *o2); 0599 0600 /* Returns the result of dividing o1 by o2 giving a float result, possibly 0601 in-place, or null on failure. 0602 0603 This is the equivalent of the Python expression: o1 /= o2. */ 0604 PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1, 0605 PyObject *o2); 0606 0607 /* Returns the remainder of dividing o1 by o2, possibly in-place, or NULL on 0608 failure. 0609 0610 This is the equivalent of the Python expression: o1 %= o2. */ 0611 PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2); 0612 0613 /* Returns the result of raising o1 to the power of o2, possibly in-place, 0614 or NULL on failure. 0615 0616 This is the equivalent of the Python expression: o1 **= o2, 0617 or o1 = pow(o1, o2, o3) if o3 is present. */ 0618 PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2, 0619 PyObject *o3); 0620 0621 /* Returns the result of left shifting o1 by o2, possibly in-place, or NULL 0622 on failure. 0623 0624 This is the equivalent of the Python expression: o1 <<= o2. */ 0625 PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2); 0626 0627 /* Returns the result of right shifting o1 by o2, possibly in-place or NULL 0628 on failure. 0629 0630 This is the equivalent of the Python expression: o1 >>= o2. */ 0631 PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2); 0632 0633 /* Returns the result of bitwise and of o1 and o2, possibly in-place, or NULL 0634 on failure. 0635 0636 This is the equivalent of the Python expression: o1 &= o2. */ 0637 PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2); 0638 0639 /* Returns the bitwise exclusive or of o1 by o2, possibly in-place, or NULL 0640 on failure. 0641 0642 This is the equivalent of the Python expression: o1 ^= o2. */ 0643 PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2); 0644 0645 /* Returns the result of bitwise or of o1 and o2, possibly in-place, 0646 or NULL on failure. 0647 0648 This is the equivalent of the Python expression: o1 |= o2. */ 0649 PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2); 0650 0651 /* Returns the integer n converted to a string with a base, with a base 0652 marker of 0b, 0o or 0x prefixed if applicable. 0653 0654 If n is not an int object, it is converted with PyNumber_Index first. */ 0655 PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base); 0656 0657 0658 /* === Sequence protocol ================================================ */ 0659 0660 /* Return 1 if the object provides sequence protocol, and zero 0661 otherwise. 0662 0663 This function always succeeds. */ 0664 PyAPI_FUNC(int) PySequence_Check(PyObject *o); 0665 0666 /* Return the size of sequence object o, or -1 on failure. */ 0667 PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o); 0668 0669 /* For DLL compatibility */ 0670 #undef PySequence_Length 0671 PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o); 0672 #define PySequence_Length PySequence_Size 0673 0674 0675 /* Return the concatenation of o1 and o2 on success, and NULL on failure. 0676 0677 This is the equivalent of the Python expression: o1 + o2. */ 0678 PyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2); 0679 0680 /* Return the result of repeating sequence object 'o' 'count' times, 0681 or NULL on failure. 0682 0683 This is the equivalent of the Python expression: o * count. */ 0684 PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count); 0685 0686 /* Return the ith element of o, or NULL on failure. 0687 0688 This is the equivalent of the Python expression: o[i]. */ 0689 PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i); 0690 0691 /* Return the slice of sequence object o between i1 and i2, or NULL on failure. 0692 0693 This is the equivalent of the Python expression: o[i1:i2]. */ 0694 PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); 0695 0696 /* Assign object 'v' to the ith element of the sequence 'o'. Raise an exception 0697 and return -1 on failure; return 0 on success. 0698 0699 This is the equivalent of the Python statement o[i] = v. */ 0700 PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v); 0701 0702 /* Delete the 'i'-th element of the sequence 'v'. Returns -1 on failure. 0703 0704 This is the equivalent of the Python statement: del o[i]. */ 0705 PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i); 0706 0707 /* Assign the sequence object 'v' to the slice in sequence object 'o', 0708 from 'i1' to 'i2'. Returns -1 on failure. 0709 0710 This is the equivalent of the Python statement: o[i1:i2] = v. */ 0711 PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, 0712 PyObject *v); 0713 0714 /* Delete the slice in sequence object 'o' from 'i1' to 'i2'. 0715 Returns -1 on failure. 0716 0717 This is the equivalent of the Python statement: del o[i1:i2]. */ 0718 PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); 0719 0720 /* Returns the sequence 'o' as a tuple on success, and NULL on failure. 0721 0722 This is equivalent to the Python expression: tuple(o). */ 0723 PyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o); 0724 0725 /* Returns the sequence 'o' as a list on success, and NULL on failure. 0726 This is equivalent to the Python expression: list(o) */ 0727 PyAPI_FUNC(PyObject *) PySequence_List(PyObject *o); 0728 0729 /* Return the sequence 'o' as a list, unless it's already a tuple or list. 0730 0731 Use PySequence_Fast_GET_ITEM to access the members of this list, and 0732 PySequence_Fast_GET_SIZE to get its length. 0733 0734 Returns NULL on failure. If the object does not support iteration, raises a 0735 TypeError exception with 'm' as the message text. */ 0736 PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m); 0737 0738 /* Return the size of the sequence 'o', assuming that 'o' was returned by 0739 PySequence_Fast and is not NULL. */ 0740 #define PySequence_Fast_GET_SIZE(o) \ 0741 (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o)) 0742 0743 /* Return the 'i'-th element of the sequence 'o', assuming that o was returned 0744 by PySequence_Fast, and that i is within bounds. */ 0745 #define PySequence_Fast_GET_ITEM(o, i)\ 0746 (PyList_Check(o) ? PyList_GET_ITEM((o), (i)) : PyTuple_GET_ITEM((o), (i))) 0747 0748 /* Return a pointer to the underlying item array for 0749 an object returned by PySequence_Fast */ 0750 #define PySequence_Fast_ITEMS(sf) \ 0751 (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \ 0752 : ((PyTupleObject *)(sf))->ob_item) 0753 0754 /* Return the number of occurrences on value on 'o', that is, return 0755 the number of keys for which o[key] == value. 0756 0757 On failure, return -1. This is equivalent to the Python expression: 0758 o.count(value). */ 0759 PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value); 0760 0761 /* Return 1 if 'ob' is in the sequence 'seq'; 0 if 'ob' is not in the sequence 0762 'seq'; -1 on error. 0763 0764 Use __contains__ if possible, else _PySequence_IterSearch(). */ 0765 PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob); 0766 0767 /* For DLL-level backwards compatibility */ 0768 #undef PySequence_In 0769 /* Determine if the sequence 'o' contains 'value'. If an item in 'o' is equal 0770 to 'value', return 1, otherwise return 0. On error, return -1. 0771 0772 This is equivalent to the Python expression: value in o. */ 0773 PyAPI_FUNC(int) PySequence_In(PyObject *o, PyObject *value); 0774 0775 /* For source-level backwards compatibility */ 0776 #define PySequence_In PySequence_Contains 0777 0778 0779 /* Return the first index for which o[i] == value. 0780 On error, return -1. 0781 0782 This is equivalent to the Python expression: o.index(value). */ 0783 PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value); 0784 0785 0786 /* --- In-place versions of some of the above Sequence functions --- */ 0787 0788 /* Append sequence 'o2' to sequence 'o1', in-place when possible. Return the 0789 resulting object, which could be 'o1', or NULL on failure. 0790 0791 This is the equivalent of the Python expression: o1 += o2. */ 0792 PyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2); 0793 0794 /* Repeat sequence 'o' by 'count', in-place when possible. Return the resulting 0795 object, which could be 'o', or NULL on failure. 0796 0797 This is the equivalent of the Python expression: o1 *= count. */ 0798 PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count); 0799 0800 0801 /* === Mapping protocol ================================================= */ 0802 0803 /* Return 1 if the object provides mapping protocol, and 0 otherwise. 0804 0805 This function always succeeds. */ 0806 PyAPI_FUNC(int) PyMapping_Check(PyObject *o); 0807 0808 /* Returns the number of keys in mapping object 'o' on success, and -1 on 0809 failure. This is equivalent to the Python expression: len(o). */ 0810 PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o); 0811 0812 /* For DLL compatibility */ 0813 #undef PyMapping_Length 0814 PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o); 0815 #define PyMapping_Length PyMapping_Size 0816 0817 0818 /* Implemented as a macro: 0819 0820 int PyMapping_DelItemString(PyObject *o, const char *key); 0821 0822 Remove the mapping for the string 'key' from the mapping 'o'. Returns -1 on 0823 failure. 0824 0825 This is equivalent to the Python statement: del o[key]. */ 0826 #define PyMapping_DelItemString(O, K) PyObject_DelItemString((O), (K)) 0827 0828 /* Implemented as a macro: 0829 0830 int PyMapping_DelItem(PyObject *o, PyObject *key); 0831 0832 Remove the mapping for the object 'key' from the mapping object 'o'. 0833 Returns -1 on failure. 0834 0835 This is equivalent to the Python statement: del o[key]. */ 0836 #define PyMapping_DelItem(O, K) PyObject_DelItem((O), (K)) 0837 0838 /* On success, return 1 if the mapping object 'o' has the key 'key', 0839 and 0 otherwise. 0840 0841 This is equivalent to the Python expression: key in o. 0842 0843 This function always succeeds. */ 0844 PyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, const char *key); 0845 0846 /* Return 1 if the mapping object has the key 'key', and 0 otherwise. 0847 0848 This is equivalent to the Python expression: key in o. 0849 0850 This function always succeeds. */ 0851 PyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key); 0852 0853 /* Return 1 if the mapping object has the key 'key', and 0 otherwise. 0854 This is equivalent to the Python expression: key in o. 0855 On failure, return -1. */ 0856 0857 PyAPI_FUNC(int) PyMapping_HasKeyWithError(PyObject *o, PyObject *key); 0858 0859 /* Return 1 if the mapping object has the key 'key', and 0 otherwise. 0860 This is equivalent to the Python expression: key in o. 0861 On failure, return -1. */ 0862 0863 PyAPI_FUNC(int) PyMapping_HasKeyStringWithError(PyObject *o, const char *key); 0864 0865 /* On success, return a list or tuple of the keys in mapping object 'o'. 0866 On failure, return NULL. */ 0867 PyAPI_FUNC(PyObject *) PyMapping_Keys(PyObject *o); 0868 0869 /* On success, return a list or tuple of the values in mapping object 'o'. 0870 On failure, return NULL. */ 0871 PyAPI_FUNC(PyObject *) PyMapping_Values(PyObject *o); 0872 0873 /* On success, return a list or tuple of the items in mapping object 'o', 0874 where each item is a tuple containing a key-value pair. On failure, return 0875 NULL. */ 0876 PyAPI_FUNC(PyObject *) PyMapping_Items(PyObject *o); 0877 0878 /* Return element of 'o' corresponding to the string 'key' or NULL on failure. 0879 0880 This is the equivalent of the Python expression: o[key]. */ 0881 PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o, 0882 const char *key); 0883 0884 /* Variants of PyObject_GetItem() and PyMapping_GetItemString() which don't 0885 raise KeyError if the key is not found. 0886 0887 If the key is found, return 1 and set *result to a new strong 0888 reference to the corresponding value. 0889 If the key is not found, return 0 and set *result to NULL; 0890 the KeyError is silenced. 0891 If an error other than KeyError is raised, return -1 and 0892 set *result to NULL. 0893 */ 0894 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000 0895 PyAPI_FUNC(int) PyMapping_GetOptionalItem(PyObject *, PyObject *, PyObject **); 0896 PyAPI_FUNC(int) PyMapping_GetOptionalItemString(PyObject *, const char *, PyObject **); 0897 #endif 0898 0899 /* Map the string 'key' to the value 'v' in the mapping 'o'. 0900 Returns -1 on failure. 0901 0902 This is the equivalent of the Python statement: o[key]=v. */ 0903 PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, const char *key, 0904 PyObject *value); 0905 0906 /* isinstance(object, typeorclass) */ 0907 PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass); 0908 0909 /* issubclass(object, typeorclass) */ 0910 PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass); 0911 0912 #ifndef Py_LIMITED_API 0913 # define Py_CPYTHON_ABSTRACTOBJECT_H 0914 # include "cpython/abstract.h" 0915 # undef Py_CPYTHON_ABSTRACTOBJECT_H 0916 #endif 0917 0918 #ifdef __cplusplus 0919 } 0920 #endif 0921 #endif /* Py_ABSTRACTOBJECT_H */
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|