abstract.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  1. /* Abstract Object Interface (many thanks to Jim Fulton) */
  2. #ifndef Py_ABSTRACTOBJECT_H
  3. #define Py_ABSTRACTOBJECT_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /* === Object Protocol ================================================== */
  8. /* Implemented elsewhere:
  9. int PyObject_Print(PyObject *o, FILE *fp, int flags);
  10. Print an object 'o' on file 'fp'. Returns -1 on error. The flags argument
  11. is used to enable certain printing options. The only option currently
  12. supported is Py_Print_RAW.
  13. (What should be said about Py_Print_RAW?). */
  14. /* Implemented elsewhere:
  15. int PyObject_HasAttrString(PyObject *o, const char *attr_name);
  16. Returns 1 if object 'o' has the attribute attr_name, and 0 otherwise.
  17. This is equivalent to the Python expression: hasattr(o,attr_name).
  18. This function always succeeds. */
  19. /* Implemented elsewhere:
  20. PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name);
  21. Retrieve an attributed named attr_name form object o.
  22. Returns the attribute value on success, or NULL on failure.
  23. This is the equivalent of the Python expression: o.attr_name. */
  24. /* Implemented elsewhere:
  25. int PyObject_HasAttr(PyObject *o, PyObject *attr_name);
  26. Returns 1 if o has the attribute attr_name, and 0 otherwise.
  27. This is equivalent to the Python expression: hasattr(o,attr_name).
  28. This function always succeeds. */
  29. /* Implemented elsewhere:
  30. PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name);
  31. Retrieve an attributed named 'attr_name' form object 'o'.
  32. Returns the attribute value on success, or NULL on failure.
  33. This is the equivalent of the Python expression: o.attr_name. */
  34. /* Implemented elsewhere:
  35. int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v);
  36. Set the value of the attribute named attr_name, for object 'o',
  37. to the value 'v'. Raise an exception and return -1 on failure; return 0 on
  38. success.
  39. This is the equivalent of the Python statement o.attr_name=v. */
  40. /* Implemented elsewhere:
  41. int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v);
  42. Set the value of the attribute named attr_name, for object 'o', to the value
  43. 'v'. an exception and return -1 on failure; return 0 on success.
  44. This is the equivalent of the Python statement o.attr_name=v. */
  45. /* Implemented as a macro:
  46. int PyObject_DelAttrString(PyObject *o, const char *attr_name);
  47. Delete attribute named attr_name, for object o. Returns
  48. -1 on failure.
  49. This is the equivalent of the Python statement: del o.attr_name. */
  50. #define PyObject_DelAttrString(O,A) PyObject_SetAttrString((O),(A), NULL)
  51. /* Implemented as a macro:
  52. int PyObject_DelAttr(PyObject *o, PyObject *attr_name);
  53. Delete attribute named attr_name, for object o. Returns -1
  54. on failure. This is the equivalent of the Python
  55. statement: del o.attr_name. */
  56. #define PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A), NULL)
  57. /* Implemented elsewhere:
  58. PyObject *PyObject_Repr(PyObject *o);
  59. Compute the string representation of object 'o'. Returns the
  60. string representation on success, NULL on failure.
  61. This is the equivalent of the Python expression: repr(o).
  62. Called by the repr() built-in function. */
  63. /* Implemented elsewhere:
  64. PyObject *PyObject_Str(PyObject *o);
  65. Compute the string representation of object, o. Returns the
  66. string representation on success, NULL on failure.
  67. This is the equivalent of the Python expression: str(o).
  68. Called by the str() and print() built-in functions. */
  69. /* Declared elsewhere
  70. PyAPI_FUNC(int) PyCallable_Check(PyObject *o);
  71. Determine if the object, o, is callable. Return 1 if the object is callable
  72. and 0 otherwise.
  73. This function always succeeds. */
  74. #ifdef PY_SSIZE_T_CLEAN
  75. # define PyObject_CallFunction _PyObject_CallFunction_SizeT
  76. # define PyObject_CallMethod _PyObject_CallMethod_SizeT
  77. #endif
  78. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
  79. /* Call a callable Python object without any arguments */
  80. PyAPI_FUNC(PyObject *) PyObject_CallNoArgs(PyObject *func);
  81. #endif
  82. /* Call a callable Python object 'callable' with arguments given by the
  83. tuple 'args' and keywords arguments given by the dictionary 'kwargs'.
  84. 'args' must not be NULL, use an empty tuple if no arguments are
  85. needed. If no named arguments are needed, 'kwargs' can be NULL.
  86. This is the equivalent of the Python expression:
  87. callable(*args, **kwargs). */
  88. PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable,
  89. PyObject *args, PyObject *kwargs);
  90. /* Call a callable Python object 'callable', with arguments given by the
  91. tuple 'args'. If no arguments are needed, then 'args' can be NULL.
  92. Returns the result of the call on success, or NULL on failure.
  93. This is the equivalent of the Python expression:
  94. callable(*args). */
  95. PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable,
  96. PyObject *args);
  97. /* Call a callable Python object, callable, with a variable number of C
  98. arguments. The C arguments are described using a mkvalue-style format
  99. string.
  100. The format may be NULL, indicating that no arguments are provided.
  101. Returns the result of the call on success, or NULL on failure.
  102. This is the equivalent of the Python expression:
  103. callable(arg1, arg2, ...). */
  104. PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable,
  105. const char *format, ...);
  106. /* Call the method named 'name' of object 'obj' with a variable number of
  107. C arguments. The C arguments are described by a mkvalue format string.
  108. The format can be NULL, indicating that no arguments are provided.
  109. Returns the result of the call on success, or NULL on failure.
  110. This is the equivalent of the Python expression:
  111. obj.name(arg1, arg2, ...). */
  112. PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *obj,
  113. const char *name,
  114. const char *format, ...);
  115. PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable,
  116. const char *format,
  117. ...);
  118. PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *obj,
  119. const char *name,
  120. const char *format,
  121. ...);
  122. /* Call a callable Python object 'callable' with a variable number of C
  123. arguments. The C arguments are provided as PyObject* values, terminated
  124. by a NULL.
  125. Returns the result of the call on success, or NULL on failure.
  126. This is the equivalent of the Python expression:
  127. callable(arg1, arg2, ...). */
  128. PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable,
  129. ...);
  130. /* Call the method named 'name' of object 'obj' with a variable number of
  131. C arguments. The C arguments are provided as PyObject* values, terminated
  132. by NULL.
  133. Returns the result of the call on success, or NULL on failure.
  134. This is the equivalent of the Python expression: obj.name(*args). */
  135. PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs(
  136. PyObject *obj,
  137. PyObject *name,
  138. ...);
  139. /* Implemented elsewhere:
  140. Py_hash_t PyObject_Hash(PyObject *o);
  141. Compute and return the hash, hash_value, of an object, o. On
  142. failure, return -1.
  143. This is the equivalent of the Python expression: hash(o). */
  144. /* Implemented elsewhere:
  145. int PyObject_IsTrue(PyObject *o);
  146. Returns 1 if the object, o, is considered to be true, 0 if o is
  147. considered to be false and -1 on failure.
  148. This is equivalent to the Python expression: not not o. */
  149. /* Implemented elsewhere:
  150. int PyObject_Not(PyObject *o);
  151. Returns 0 if the object, o, is considered to be true, 1 if o is
  152. considered to be false and -1 on failure.
  153. This is equivalent to the Python expression: not o. */
  154. /* Get the type of an object.
  155. On success, returns a type object corresponding to the object type of object
  156. 'o'. On failure, returns NULL.
  157. This is equivalent to the Python expression: type(o) */
  158. PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o);
  159. /* Return the size of object 'o'. If the object 'o' provides both sequence and
  160. mapping protocols, the sequence size is returned.
  161. On error, -1 is returned.
  162. This is the equivalent to the Python expression: len(o) */
  163. PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o);
  164. /* For DLL compatibility */
  165. #undef PyObject_Length
  166. PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o);
  167. #define PyObject_Length PyObject_Size
  168. /* Return element of 'o' corresponding to the object 'key'. Return NULL
  169. on failure.
  170. This is the equivalent of the Python expression: o[key] */
  171. PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key);
  172. /* Map the object 'key' to the value 'v' into 'o'.
  173. Raise an exception and return -1 on failure; return 0 on success.
  174. This is the equivalent of the Python statement: o[key]=v. */
  175. PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v);
  176. /* Remove the mapping for the string 'key' from the object 'o'.
  177. Returns -1 on failure.
  178. This is equivalent to the Python statement: del o[key]. */
  179. PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, const char *key);
  180. /* Delete the mapping for the object 'key' from the object 'o'.
  181. Returns -1 on failure.
  182. This is the equivalent of the Python statement: del o[key]. */
  183. PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key);
  184. /* === Old Buffer API ============================================ */
  185. /* FIXME: usage of these should all be replaced in Python itself
  186. but for backwards compatibility we will implement them.
  187. Their usage without a corresponding "unlock" mechanism
  188. may create issues (but they would already be there). */
  189. /* Takes an arbitrary object which must support the (character, single segment)
  190. buffer interface and returns a pointer to a read-only memory location
  191. usable as character based input for subsequent processing.
  192. Return 0 on success. buffer and buffer_len are only set in case no error
  193. occurs. Otherwise, -1 is returned and an exception set. */
  194. Py_DEPRECATED(3.0)
  195. PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj,
  196. const char **buffer,
  197. Py_ssize_t *buffer_len);
  198. /* Checks whether an arbitrary object supports the (character, single segment)
  199. buffer interface.
  200. Returns 1 on success, 0 on failure. */
  201. Py_DEPRECATED(3.0) PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj);
  202. /* Same as PyObject_AsCharBuffer() except that this API expects (readable,
  203. single segment) buffer interface and returns a pointer to a read-only memory
  204. location which can contain arbitrary data.
  205. 0 is returned on success. buffer and buffer_len are only set in case no
  206. error occurs. Otherwise, -1 is returned and an exception set. */
  207. Py_DEPRECATED(3.0)
  208. PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj,
  209. const void **buffer,
  210. Py_ssize_t *buffer_len);
  211. /* Takes an arbitrary object which must support the (writable, single segment)
  212. buffer interface and returns a pointer to a writable memory location in
  213. buffer of size 'buffer_len'.
  214. Return 0 on success. buffer and buffer_len are only set in case no error
  215. occurs. Otherwise, -1 is returned and an exception set. */
  216. Py_DEPRECATED(3.0)
  217. PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj,
  218. void **buffer,
  219. Py_ssize_t *buffer_len);
  220. /* === New Buffer API ============================================ */
  221. /* Takes an arbitrary object and returns the result of calling
  222. obj.__format__(format_spec). */
  223. PyAPI_FUNC(PyObject *) PyObject_Format(PyObject *obj,
  224. PyObject *format_spec);
  225. /* ==== Iterators ================================================ */
  226. /* Takes an object and returns an iterator for it.
  227. This is typically a new iterator but if the argument is an iterator, this
  228. returns itself. */
  229. PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *);
  230. /* Returns 1 if the object 'obj' provides iterator protocols, and 0 otherwise.
  231. This function always succeeds. */
  232. PyAPI_FUNC(int) PyIter_Check(PyObject *);
  233. /* Takes an iterator object and calls its tp_iternext slot,
  234. returning the next value.
  235. If the iterator is exhausted, this returns NULL without setting an
  236. exception.
  237. NULL with an exception means an error occurred. */
  238. PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *);
  239. /* === Number Protocol ================================================== */
  240. /* Returns 1 if the object 'o' provides numeric protocols, and 0 otherwise.
  241. This function always succeeds. */
  242. PyAPI_FUNC(int) PyNumber_Check(PyObject *o);
  243. /* Returns the result of adding o1 and o2, or NULL on failure.
  244. This is the equivalent of the Python expression: o1 + o2. */
  245. PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2);
  246. /* Returns the result of subtracting o2 from o1, or NULL on failure.
  247. This is the equivalent of the Python expression: o1 - o2. */
  248. PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2);
  249. /* Returns the result of multiplying o1 and o2, or NULL on failure.
  250. This is the equivalent of the Python expression: o1 * o2. */
  251. PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2);
  252. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
  253. /* This is the equivalent of the Python expression: o1 @ o2. */
  254. PyAPI_FUNC(PyObject *) PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2);
  255. #endif
  256. /* Returns the result of dividing o1 by o2 giving an integral result,
  257. or NULL on failure.
  258. This is the equivalent of the Python expression: o1 // o2. */
  259. PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2);
  260. /* Returns the result of dividing o1 by o2 giving a float result, or NULL on
  261. failure.
  262. This is the equivalent of the Python expression: o1 / o2. */
  263. PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2);
  264. /* Returns the remainder of dividing o1 by o2, or NULL on failure.
  265. This is the equivalent of the Python expression: o1 % o2. */
  266. PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2);
  267. /* See the built-in function divmod.
  268. Returns NULL on failure.
  269. This is the equivalent of the Python expression: divmod(o1, o2). */
  270. PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2);
  271. /* See the built-in function pow. Returns NULL on failure.
  272. This is the equivalent of the Python expression: pow(o1, o2, o3),
  273. where o3 is optional. */
  274. PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2,
  275. PyObject *o3);
  276. /* Returns the negation of o on success, or NULL on failure.
  277. This is the equivalent of the Python expression: -o. */
  278. PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o);
  279. /* Returns the positive of o on success, or NULL on failure.
  280. This is the equivalent of the Python expression: +o. */
  281. PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o);
  282. /* Returns the absolute value of 'o', or NULL on failure.
  283. This is the equivalent of the Python expression: abs(o). */
  284. PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o);
  285. /* Returns the bitwise negation of 'o' on success, or NULL on failure.
  286. This is the equivalent of the Python expression: ~o. */
  287. PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o);
  288. /* Returns the result of left shifting o1 by o2 on success, or NULL on failure.
  289. This is the equivalent of the Python expression: o1 << o2. */
  290. PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2);
  291. /* Returns the result of right shifting o1 by o2 on success, or NULL on
  292. failure.
  293. This is the equivalent of the Python expression: o1 >> o2. */
  294. PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2);
  295. /* Returns the result of bitwise and of o1 and o2 on success, or NULL on
  296. failure.
  297. This is the equivalent of the Python expression: o1 & o2. */
  298. PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2);
  299. /* Returns the bitwise exclusive or of o1 by o2 on success, or NULL on failure.
  300. This is the equivalent of the Python expression: o1 ^ o2. */
  301. PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2);
  302. /* Returns the result of bitwise or on o1 and o2 on success, or NULL on
  303. failure.
  304. This is the equivalent of the Python expression: o1 | o2. */
  305. PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2);
  306. /* Returns 1 if obj is an index integer (has the nb_index slot of the
  307. tp_as_number structure filled in), and 0 otherwise. */
  308. PyAPI_FUNC(int) PyIndex_Check(PyObject *);
  309. /* Returns the object 'o' converted to a Python int, or NULL with an exception
  310. raised on failure. */
  311. PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o);
  312. /* Returns the object 'o' converted to Py_ssize_t by going through
  313. PyNumber_Index() first.
  314. If an overflow error occurs while converting the int to Py_ssize_t, then the
  315. second argument 'exc' is the error-type to return. If it is NULL, then the
  316. overflow error is cleared and the value is clipped. */
  317. PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc);
  318. /* Returns the object 'o' converted to an integer object on success, or NULL
  319. on failure.
  320. This is the equivalent of the Python expression: int(o). */
  321. PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o);
  322. /* Returns the object 'o' converted to a float object on success, or NULL
  323. on failure.
  324. This is the equivalent of the Python expression: float(o). */
  325. PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o);
  326. /* --- In-place variants of (some of) the above number protocol functions -- */
  327. /* Returns the result of adding o2 to o1, possibly in-place, or NULL
  328. on failure.
  329. This is the equivalent of the Python expression: o1 += o2. */
  330. PyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2);
  331. /* Returns the result of subtracting o2 from o1, possibly in-place or
  332. NULL on failure.
  333. This is the equivalent of the Python expression: o1 -= o2. */
  334. PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2);
  335. /* Returns the result of multiplying o1 by o2, possibly in-place, or NULL on
  336. failure.
  337. This is the equivalent of the Python expression: o1 *= o2. */
  338. PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2);
  339. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
  340. /* This is the equivalent of the Python expression: o1 @= o2. */
  341. PyAPI_FUNC(PyObject *) PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2);
  342. #endif
  343. /* Returns the result of dividing o1 by o2 giving an integral result, possibly
  344. in-place, or NULL on failure.
  345. This is the equivalent of the Python expression: o1 /= o2. */
  346. PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1,
  347. PyObject *o2);
  348. /* Returns the result of dividing o1 by o2 giving a float result, possibly
  349. in-place, or null on failure.
  350. This is the equivalent of the Python expression: o1 /= o2. */
  351. PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1,
  352. PyObject *o2);
  353. /* Returns the remainder of dividing o1 by o2, possibly in-place, or NULL on
  354. failure.
  355. This is the equivalent of the Python expression: o1 %= o2. */
  356. PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2);
  357. /* Returns the result of raising o1 to the power of o2, possibly in-place,
  358. or NULL on failure.
  359. This is the equivalent of the Python expression: o1 **= o2,
  360. or o1 = pow(o1, o2, o3) if o3 is present. */
  361. PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2,
  362. PyObject *o3);
  363. /* Returns the result of left shifting o1 by o2, possibly in-place, or NULL
  364. on failure.
  365. This is the equivalent of the Python expression: o1 <<= o2. */
  366. PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2);
  367. /* Returns the result of right shifting o1 by o2, possibly in-place or NULL
  368. on failure.
  369. This is the equivalent of the Python expression: o1 >>= o2. */
  370. PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2);
  371. /* Returns the result of bitwise and of o1 and o2, possibly in-place, or NULL
  372. on failure.
  373. This is the equivalent of the Python expression: o1 &= o2. */
  374. PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2);
  375. /* Returns the bitwise exclusive or of o1 by o2, possibly in-place, or NULL
  376. on failure.
  377. This is the equivalent of the Python expression: o1 ^= o2. */
  378. PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2);
  379. /* Returns the result of bitwise or of o1 and o2, possibly in-place,
  380. or NULL on failure.
  381. This is the equivalent of the Python expression: o1 |= o2. */
  382. PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2);
  383. /* Returns the integer n converted to a string with a base, with a base
  384. marker of 0b, 0o or 0x prefixed if applicable.
  385. If n is not an int object, it is converted with PyNumber_Index first. */
  386. PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base);
  387. /* === Sequence protocol ================================================ */
  388. /* Return 1 if the object provides sequence protocol, and zero
  389. otherwise.
  390. This function always succeeds. */
  391. PyAPI_FUNC(int) PySequence_Check(PyObject *o);
  392. /* Return the size of sequence object o, or -1 on failure. */
  393. PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o);
  394. /* For DLL compatibility */
  395. #undef PySequence_Length
  396. PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o);
  397. #define PySequence_Length PySequence_Size
  398. /* Return the concatenation of o1 and o2 on success, and NULL on failure.
  399. This is the equivalent of the Python expression: o1 + o2. */
  400. PyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2);
  401. /* Return the result of repeating sequence object 'o' 'count' times,
  402. or NULL on failure.
  403. This is the equivalent of the Python expression: o * count. */
  404. PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count);
  405. /* Return the ith element of o, or NULL on failure.
  406. This is the equivalent of the Python expression: o[i]. */
  407. PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i);
  408. /* Return the slice of sequence object o between i1 and i2, or NULL on failure.
  409. This is the equivalent of the Python expression: o[i1:i2]. */
  410. PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
  411. /* Assign object 'v' to the ith element of the sequence 'o'. Raise an exception
  412. and return -1 on failure; return 0 on success.
  413. This is the equivalent of the Python statement o[i] = v. */
  414. PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v);
  415. /* Delete the 'i'-th element of the sequence 'v'. Returns -1 on failure.
  416. This is the equivalent of the Python statement: del o[i]. */
  417. PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i);
  418. /* Assign the sequence object 'v' to the slice in sequence object 'o',
  419. from 'i1' to 'i2'. Returns -1 on failure.
  420. This is the equivalent of the Python statement: o[i1:i2] = v. */
  421. PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2,
  422. PyObject *v);
  423. /* Delete the slice in sequence object 'o' from 'i1' to 'i2'.
  424. Returns -1 on failure.
  425. This is the equivalent of the Python statement: del o[i1:i2]. */
  426. PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
  427. /* Returns the sequence 'o' as a tuple on success, and NULL on failure.
  428. This is equivalent to the Python expression: tuple(o). */
  429. PyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o);
  430. /* Returns the sequence 'o' as a list on success, and NULL on failure.
  431. This is equivalent to the Python expression: list(o) */
  432. PyAPI_FUNC(PyObject *) PySequence_List(PyObject *o);
  433. /* Return the sequence 'o' as a list, unless it's already a tuple or list.
  434. Use PySequence_Fast_GET_ITEM to access the members of this list, and
  435. PySequence_Fast_GET_SIZE to get its length.
  436. Returns NULL on failure. If the object does not support iteration, raises a
  437. TypeError exception with 'm' as the message text. */
  438. PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m);
  439. /* Return the size of the sequence 'o', assuming that 'o' was returned by
  440. PySequence_Fast and is not NULL. */
  441. #define PySequence_Fast_GET_SIZE(o) \
  442. (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o))
  443. /* Return the 'i'-th element of the sequence 'o', assuming that o was returned
  444. by PySequence_Fast, and that i is within bounds. */
  445. #define PySequence_Fast_GET_ITEM(o, i)\
  446. (PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i))
  447. /* Return a pointer to the underlying item array for
  448. an object returned by PySequence_Fast */
  449. #define PySequence_Fast_ITEMS(sf) \
  450. (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \
  451. : ((PyTupleObject *)(sf))->ob_item)
  452. /* Return the number of occurrences on value on 'o', that is, return
  453. the number of keys for which o[key] == value.
  454. On failure, return -1. This is equivalent to the Python expression:
  455. o.count(value). */
  456. PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value);
  457. /* Return 1 if 'ob' is in the sequence 'seq'; 0 if 'ob' is not in the sequence
  458. 'seq'; -1 on error.
  459. Use __contains__ if possible, else _PySequence_IterSearch(). */
  460. PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob);
  461. /* For DLL-level backwards compatibility */
  462. #undef PySequence_In
  463. /* Determine if the sequence 'o' contains 'value'. If an item in 'o' is equal
  464. to 'value', return 1, otherwise return 0. On error, return -1.
  465. This is equivalent to the Python expression: value in o. */
  466. PyAPI_FUNC(int) PySequence_In(PyObject *o, PyObject *value);
  467. /* For source-level backwards compatibility */
  468. #define PySequence_In PySequence_Contains
  469. /* Return the first index for which o[i] == value.
  470. On error, return -1.
  471. This is equivalent to the Python expression: o.index(value). */
  472. PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value);
  473. /* --- In-place versions of some of the above Sequence functions --- */
  474. /* Append sequence 'o2' to sequence 'o1', in-place when possible. Return the
  475. resulting object, which could be 'o1', or NULL on failure.
  476. This is the equivalent of the Python expression: o1 += o2. */
  477. PyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2);
  478. /* Repeat sequence 'o' by 'count', in-place when possible. Return the resulting
  479. object, which could be 'o', or NULL on failure.
  480. This is the equivalent of the Python expression: o1 *= count. */
  481. PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count);
  482. /* === Mapping protocol ================================================= */
  483. /* Return 1 if the object provides mapping protocol, and 0 otherwise.
  484. This function always succeeds. */
  485. PyAPI_FUNC(int) PyMapping_Check(PyObject *o);
  486. /* Returns the number of keys in mapping object 'o' on success, and -1 on
  487. failure. This is equivalent to the Python expression: len(o). */
  488. PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o);
  489. /* For DLL compatibility */
  490. #undef PyMapping_Length
  491. PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o);
  492. #define PyMapping_Length PyMapping_Size
  493. /* Implemented as a macro:
  494. int PyMapping_DelItemString(PyObject *o, const char *key);
  495. Remove the mapping for the string 'key' from the mapping 'o'. Returns -1 on
  496. failure.
  497. This is equivalent to the Python statement: del o[key]. */
  498. #define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K))
  499. /* Implemented as a macro:
  500. int PyMapping_DelItem(PyObject *o, PyObject *key);
  501. Remove the mapping for the object 'key' from the mapping object 'o'.
  502. Returns -1 on failure.
  503. This is equivalent to the Python statement: del o[key]. */
  504. #define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K))
  505. /* On success, return 1 if the mapping object 'o' has the key 'key',
  506. and 0 otherwise.
  507. This is equivalent to the Python expression: key in o.
  508. This function always succeeds. */
  509. PyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, const char *key);
  510. /* Return 1 if the mapping object has the key 'key', and 0 otherwise.
  511. This is equivalent to the Python expression: key in o.
  512. This function always succeeds. */
  513. PyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key);
  514. /* On success, return a list or tuple of the keys in mapping object 'o'.
  515. On failure, return NULL. */
  516. PyAPI_FUNC(PyObject *) PyMapping_Keys(PyObject *o);
  517. /* On success, return a list or tuple of the values in mapping object 'o'.
  518. On failure, return NULL. */
  519. PyAPI_FUNC(PyObject *) PyMapping_Values(PyObject *o);
  520. /* On success, return a list or tuple of the items in mapping object 'o',
  521. where each item is a tuple containing a key-value pair. On failure, return
  522. NULL. */
  523. PyAPI_FUNC(PyObject *) PyMapping_Items(PyObject *o);
  524. /* Return element of 'o' corresponding to the string 'key' or NULL on failure.
  525. This is the equivalent of the Python expression: o[key]. */
  526. PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o,
  527. const char *key);
  528. /* Map the string 'key' to the value 'v' in the mapping 'o'.
  529. Returns -1 on failure.
  530. This is the equivalent of the Python statement: o[key]=v. */
  531. PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, const char *key,
  532. PyObject *value);
  533. /* isinstance(object, typeorclass) */
  534. PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass);
  535. /* issubclass(object, typeorclass) */
  536. PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass);
  537. #ifndef Py_LIMITED_API
  538. # define Py_CPYTHON_ABSTRACTOBJECT_H
  539. # include "cpython/abstract.h"
  540. # undef Py_CPYTHON_ABSTRACTOBJECT_H
  541. #endif
  542. #ifdef __cplusplus
  543. }
  544. #endif
  545. #endif /* Py_ABSTRACTOBJECT_H */