abstract.h 30 KB

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