abstract.h 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  1. #ifndef Py_ABSTRACTOBJECT_H
  2. #define Py_ABSTRACTOBJECT_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #ifdef PY_SSIZE_T_CLEAN
  7. #define PyObject_CallFunction _PyObject_CallFunction_SizeT
  8. #define PyObject_CallMethod _PyObject_CallMethod_SizeT
  9. #endif
  10. /* Abstract Object Interface (many thanks to Jim Fulton) */
  11. /*
  12. PROPOSAL: A Generic Python Object Interface for Python C Modules
  13. Problem
  14. Python modules written in C that must access Python objects must do
  15. so through routines whose interfaces are described by a set of
  16. include files. Unfortunately, these routines vary according to the
  17. object accessed. To use these routines, the C programmer must check
  18. the type of the object being used and must call a routine based on
  19. the object type. For example, to access an element of a sequence,
  20. the programmer must determine whether the sequence is a list or a
  21. tuple:
  22. if(is_tupleobject(o))
  23. e=gettupleitem(o,i)
  24. else if(is_listitem(o))
  25. e=getlistitem(o,i)
  26. If the programmer wants to get an item from another type of object
  27. that provides sequence behavior, there is no clear way to do it
  28. correctly.
  29. The persistent programmer may peruse object.h and find that the
  30. _typeobject structure provides a means of invoking up to (currently
  31. about) 41 special operators. So, for example, a routine can get an
  32. item from any object that provides sequence behavior. However, to
  33. use this mechanism, the programmer must make their code dependent on
  34. the current Python implementation.
  35. Also, certain semantics, especially memory management semantics, may
  36. differ by the type of object being used. Unfortunately, these
  37. semantics are not clearly described in the current include files.
  38. An abstract interface providing more consistent semantics is needed.
  39. Proposal
  40. I propose the creation of a standard interface (with an associated
  41. library of routines and/or macros) for generically obtaining the
  42. services of Python objects. This proposal can be viewed as one
  43. components of a Python C interface consisting of several components.
  44. From the viewpoint of C access to Python services, we have (as
  45. suggested by Guido in off-line discussions):
  46. - "Very high level layer": two or three functions that let you exec or
  47. eval arbitrary Python code given as a string in a module whose name is
  48. given, passing C values in and getting C values out using
  49. mkvalue/getargs style format strings. This does not require the user
  50. to declare any variables of type "PyObject *". This should be enough
  51. to write a simple application that gets Python code from the user,
  52. execs it, and returns the output or errors. (Error handling must also
  53. be part of this API.)
  54. - "Abstract objects layer": which is the subject of this proposal.
  55. It has many functions operating on objects, and lest you do many
  56. things from C that you can also write in Python, without going
  57. through the Python parser.
  58. - "Concrete objects layer": This is the public type-dependent
  59. interface provided by the standard built-in types, such as floats,
  60. strings, and lists. This interface exists and is currently
  61. documented by the collection of include files provided with the
  62. Python distributions.
  63. From the point of view of Python accessing services provided by C
  64. modules:
  65. - "Python module interface": this interface consist of the basic
  66. routines used to define modules and their members. Most of the
  67. current extensions-writing guide deals with this interface.
  68. - "Built-in object interface": this is the interface that a new
  69. built-in type must provide and the mechanisms and rules that a
  70. developer of a new built-in type must use and follow.
  71. This proposal is a "first-cut" that is intended to spur
  72. discussion. See especially the lists of notes.
  73. The Python C object interface will provide four protocols: object,
  74. numeric, sequence, and mapping. Each protocol consists of a
  75. collection of related operations. If an operation that is not
  76. provided by a particular type is invoked, then a standard exception,
  77. NotImplementedError is raised with a operation name as an argument.
  78. In addition, for convenience this interface defines a set of
  79. constructors for building objects of built-in types. This is needed
  80. so new objects can be returned from C functions that otherwise treat
  81. objects generically.
  82. Memory Management
  83. For all of the functions described in this proposal, if a function
  84. retains a reference to a Python object passed as an argument, then the
  85. function will increase the reference count of the object. It is
  86. unnecessary for the caller to increase the reference count of an
  87. argument in anticipation of the object's retention.
  88. All Python objects returned from functions should be treated as new
  89. objects. Functions that return objects assume that the caller will
  90. retain a reference and the reference count of the object has already
  91. been incremented to account for this fact. A caller that does not
  92. retain a reference to an object that is returned from a function
  93. must decrement the reference count of the object (using
  94. DECREF(object)) to prevent memory leaks.
  95. Note that the behavior mentioned here is different from the current
  96. behavior for some objects (e.g. lists and tuples) when certain
  97. type-specific routines are called directly (e.g. setlistitem). The
  98. proposed abstraction layer will provide a consistent memory
  99. management interface, correcting for inconsistent behavior for some
  100. built-in types.
  101. Protocols
  102. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
  103. /* Object Protocol: */
  104. /* Implemented elsewhere:
  105. int PyObject_Print(PyObject *o, FILE *fp, int flags);
  106. Print an object, o, on file, fp. Returns -1 on
  107. error. The flags argument is used to enable certain printing
  108. options. The only option currently supported is Py_Print_RAW.
  109. (What should be said about Py_Print_RAW?)
  110. */
  111. /* Implemented elsewhere:
  112. int PyObject_HasAttrString(PyObject *o, char *attr_name);
  113. Returns 1 if o has the attribute attr_name, and 0 otherwise.
  114. This is equivalent to the Python expression:
  115. hasattr(o,attr_name).
  116. This function always succeeds.
  117. */
  118. /* Implemented elsewhere:
  119. PyObject* PyObject_GetAttrString(PyObject *o, char *attr_name);
  120. Retrieve an attributed named attr_name form object o.
  121. Returns the attribute value on success, or NULL on failure.
  122. This is the equivalent of the Python expression: o.attr_name.
  123. */
  124. /* Implemented elsewhere:
  125. int PyObject_HasAttr(PyObject *o, PyObject *attr_name);
  126. Returns 1 if o has the attribute attr_name, and 0 otherwise.
  127. This is equivalent to the Python expression:
  128. hasattr(o,attr_name).
  129. This function always succeeds.
  130. */
  131. /* Implemented elsewhere:
  132. PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name);
  133. Retrieve an attributed named attr_name form object o.
  134. Returns the attribute value on success, or NULL on failure.
  135. This is the equivalent of the Python expression: o.attr_name.
  136. */
  137. /* Implemented elsewhere:
  138. int PyObject_SetAttrString(PyObject *o, char *attr_name, PyObject *v);
  139. Set the value of the attribute named attr_name, for object o,
  140. to the value, v. Returns -1 on failure. This is
  141. the equivalent of the Python statement: o.attr_name=v.
  142. */
  143. /* Implemented elsewhere:
  144. int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v);
  145. Set the value of the attribute named attr_name, for object o,
  146. to the value, v. Returns -1 on failure. This is
  147. the equivalent of the Python statement: o.attr_name=v.
  148. */
  149. /* implemented as a macro:
  150. int PyObject_DelAttrString(PyObject *o, char *attr_name);
  151. Delete attribute named attr_name, for object o. Returns
  152. -1 on failure. This is the equivalent of the Python
  153. statement: del o.attr_name.
  154. */
  155. #define PyObject_DelAttrString(O,A) PyObject_SetAttrString((O),(A),NULL)
  156. /* implemented as a macro:
  157. int PyObject_DelAttr(PyObject *o, PyObject *attr_name);
  158. Delete attribute named attr_name, for object o. Returns -1
  159. on failure. This is the equivalent of the Python
  160. statement: del o.attr_name.
  161. */
  162. #define PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A),NULL)
  163. PyAPI_FUNC(int) PyObject_Cmp(PyObject *o1, PyObject *o2, int *result);
  164. /*
  165. Compare the values of o1 and o2 using a routine provided by
  166. o1, if one exists, otherwise with a routine provided by o2.
  167. The result of the comparison is returned in result. Returns
  168. -1 on failure. This is the equivalent of the Python
  169. statement: result=cmp(o1,o2).
  170. */
  171. /* Implemented elsewhere:
  172. int PyObject_Compare(PyObject *o1, PyObject *o2);
  173. Compare the values of o1 and o2 using a routine provided by
  174. o1, if one exists, otherwise with a routine provided by o2.
  175. Returns the result of the comparison on success. On error,
  176. the value returned is undefined. This is equivalent to the
  177. Python expression: cmp(o1,o2).
  178. */
  179. /* Implemented elsewhere:
  180. PyObject *PyObject_Repr(PyObject *o);
  181. Compute the string representation of object, o. Returns the
  182. string representation on success, NULL on failure. This is
  183. the equivalent of the Python expression: repr(o).
  184. Called by the repr() built-in function and by reverse quotes.
  185. */
  186. /* Implemented elsewhere:
  187. PyObject *PyObject_Str(PyObject *o);
  188. Compute the string representation of object, o. Returns the
  189. string representation on success, NULL on failure. This is
  190. the equivalent of the Python expression: str(o).)
  191. Called by the str() built-in function and by the print
  192. statement.
  193. */
  194. /* Implemented elsewhere:
  195. PyObject *PyObject_Unicode(PyObject *o);
  196. Compute the unicode representation of object, o. Returns the
  197. unicode representation on success, NULL on failure. This is
  198. the equivalent of the Python expression: unistr(o).)
  199. Called by the unistr() built-in function.
  200. */
  201. /* Declared elsewhere
  202. PyAPI_FUNC(int) PyCallable_Check(PyObject *o);
  203. Determine if the object, o, is callable. Return 1 if the
  204. object is callable and 0 otherwise.
  205. This function always succeeds.
  206. */
  207. PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable_object,
  208. PyObject *args, PyObject *kw);
  209. /*
  210. Call a callable Python object, callable_object, with
  211. arguments and keywords arguments. The 'args' argument can not be
  212. NULL, but the 'kw' argument can be NULL.
  213. */
  214. PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable_object,
  215. PyObject *args);
  216. /*
  217. Call a callable Python object, callable_object, with
  218. arguments given by the tuple, args. If no arguments are
  219. needed, then args may be NULL. Returns the result of the
  220. call on success, or NULL on failure. This is the equivalent
  221. of the Python expression: apply(o,args).
  222. */
  223. PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable_object,
  224. char *format, ...);
  225. /*
  226. Call a callable Python object, callable_object, with a
  227. variable number of C arguments. The C arguments are described
  228. using a mkvalue-style format string. The format may be NULL,
  229. indicating that no arguments are provided. Returns the
  230. result of the call on success, or NULL on failure. This is
  231. the equivalent of the Python expression: apply(o,args).
  232. */
  233. PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *o, char *m,
  234. char *format, ...);
  235. /*
  236. Call the method named m of object o with a variable number of
  237. C arguments. The C arguments are described by a mkvalue
  238. format string. The format may be NULL, indicating that no
  239. arguments are provided. Returns the result of the call on
  240. success, or NULL on failure. This is the equivalent of the
  241. Python expression: o.method(args).
  242. */
  243. PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable,
  244. char *format, ...);
  245. PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *o,
  246. char *name,
  247. char *format, ...);
  248. PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable,
  249. ...);
  250. /*
  251. Call a callable Python object, callable_object, with a
  252. variable number of C arguments. The C arguments are provided
  253. as PyObject * values, terminated by a NULL. Returns the
  254. result of the call on success, or NULL on failure. This is
  255. the equivalent of the Python expression: apply(o,args).
  256. */
  257. PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs(PyObject *o,
  258. PyObject *m, ...);
  259. /*
  260. Call the method named m of object o with a variable number of
  261. C arguments. The C arguments are provided as PyObject *
  262. values, terminated by NULL. Returns the result of the call
  263. on success, or NULL on failure. This is the equivalent of
  264. the Python expression: o.method(args).
  265. */
  266. /* Implemented elsewhere:
  267. long PyObject_Hash(PyObject *o);
  268. Compute and return the hash, hash_value, of an object, o. On
  269. failure, return -1. This is the equivalent of the Python
  270. expression: hash(o).
  271. */
  272. /* Implemented elsewhere:
  273. int PyObject_IsTrue(PyObject *o);
  274. Returns 1 if the object, o, is considered to be true, 0 if o is
  275. considered to be false and -1 on failure. This is equivalent to the
  276. Python expression: not not o
  277. */
  278. /* Implemented elsewhere:
  279. int PyObject_Not(PyObject *o);
  280. Returns 0 if the object, o, is considered to be true, 1 if o is
  281. considered to be false and -1 on failure. This is equivalent to the
  282. Python expression: not o
  283. */
  284. PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o);
  285. /*
  286. On success, returns a type object corresponding to the object
  287. type of object o. On failure, returns NULL. This is
  288. equivalent to the Python expression: type(o).
  289. */
  290. PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o);
  291. /*
  292. Return the size of object o. If the object, o, provides
  293. both sequence and mapping protocols, the sequence size is
  294. returned. On error, -1 is returned. This is the equivalent
  295. to the Python expression: len(o).
  296. */
  297. /* For DLL compatibility */
  298. #undef PyObject_Length
  299. PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o);
  300. #define PyObject_Length PyObject_Size
  301. PyAPI_FUNC(Py_ssize_t) _PyObject_LengthHint(PyObject *o, Py_ssize_t);
  302. /*
  303. Guess the size of object o using len(o) or o.__length_hint__().
  304. If neither of those return a non-negative value, then return the
  305. default value. If one of the calls fails, this function returns -1.
  306. */
  307. PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key);
  308. /*
  309. Return element of o corresponding to the object, key, or NULL
  310. on failure. This is the equivalent of the Python expression:
  311. o[key].
  312. */
  313. PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v);
  314. /*
  315. Map the object, key, to the value, v. Returns
  316. -1 on failure. This is the equivalent of the Python
  317. statement: o[key]=v.
  318. */
  319. PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, char *key);
  320. /*
  321. Remove the mapping for object, key, from the object *o.
  322. Returns -1 on failure. This is equivalent to
  323. the Python statement: del o[key].
  324. */
  325. PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key);
  326. /*
  327. Delete the mapping for key from *o. Returns -1 on failure.
  328. This is the equivalent of the Python statement: del o[key].
  329. */
  330. PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj,
  331. const char **buffer,
  332. Py_ssize_t *buffer_len);
  333. /*
  334. Takes an arbitrary object which must support the (character,
  335. single segment) buffer interface and returns a pointer to a
  336. read-only memory location useable as character based input
  337. for subsequent processing.
  338. 0 is returned on success. buffer and buffer_len are only
  339. set in case no error occurs. Otherwise, -1 is returned and
  340. an exception set.
  341. */
  342. PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj);
  343. /*
  344. Checks whether an arbitrary object supports the (character,
  345. single segment) buffer interface. Returns 1 on success, 0
  346. on failure.
  347. */
  348. PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj,
  349. const void **buffer,
  350. Py_ssize_t *buffer_len);
  351. /*
  352. Same as PyObject_AsCharBuffer() except that this API expects
  353. (readable, single segment) buffer interface and returns a
  354. pointer to a read-only memory location which can contain
  355. arbitrary data.
  356. 0 is returned on success. buffer and buffer_len are only
  357. set in case no error occurs. Otherwise, -1 is returned and
  358. an exception set.
  359. */
  360. PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj,
  361. void **buffer,
  362. Py_ssize_t *buffer_len);
  363. /*
  364. Takes an arbitrary object which must support the (writeable,
  365. single segment) buffer interface and returns a pointer to a
  366. writeable memory location in buffer of size buffer_len.
  367. 0 is returned on success. buffer and buffer_len are only
  368. set in case no error occurs. Otherwise, -1 is returned and
  369. an exception set.
  370. */
  371. /* new buffer API */
  372. #define PyObject_CheckBuffer(obj) \
  373. (((obj)->ob_type->tp_as_buffer != NULL) && \
  374. (PyType_HasFeature((obj)->ob_type, Py_TPFLAGS_HAVE_NEWBUFFER)) && \
  375. ((obj)->ob_type->tp_as_buffer->bf_getbuffer != NULL))
  376. /* Return 1 if the getbuffer function is available, otherwise
  377. return 0 */
  378. PyAPI_FUNC(int) PyObject_GetBuffer(PyObject *obj, Py_buffer *view,
  379. int flags);
  380. /* This is a C-API version of the getbuffer function call. It checks
  381. to make sure object has the required function pointer and issues the
  382. call. Returns -1 and raises an error on failure and returns 0 on
  383. success
  384. */
  385. PyAPI_FUNC(void *) PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices);
  386. /* Get the memory area pointed to by the indices for the buffer given.
  387. Note that view->ndim is the assumed size of indices
  388. */
  389. PyAPI_FUNC(int) PyBuffer_SizeFromFormat(const char *);
  390. /* Return the implied itemsize of the data-format area from a
  391. struct-style description */
  392. PyAPI_FUNC(int) PyBuffer_ToContiguous(void *buf, Py_buffer *view,
  393. Py_ssize_t len, char fort);
  394. PyAPI_FUNC(int) PyBuffer_FromContiguous(Py_buffer *view, void *buf,
  395. Py_ssize_t len, char fort);
  396. /* Copy len bytes of data from the contiguous chunk of memory
  397. pointed to by buf into the buffer exported by obj. Return
  398. 0 on success and return -1 and raise a PyBuffer_Error on
  399. error (i.e. the object does not have a buffer interface or
  400. it is not working).
  401. If fort is 'F' and the object is multi-dimensional,
  402. then the data will be copied into the array in
  403. Fortran-style (first dimension varies the fastest). If
  404. fort is 'C', then the data will be copied into the array
  405. in C-style (last dimension varies the fastest). If fort
  406. is 'A', then it does not matter and the copy will be made
  407. in whatever way is more efficient.
  408. */
  409. PyAPI_FUNC(int) PyObject_CopyData(PyObject *dest, PyObject *src);
  410. /* Copy the data from the src buffer to the buffer of destination
  411. */
  412. PyAPI_FUNC(int) PyBuffer_IsContiguous(Py_buffer *view, char fort);
  413. PyAPI_FUNC(void) PyBuffer_FillContiguousStrides(int ndims,
  414. Py_ssize_t *shape,
  415. Py_ssize_t *strides,
  416. int itemsize,
  417. char fort);
  418. /* Fill the strides array with byte-strides of a contiguous
  419. (Fortran-style if fort is 'F' or C-style otherwise)
  420. array of the given shape with the given number of bytes
  421. per element.
  422. */
  423. PyAPI_FUNC(int) PyBuffer_FillInfo(Py_buffer *view, PyObject *o, void *buf,
  424. Py_ssize_t len, int readonly,
  425. int flags);
  426. /* Fills in a buffer-info structure correctly for an exporter
  427. that can only share a contiguous chunk of memory of
  428. "unsigned bytes" of the given length. Returns 0 on success
  429. and -1 (with raising an error) on error.
  430. */
  431. PyAPI_FUNC(void) PyBuffer_Release(Py_buffer *view);
  432. /* Releases a Py_buffer obtained from getbuffer ParseTuple's s*.
  433. */
  434. PyAPI_FUNC(PyObject *) PyObject_Format(PyObject* obj,
  435. PyObject *format_spec);
  436. /*
  437. Takes an arbitrary object and returns the result of
  438. calling obj.__format__(format_spec).
  439. */
  440. /* Iterators */
  441. PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *);
  442. /* Takes an object and returns an iterator for it.
  443. This is typically a new iterator but if the argument
  444. is an iterator, this returns itself. */
  445. #define PyIter_Check(obj) \
  446. (PyType_HasFeature((obj)->ob_type, Py_TPFLAGS_HAVE_ITER) && \
  447. (obj)->ob_type->tp_iternext != NULL && \
  448. (obj)->ob_type->tp_iternext != &_PyObject_NextNotImplemented)
  449. PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *);
  450. /* Takes an iterator object and calls its tp_iternext slot,
  451. returning the next value. If the iterator is exhausted,
  452. this returns NULL without setting an exception.
  453. NULL with an exception means an error occurred. */
  454. /* Number Protocol:*/
  455. PyAPI_FUNC(int) PyNumber_Check(PyObject *o);
  456. /*
  457. Returns 1 if the object, o, provides numeric protocols, and
  458. false otherwise.
  459. This function always succeeds.
  460. */
  461. PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2);
  462. /*
  463. Returns the result of adding o1 and o2, or null on failure.
  464. This is the equivalent of the Python expression: o1+o2.
  465. */
  466. PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2);
  467. /*
  468. Returns the result of subtracting o2 from o1, or null on
  469. failure. This is the equivalent of the Python expression:
  470. o1-o2.
  471. */
  472. PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2);
  473. /*
  474. Returns the result of multiplying o1 and o2, or null on
  475. failure. This is the equivalent of the Python expression:
  476. o1*o2.
  477. */
  478. PyAPI_FUNC(PyObject *) PyNumber_Divide(PyObject *o1, PyObject *o2);
  479. /*
  480. Returns the result of dividing o1 by o2, or null on failure.
  481. This is the equivalent of the Python expression: o1/o2.
  482. */
  483. PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2);
  484. /*
  485. Returns the result of dividing o1 by o2 giving an integral result,
  486. or null on failure.
  487. This is the equivalent of the Python expression: o1//o2.
  488. */
  489. PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2);
  490. /*
  491. Returns the result of dividing o1 by o2 giving a float result,
  492. or null on failure.
  493. This is the equivalent of the Python expression: o1/o2.
  494. */
  495. PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2);
  496. /*
  497. Returns the remainder of dividing o1 by o2, or null on
  498. failure. This is the equivalent of the Python expression:
  499. o1%o2.
  500. */
  501. PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2);
  502. /*
  503. See the built-in function divmod. Returns NULL on failure.
  504. This is the equivalent of the Python expression:
  505. divmod(o1,o2).
  506. */
  507. PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2,
  508. PyObject *o3);
  509. /*
  510. See the built-in function pow. Returns NULL on failure.
  511. This is the equivalent of the Python expression:
  512. pow(o1,o2,o3), where o3 is optional.
  513. */
  514. PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o);
  515. /*
  516. Returns the negation of o on success, or null on failure.
  517. This is the equivalent of the Python expression: -o.
  518. */
  519. PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o);
  520. /*
  521. Returns the (what?) of o on success, or NULL on failure.
  522. This is the equivalent of the Python expression: +o.
  523. */
  524. PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o);
  525. /*
  526. Returns the absolute value of o, or null on failure. This is
  527. the equivalent of the Python expression: abs(o).
  528. */
  529. PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o);
  530. /*
  531. Returns the bitwise negation of o on success, or NULL on
  532. failure. This is the equivalent of the Python expression:
  533. ~o.
  534. */
  535. PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2);
  536. /*
  537. Returns the result of left shifting o1 by o2 on success, or
  538. NULL on failure. This is the equivalent of the Python
  539. expression: o1 << o2.
  540. */
  541. PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2);
  542. /*
  543. Returns the result of right shifting o1 by o2 on success, or
  544. NULL on failure. This is the equivalent of the Python
  545. expression: o1 >> o2.
  546. */
  547. PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2);
  548. /*
  549. Returns the result of bitwise and of o1 and o2 on success, or
  550. NULL on failure. This is the equivalent of the Python
  551. expression: o1&o2.
  552. */
  553. PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2);
  554. /*
  555. Returns the bitwise exclusive or of o1 by o2 on success, or
  556. NULL on failure. This is the equivalent of the Python
  557. expression: o1^o2.
  558. */
  559. PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2);
  560. /*
  561. Returns the result of bitwise or on o1 and o2 on success, or
  562. NULL on failure. This is the equivalent of the Python
  563. expression: o1|o2.
  564. */
  565. /* Implemented elsewhere:
  566. int PyNumber_Coerce(PyObject **p1, PyObject **p2);
  567. This function takes the addresses of two variables of type
  568. PyObject*.
  569. If the objects pointed to by *p1 and *p2 have the same type,
  570. increment their reference count and return 0 (success).
  571. If the objects can be converted to a common numeric type,
  572. replace *p1 and *p2 by their converted value (with 'new'
  573. reference counts), and return 0.
  574. If no conversion is possible, or if some other error occurs,
  575. return -1 (failure) and don't increment the reference counts.
  576. The call PyNumber_Coerce(&o1, &o2) is equivalent to the Python
  577. statement o1, o2 = coerce(o1, o2).
  578. */
  579. #define PyIndex_Check(obj) \
  580. ((obj)->ob_type->tp_as_number != NULL && \
  581. PyType_HasFeature((obj)->ob_type, Py_TPFLAGS_HAVE_INDEX) && \
  582. (obj)->ob_type->tp_as_number->nb_index != NULL)
  583. PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o);
  584. /*
  585. Returns the object converted to a Python long or int
  586. or NULL with an error raised on failure.
  587. */
  588. PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc);
  589. /*
  590. Returns the Integral instance converted to an int. The
  591. instance is expected to be int or long or have an __int__
  592. method. Steals integral's reference. error_format will be
  593. used to create the TypeError if integral isn't actually an
  594. Integral instance. error_format should be a format string
  595. that can accept a char* naming integral's type.
  596. */
  597. PyAPI_FUNC(PyObject *) _PyNumber_ConvertIntegralToInt(
  598. PyObject *integral,
  599. const char* error_format);
  600. /*
  601. Returns the object converted to Py_ssize_t by going through
  602. PyNumber_Index first. If an overflow error occurs while
  603. converting the int-or-long to Py_ssize_t, then the second argument
  604. is the error-type to return. If it is NULL, then the overflow error
  605. is cleared and the value is clipped.
  606. */
  607. PyAPI_FUNC(PyObject *) PyNumber_Int(PyObject *o);
  608. /*
  609. Returns the o converted to an integer object on success, or
  610. NULL on failure. This is the equivalent of the Python
  611. expression: int(o).
  612. */
  613. PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o);
  614. /*
  615. Returns the o converted to a long integer object on success,
  616. or NULL on failure. This is the equivalent of the Python
  617. expression: long(o).
  618. */
  619. PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o);
  620. /*
  621. Returns the o converted to a float object on success, or NULL
  622. on failure. This is the equivalent of the Python expression:
  623. float(o).
  624. */
  625. /* In-place variants of (some of) the above number protocol functions */
  626. PyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2);
  627. /*
  628. Returns the result of adding o2 to o1, possibly in-place, or null
  629. on failure. This is the equivalent of the Python expression:
  630. o1 += o2.
  631. */
  632. PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2);
  633. /*
  634. Returns the result of subtracting o2 from o1, possibly in-place or
  635. null on failure. This is the equivalent of the Python expression:
  636. o1 -= o2.
  637. */
  638. PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2);
  639. /*
  640. Returns the result of multiplying o1 by o2, possibly in-place, or
  641. null on failure. This is the equivalent of the Python expression:
  642. o1 *= o2.
  643. */
  644. PyAPI_FUNC(PyObject *) PyNumber_InPlaceDivide(PyObject *o1, PyObject *o2);
  645. /*
  646. Returns the result of dividing o1 by o2, possibly in-place, or null
  647. on failure. This is the equivalent of the Python expression:
  648. o1 /= o2.
  649. */
  650. PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1,
  651. PyObject *o2);
  652. /*
  653. Returns the result of dividing o1 by o2 giving an integral result,
  654. possibly in-place, or null on failure.
  655. This is the equivalent of the Python expression:
  656. o1 /= o2.
  657. */
  658. PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1,
  659. PyObject *o2);
  660. /*
  661. Returns the result of dividing o1 by o2 giving a float result,
  662. possibly in-place, or null on failure.
  663. This is the equivalent of the Python expression:
  664. o1 /= o2.
  665. */
  666. PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2);
  667. /*
  668. Returns the remainder of dividing o1 by o2, possibly in-place, or
  669. null on failure. This is the equivalent of the Python expression:
  670. o1 %= o2.
  671. */
  672. PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2,
  673. PyObject *o3);
  674. /*
  675. Returns the result of raising o1 to the power of o2, possibly
  676. in-place, or null on failure. This is the equivalent of the Python
  677. expression: o1 **= o2, or pow(o1, o2, o3) if o3 is present.
  678. */
  679. PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2);
  680. /*
  681. Returns the result of left shifting o1 by o2, possibly in-place, or
  682. null on failure. This is the equivalent of the Python expression:
  683. o1 <<= o2.
  684. */
  685. PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2);
  686. /*
  687. Returns the result of right shifting o1 by o2, possibly in-place or
  688. null on failure. This is the equivalent of the Python expression:
  689. o1 >>= o2.
  690. */
  691. PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2);
  692. /*
  693. Returns the result of bitwise and of o1 and o2, possibly in-place,
  694. or null on failure. This is the equivalent of the Python
  695. expression: o1 &= o2.
  696. */
  697. PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2);
  698. /*
  699. Returns the bitwise exclusive or of o1 by o2, possibly in-place, or
  700. null on failure. This is the equivalent of the Python expression:
  701. o1 ^= o2.
  702. */
  703. PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2);
  704. /*
  705. Returns the result of bitwise or of o1 and o2, possibly in-place,
  706. or null on failure. This is the equivalent of the Python
  707. expression: o1 |= o2.
  708. */
  709. PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base);
  710. /*
  711. Returns the integer n converted to a string with a base, with a base
  712. marker of 0b, 0o or 0x prefixed if applicable.
  713. If n is not an int object, it is converted with PyNumber_Index first.
  714. */
  715. /* Sequence protocol:*/
  716. PyAPI_FUNC(int) PySequence_Check(PyObject *o);
  717. /*
  718. Return 1 if the object provides sequence protocol, and zero
  719. otherwise.
  720. This function always succeeds.
  721. */
  722. PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o);
  723. /*
  724. Return the size of sequence object o, or -1 on failure.
  725. */
  726. /* For DLL compatibility */
  727. #undef PySequence_Length
  728. PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o);
  729. #define PySequence_Length PySequence_Size
  730. PyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2);
  731. /*
  732. Return the concatenation of o1 and o2 on success, and NULL on
  733. failure. This is the equivalent of the Python
  734. expression: o1+o2.
  735. */
  736. PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count);
  737. /*
  738. Return the result of repeating sequence object o count times,
  739. or NULL on failure. This is the equivalent of the Python
  740. expression: o1*count.
  741. */
  742. PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i);
  743. /*
  744. Return the ith element of o, or NULL on failure. This is the
  745. equivalent of the Python expression: o[i].
  746. */
  747. PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
  748. /*
  749. Return the slice of sequence object o between i1 and i2, or
  750. NULL on failure. This is the equivalent of the Python
  751. expression: o[i1:i2].
  752. */
  753. PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v);
  754. /*
  755. Assign object v to the ith element of o. Returns
  756. -1 on failure. This is the equivalent of the Python
  757. statement: o[i]=v.
  758. */
  759. PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i);
  760. /*
  761. Delete the ith element of object v. Returns
  762. -1 on failure. This is the equivalent of the Python
  763. statement: del o[i].
  764. */
  765. PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2,
  766. PyObject *v);
  767. /*
  768. Assign the sequence object, v, to the slice in sequence
  769. object, o, from i1 to i2. Returns -1 on failure. This is the
  770. equivalent of the Python statement: o[i1:i2]=v.
  771. */
  772. PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
  773. /*
  774. Delete the slice in sequence object, o, from i1 to i2.
  775. Returns -1 on failure. This is the equivalent of the Python
  776. statement: del o[i1:i2].
  777. */
  778. PyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o);
  779. /*
  780. Returns the sequence, o, as a tuple on success, and NULL on failure.
  781. This is equivalent to the Python expression: tuple(o)
  782. */
  783. PyAPI_FUNC(PyObject *) PySequence_List(PyObject *o);
  784. /*
  785. Returns the sequence, o, as a list on success, and NULL on failure.
  786. This is equivalent to the Python expression: list(o)
  787. */
  788. PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m);
  789. /*
  790. Return the sequence, o, as a list, unless it's already a
  791. tuple or list. Use PySequence_Fast_GET_ITEM to access the
  792. members of this list, and PySequence_Fast_GET_SIZE to get its length.
  793. Returns NULL on failure. If the object does not support iteration,
  794. raises a TypeError exception with m as the message text.
  795. */
  796. #define PySequence_Fast_GET_SIZE(o) \
  797. (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o))
  798. /*
  799. Return the size of o, assuming that o was returned by
  800. PySequence_Fast and is not NULL.
  801. */
  802. #define PySequence_Fast_GET_ITEM(o, i)\
  803. (PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i))
  804. /*
  805. Return the ith element of o, assuming that o was returned by
  806. PySequence_Fast, and that i is within bounds.
  807. */
  808. #define PySequence_ITEM(o, i)\
  809. ( Py_TYPE(o)->tp_as_sequence->sq_item(o, i) )
  810. /* Assume tp_as_sequence and sq_item exist and that i does not
  811. need to be corrected for a negative index
  812. */
  813. #define PySequence_Fast_ITEMS(sf) \
  814. (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \
  815. : ((PyTupleObject *)(sf))->ob_item)
  816. /* Return a pointer to the underlying item array for
  817. an object retured by PySequence_Fast */
  818. PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value);
  819. /*
  820. Return the number of occurrences on value on o, that is,
  821. return the number of keys for which o[key]==value. On
  822. failure, return -1. This is equivalent to the Python
  823. expression: o.count(value).
  824. */
  825. PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob);
  826. /*
  827. Return -1 if error; 1 if ob in seq; 0 if ob not in seq.
  828. Use __contains__ if possible, else _PySequence_IterSearch().
  829. */
  830. #define PY_ITERSEARCH_COUNT 1
  831. #define PY_ITERSEARCH_INDEX 2
  832. #define PY_ITERSEARCH_CONTAINS 3
  833. PyAPI_FUNC(Py_ssize_t) _PySequence_IterSearch(PyObject *seq,
  834. PyObject *obj, int operation);
  835. /*
  836. Iterate over seq. Result depends on the operation:
  837. PY_ITERSEARCH_COUNT: return # of times obj appears in seq; -1 if
  838. error.
  839. PY_ITERSEARCH_INDEX: return 0-based index of first occurrence of
  840. obj in seq; set ValueError and return -1 if none found;
  841. also return -1 on error.
  842. PY_ITERSEARCH_CONTAINS: return 1 if obj in seq, else 0; -1 on
  843. error.
  844. */
  845. /* For DLL-level backwards compatibility */
  846. #undef PySequence_In
  847. PyAPI_FUNC(int) PySequence_In(PyObject *o, PyObject *value);
  848. /* For source-level backwards compatibility */
  849. #define PySequence_In PySequence_Contains
  850. /*
  851. Determine if o contains value. If an item in o is equal to
  852. X, return 1, otherwise return 0. On error, return -1. This
  853. is equivalent to the Python expression: value in o.
  854. */
  855. PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value);
  856. /*
  857. Return the first index for which o[i]=value. On error,
  858. return -1. This is equivalent to the Python
  859. expression: o.index(value).
  860. */
  861. /* In-place versions of some of the above Sequence functions. */
  862. PyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2);
  863. /*
  864. Append o2 to o1, in-place when possible. Return the resulting
  865. object, which could be o1, or NULL on failure. This is the
  866. equivalent of the Python expression: o1 += o2.
  867. */
  868. PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count);
  869. /*
  870. Repeat o1 by count, in-place when possible. Return the resulting
  871. object, which could be o1, or NULL on failure. This is the
  872. equivalent of the Python expression: o1 *= count.
  873. */
  874. /* Mapping protocol:*/
  875. PyAPI_FUNC(int) PyMapping_Check(PyObject *o);
  876. /*
  877. Return 1 if the object provides mapping protocol, and zero
  878. otherwise.
  879. This function always succeeds.
  880. */
  881. PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o);
  882. /*
  883. Returns the number of keys in object o on success, and -1 on
  884. failure. For objects that do not provide sequence protocol,
  885. this is equivalent to the Python expression: len(o).
  886. */
  887. /* For DLL compatibility */
  888. #undef PyMapping_Length
  889. PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o);
  890. #define PyMapping_Length PyMapping_Size
  891. /* implemented as a macro:
  892. int PyMapping_DelItemString(PyObject *o, char *key);
  893. Remove the mapping for object, key, from the object *o.
  894. Returns -1 on failure. This is equivalent to
  895. the Python statement: del o[key].
  896. */
  897. #define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K))
  898. /* implemented as a macro:
  899. int PyMapping_DelItem(PyObject *o, PyObject *key);
  900. Remove the mapping for object, key, from the object *o.
  901. Returns -1 on failure. This is equivalent to
  902. the Python statement: del o[key].
  903. */
  904. #define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K))
  905. PyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, char *key);
  906. /*
  907. On success, return 1 if the mapping object has the key, key,
  908. and 0 otherwise. This is equivalent to the Python expression:
  909. o.has_key(key).
  910. This function always succeeds.
  911. */
  912. PyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key);
  913. /*
  914. Return 1 if the mapping object has the key, key,
  915. and 0 otherwise. This is equivalent to the Python expression:
  916. o.has_key(key).
  917. This function always succeeds.
  918. */
  919. /* Implemented as macro:
  920. PyObject *PyMapping_Keys(PyObject *o);
  921. On success, return a list of the keys in object o. On
  922. failure, return NULL. This is equivalent to the Python
  923. expression: o.keys().
  924. */
  925. #define PyMapping_Keys(O) PyObject_CallMethod(O,"keys",NULL)
  926. /* Implemented as macro:
  927. PyObject *PyMapping_Values(PyObject *o);
  928. On success, return a list of the values in object o. On
  929. failure, return NULL. This is equivalent to the Python
  930. expression: o.values().
  931. */
  932. #define PyMapping_Values(O) PyObject_CallMethod(O,"values",NULL)
  933. /* Implemented as macro:
  934. PyObject *PyMapping_Items(PyObject *o);
  935. On success, return a list of the items in object o, where
  936. each item is a tuple containing a key-value pair. On
  937. failure, return NULL. This is equivalent to the Python
  938. expression: o.items().
  939. */
  940. #define PyMapping_Items(O) PyObject_CallMethod(O,"items",NULL)
  941. PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o, char *key);
  942. /*
  943. Return element of o corresponding to the object, key, or NULL
  944. on failure. This is the equivalent of the Python expression:
  945. o[key].
  946. */
  947. PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, char *key,
  948. PyObject *value);
  949. /*
  950. Map the object, key, to the value, v. Returns
  951. -1 on failure. This is the equivalent of the Python
  952. statement: o[key]=v.
  953. */
  954. PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass);
  955. /* isinstance(object, typeorclass) */
  956. PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass);
  957. /* issubclass(object, typeorclass) */
  958. PyAPI_FUNC(int) _PyObject_RealIsInstance(PyObject *inst, PyObject *cls);
  959. PyAPI_FUNC(int) _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls);
  960. /* For internal use by buffer API functions */
  961. PyAPI_FUNC(void) _Py_add_one_to_index_F(int nd, Py_ssize_t *index,
  962. const Py_ssize_t *shape);
  963. PyAPI_FUNC(void) _Py_add_one_to_index_C(int nd, Py_ssize_t *index,
  964. const Py_ssize_t *shape);
  965. #ifdef __cplusplus
  966. }
  967. #endif
  968. #endif /* Py_ABSTRACTOBJECT_H */