PageRenderTime 58ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/pypy/module/cpyext/stubs.py

https://bitbucket.org/dac_io/pypy
Python | 2505 lines | 2496 code | 5 blank | 4 comment | 1 complexity | 5ce6b99c9b4a05d4f8e0cbd3476c305a MD5 | raw file
  1. from pypy.module.cpyext.api import (
  2. cpython_api, PyObject, PyObjectP, CANNOT_FAIL
  3. )
  4. from pypy.module.cpyext.complexobject import Py_complex_ptr as Py_complex
  5. from pypy.rpython.lltypesystem import rffi, lltype
  6. # we don't really care
  7. PyTypeObjectPtr = rffi.VOIDP
  8. Py_ssize_t = rffi.SSIZE_T
  9. PyMethodDef = rffi.VOIDP
  10. PyGetSetDef = rffi.VOIDP
  11. PyMemberDef = rffi.VOIDP
  12. Py_buffer = rffi.VOIDP
  13. va_list = rffi.VOIDP
  14. PyDateTime_Date = rffi.VOIDP
  15. PyDateTime_DateTime = rffi.VOIDP
  16. PyDateTime_Time = rffi.VOIDP
  17. wrapperbase = rffi.VOIDP
  18. FILE = rffi.VOIDP
  19. PyFileObject = rffi.VOIDP
  20. PyCodeObject = rffi.VOIDP
  21. PyFrameObject = rffi.VOIDP
  22. PyFloatObject = rffi.VOIDP
  23. _inittab = rffi.VOIDP
  24. PyThreadState = rffi.VOIDP
  25. PyInterpreterState = rffi.VOIDP
  26. Py_UNICODE = lltype.UniChar
  27. PyCompilerFlags = rffi.VOIDP
  28. _node = rffi.VOIDP
  29. Py_tracefunc = rffi.VOIDP
  30. @cpython_api([PyObject], lltype.Void)
  31. def _PyObject_Del(space, op):
  32. raise NotImplementedError
  33. @cpython_api([rffi.CCHARP], Py_ssize_t, error=CANNOT_FAIL)
  34. def PyBuffer_SizeFromFormat(space, format):
  35. """Return the implied ~Py_buffer.itemsize from the struct-stype
  36. ~Py_buffer.format."""
  37. raise NotImplementedError
  38. @cpython_api([rffi.INT_real, Py_ssize_t, Py_ssize_t, Py_ssize_t, lltype.Char], lltype.Void)
  39. def PyBuffer_FillContiguousStrides(space, ndim, shape, strides, itemsize, fortran):
  40. """Fill the strides array with byte-strides of a contiguous (C-style if
  41. fortran is 'C' or Fortran-style if fortran is 'F' array of the
  42. given shape with the given number of bytes per element."""
  43. raise NotImplementedError
  44. @cpython_api([Py_buffer], PyObject)
  45. def PyMemoryView_FromBuffer(space, view):
  46. """Create a memoryview object wrapping the given buffer-info structure view.
  47. The memoryview object then owns the buffer, which means you shouldn't
  48. try to release it yourself: it will be released on deallocation of the
  49. memoryview object."""
  50. raise NotImplementedError
  51. @cpython_api([PyObject, rffi.INT_real, lltype.Char], PyObject)
  52. def PyMemoryView_GetContiguous(space, obj, buffertype, order):
  53. """Create a memoryview object to a contiguous chunk of memory (in either
  54. 'C' or 'F'ortran order) from an object that defines the buffer
  55. interface. If memory is contiguous, the memoryview object points to the
  56. original memory. Otherwise copy is made and the memoryview points to a
  57. new bytes object."""
  58. raise NotImplementedError
  59. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  60. def PyMemoryView_Check(space, obj):
  61. """Return true if the object obj is a memoryview object. It is not
  62. currently allowed to create subclasses of memoryview."""
  63. raise NotImplementedError
  64. @cpython_api([PyObject], Py_buffer)
  65. def PyMemoryView_GET_BUFFER(space, obj):
  66. """Return a pointer to the buffer-info structure wrapped by the given
  67. object. The object must be a memoryview instance; this macro doesn't
  68. check its type, you must do it yourself or you will risk crashes."""
  69. raise NotImplementedError
  70. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  71. def PyByteArray_Check(space, o):
  72. """Return true if the object o is a bytearray object or an instance of a
  73. subtype of the bytearray type."""
  74. raise NotImplementedError
  75. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  76. def PyByteArray_CheckExact(space, o):
  77. """Return true if the object o is a bytearray object, but not an instance of a
  78. subtype of the bytearray type."""
  79. raise NotImplementedError
  80. @cpython_api([PyObject], PyObject)
  81. def PyByteArray_FromObject(space, o):
  82. """Return a new bytearray object from any object, o, that implements the
  83. buffer protocol.
  84. XXX expand about the buffer protocol, at least somewhere"""
  85. raise NotImplementedError
  86. @cpython_api([rffi.CCHARP, Py_ssize_t], PyObject)
  87. def PyByteArray_FromStringAndSize(space, string, len):
  88. """Create a new bytearray object from string and its length, len. On
  89. failure, NULL is returned."""
  90. raise NotImplementedError
  91. @cpython_api([PyObject, PyObject], PyObject)
  92. def PyByteArray_Concat(space, a, b):
  93. """Concat bytearrays a and b and return a new bytearray with the result."""
  94. raise NotImplementedError
  95. @cpython_api([PyObject], Py_ssize_t, error=-1)
  96. def PyByteArray_Size(space, bytearray):
  97. """Return the size of bytearray after checking for a NULL pointer."""
  98. raise NotImplementedError
  99. @cpython_api([PyObject], rffi.CCHARP)
  100. def PyByteArray_AsString(space, bytearray):
  101. """Return the contents of bytearray as a char array after checking for a
  102. NULL pointer."""
  103. raise NotImplementedError
  104. @cpython_api([PyObject, Py_ssize_t], rffi.INT_real, error=-1)
  105. def PyByteArray_Resize(space, bytearray, len):
  106. """Resize the internal buffer of bytearray to len."""
  107. raise NotImplementedError
  108. @cpython_api([PyObject], rffi.CCHARP)
  109. def PyByteArray_AS_STRING(space, bytearray):
  110. """Macro version of PyByteArray_AsString()."""
  111. raise NotImplementedError
  112. @cpython_api([PyObject], Py_ssize_t, error=-1)
  113. def PyByteArray_GET_SIZE(space, bytearray):
  114. """Macro version of PyByteArray_Size()."""
  115. raise NotImplementedError
  116. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  117. def PyCell_Check(space, ob):
  118. """Return true if ob is a cell object; ob must not be NULL."""
  119. raise NotImplementedError
  120. @cpython_api([PyObject], PyObject)
  121. def PyCell_New(space, ob):
  122. """Create and return a new cell object containing the value ob. The parameter may
  123. be NULL."""
  124. raise NotImplementedError
  125. @cpython_api([PyObject], PyObject)
  126. def PyCell_Get(space, cell):
  127. """Return the contents of the cell cell."""
  128. raise NotImplementedError
  129. @cpython_api([PyObject], PyObject)
  130. def PyCell_GET(space, cell):
  131. """Return the contents of the cell cell, but without checking that cell is
  132. non-NULL and a cell object."""
  133. borrow_from()
  134. raise NotImplementedError
  135. @cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
  136. def PyCell_Set(space, cell, value):
  137. """Set the contents of the cell object cell to value. This releases the
  138. reference to any current content of the cell. value may be NULL. cell
  139. must be non-NULL; if it is not a cell object, -1 will be returned. On
  140. success, 0 will be returned."""
  141. raise NotImplementedError
  142. @cpython_api([PyObject, PyObject], lltype.Void)
  143. def PyCell_SET(space, cell, value):
  144. """Sets the value of the cell object cell to value. No reference counts are
  145. adjusted, and no checks are made for safety; cell must be non-NULL and must
  146. be a cell object."""
  147. raise NotImplementedError
  148. @cpython_api([PyObject, PyObject], rffi.INT_real, error=CANNOT_FAIL)
  149. def PyClass_IsSubclass(space, klass, base):
  150. """Return true if klass is a subclass of base. Return false in all other cases."""
  151. raise NotImplementedError
  152. @cpython_api([PyObject, PyObject, PyObject], PyObject)
  153. def PyInstance_New(space, cls, arg, kw):
  154. """Create a new instance of a specific class. The parameters arg and kw are
  155. used as the positional and keyword parameters to the object's constructor."""
  156. raise NotImplementedError
  157. @cpython_api([PyObject], rffi.INT_real, error=-1)
  158. def PyCodec_Register(space, search_function):
  159. """Register a new codec search function.
  160. As side effect, this tries to load the encodings package, if not yet
  161. done, to make sure that it is always first in the list of search functions."""
  162. raise NotImplementedError
  163. @cpython_api([PyObject, rffi.CCHARP, rffi.CCHARP], PyObject)
  164. def PyCodec_Encode(space, object, encoding, errors):
  165. """Generic codec based encoding API.
  166. object is passed through the encoder function found for the given
  167. encoding using the error handling method defined by errors. errors may
  168. be NULL to use the default method defined for the codec. Raises a
  169. LookupError if no encoder can be found."""
  170. raise NotImplementedError
  171. @cpython_api([PyObject, rffi.CCHARP, rffi.CCHARP], PyObject)
  172. def PyCodec_Decode(space, object, encoding, errors):
  173. """Generic codec based decoding API.
  174. object is passed through the decoder function found for the given
  175. encoding using the error handling method defined by errors. errors may
  176. be NULL to use the default method defined for the codec. Raises a
  177. LookupError if no encoder can be found."""
  178. raise NotImplementedError
  179. @cpython_api([rffi.CCHARP], PyObject)
  180. def PyCodec_Encoder(space, encoding):
  181. """Get an encoder function for the given encoding."""
  182. raise NotImplementedError
  183. @cpython_api([rffi.CCHARP], PyObject)
  184. def PyCodec_Decoder(space, encoding):
  185. """Get a decoder function for the given encoding."""
  186. raise NotImplementedError
  187. @cpython_api([rffi.CCHARP, PyObject, rffi.CCHARP], PyObject)
  188. def PyCodec_StreamReader(space, encoding, stream, errors):
  189. """Get a StreamReader factory function for the given encoding."""
  190. raise NotImplementedError
  191. @cpython_api([rffi.CCHARP, PyObject, rffi.CCHARP], PyObject)
  192. def PyCodec_StreamWriter(space, encoding, stream, errors):
  193. """Get a StreamWriter factory function for the given encoding."""
  194. raise NotImplementedError
  195. @cpython_api([rffi.CCHARP, PyObject], rffi.INT_real, error=-1)
  196. def PyCodec_RegisterError(space, name, error):
  197. """Register the error handling callback function error under the given name.
  198. This callback function will be called by a codec when it encounters
  199. unencodable characters/undecodable bytes and name is specified as the error
  200. parameter in the call to the encode/decode function.
  201. The callback gets a single argument, an instance of
  202. UnicodeEncodeError, UnicodeDecodeError or
  203. UnicodeTranslateError that holds information about the problematic
  204. sequence of characters or bytes and their offset in the original string (see
  205. unicodeexceptions for functions to extract this information). The
  206. callback must either raise the given exception, or return a two-item tuple
  207. containing the replacement for the problematic sequence, and an integer
  208. giving the offset in the original string at which encoding/decoding should be
  209. resumed.
  210. Return 0 on success, -1 on error."""
  211. raise NotImplementedError
  212. @cpython_api([rffi.CCHARP], PyObject)
  213. def PyCodec_LookupError(space, name):
  214. """Lookup the error handling callback function registered under name. As a
  215. special case NULL can be passed, in which case the error handling callback
  216. for "strict" will be returned."""
  217. raise NotImplementedError
  218. @cpython_api([PyObject], PyObject)
  219. def PyCodec_StrictErrors(space, exc):
  220. """Raise exc as an exception."""
  221. raise NotImplementedError
  222. @cpython_api([PyObject], PyObject)
  223. def PyCodec_IgnoreErrors(space, exc):
  224. """Ignore the unicode error, skipping the faulty input."""
  225. raise NotImplementedError
  226. @cpython_api([PyObject], PyObject)
  227. def PyCodec_ReplaceErrors(space, exc):
  228. """Replace the unicode encode error with ? or U+FFFD."""
  229. raise NotImplementedError
  230. @cpython_api([PyObject], PyObject)
  231. def PyCodec_XMLCharRefReplaceErrors(space, exc):
  232. """Replace the unicode encode error with XML character references."""
  233. raise NotImplementedError
  234. @cpython_api([PyObject], PyObject)
  235. def PyCodec_BackslashReplaceErrors(space, exc):
  236. r"""Replace the unicode encode error with backslash escapes (\x, \u and
  237. \U)."""
  238. raise NotImplementedError
  239. @cpython_api([Py_complex, Py_complex], Py_complex)
  240. def _Py_c_sum(space, left, right):
  241. """Return the sum of two complex numbers, using the C Py_complex
  242. representation."""
  243. raise NotImplementedError
  244. @cpython_api([Py_complex, Py_complex], Py_complex)
  245. def _Py_c_diff(space, left, right):
  246. """Return the difference between two complex numbers, using the C
  247. Py_complex representation."""
  248. raise NotImplementedError
  249. @cpython_api([Py_complex], Py_complex)
  250. def _Py_c_neg(space, complex):
  251. """Return the negation of the complex number complex, using the C
  252. Py_complex representation."""
  253. raise NotImplementedError
  254. @cpython_api([Py_complex, Py_complex], Py_complex)
  255. def _Py_c_prod(space, left, right):
  256. """Return the product of two complex numbers, using the C Py_complex
  257. representation."""
  258. raise NotImplementedError
  259. @cpython_api([Py_complex, Py_complex], Py_complex)
  260. def _Py_c_quot(space, dividend, divisor):
  261. """Return the quotient of two complex numbers, using the C Py_complex
  262. representation."""
  263. raise NotImplementedError
  264. @cpython_api([Py_complex, Py_complex], Py_complex)
  265. def _Py_c_pow(space, num, exp):
  266. """Return the exponentiation of num by exp, using the C Py_complex
  267. representation."""
  268. raise NotImplementedError
  269. @cpython_api([Py_complex], PyObject)
  270. def PyComplex_FromCComplex(space, v):
  271. """Create a new Python complex number object from a C Py_complex value."""
  272. raise NotImplementedError
  273. @cpython_api([rffi.CCHARP, rffi.CCHARPP], rffi.DOUBLE, error=CANNOT_FAIL)
  274. def PyOS_ascii_strtod(space, nptr, endptr):
  275. """Convert a string to a double. This function behaves like the Standard C
  276. function strtod() does in the C locale. It does this without changing the
  277. current locale, since that would not be thread-safe.
  278. PyOS_ascii_strtod() should typically be used for reading configuration
  279. files or other non-user input that should be locale independent.
  280. See the Unix man page strtod(2) for details.
  281. Use PyOS_string_to_double() instead."""
  282. raise NotImplementedError
  283. @cpython_api([rffi.CCHARP, rffi.SIZE_T, rffi.CCHARP, rffi.DOUBLE], rffi.CCHARP)
  284. def PyOS_ascii_formatd(space, buffer, buf_len, format, d):
  285. """Convert a double to a string using the '.' as the decimal
  286. separator. format is a printf()-style format string specifying the
  287. number format. Allowed conversion characters are 'e', 'E', 'f',
  288. 'F', 'g' and 'G'.
  289. The return value is a pointer to buffer with the converted string or NULL if
  290. the conversion failed.
  291. This function is removed in Python 2.7 and 3.1. Use PyOS_double_to_string()
  292. instead."""
  293. raise NotImplementedError
  294. @cpython_api([rffi.DOUBLE, lltype.Char, rffi.INT_real, rffi.INT_real, rffi.INTP], rffi.CCHARP)
  295. def PyOS_double_to_string(space, val, format_code, precision, flags, ptype):
  296. """Convert a double val to a string using supplied
  297. format_code, precision, and flags.
  298. format_code must be one of 'e', 'E', 'f', 'F',
  299. 'g', 'G' or 'r'. For 'r', the supplied precision
  300. must be 0 and is ignored. The 'r' format code specifies the
  301. standard repr() format.
  302. flags can be zero or more of the values Py_DTSF_SIGN,
  303. Py_DTSF_ADD_DOT_0, or Py_DTSF_ALT, or-ed together:
  304. Py_DTSF_SIGN means to always precede the returned string with a sign
  305. character, even if val is non-negative.
  306. Py_DTSF_ADD_DOT_0 means to ensure that the returned string will not look
  307. like an integer.
  308. Py_DTSF_ALT means to apply "alternate" formatting rules. See the
  309. documentation for the PyOS_snprintf() '#' specifier for
  310. details.
  311. If ptype is non-NULL, then the value it points to will be set to one of
  312. Py_DTST_FINITE, Py_DTST_INFINITE, or Py_DTST_NAN, signifying that
  313. val is a finite number, an infinite number, or not a number, respectively.
  314. The return value is a pointer to buffer with the converted string or
  315. NULL if the conversion failed. The caller is responsible for freeing the
  316. returned string by calling PyMem_Free().
  317. """
  318. raise NotImplementedError
  319. @cpython_api([rffi.CCHARP], rffi.DOUBLE, error=CANNOT_FAIL)
  320. def PyOS_ascii_atof(space, nptr):
  321. """Convert a string to a double in a locale-independent way.
  322. See the Unix man page atof(2) for details.
  323. Use PyOS_string_to_double() instead."""
  324. raise NotImplementedError
  325. @cpython_api([rffi.CCHARP, rffi.CCHARP], rffi.CCHARP)
  326. def PyOS_stricmp(space, s1, s2):
  327. """Case insensitive comparison of strings. The function works almost
  328. identically to strcmp() except that it ignores the case.
  329. """
  330. raise NotImplementedError
  331. @cpython_api([rffi.CCHARP, rffi.CCHARP, Py_ssize_t], rffi.CCHARP)
  332. def PyOS_strnicmp(space, s1, s2, size):
  333. """Case insensitive comparison of strings. The function works almost
  334. identically to strncmp() except that it ignores the case.
  335. """
  336. raise NotImplementedError
  337. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  338. def PyTZInfo_Check(space, ob):
  339. """Return true if ob is of type PyDateTime_TZInfoType or a subtype of
  340. PyDateTime_TZInfoType. ob must not be NULL.
  341. """
  342. raise NotImplementedError
  343. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  344. def PyTZInfo_CheckExact(space, ob):
  345. """Return true if ob is of type PyDateTime_TZInfoType. ob must not be
  346. NULL.
  347. """
  348. raise NotImplementedError
  349. @cpython_api([PyTypeObjectPtr, PyGetSetDef], PyObject)
  350. def PyDescr_NewGetSet(space, type, getset):
  351. raise NotImplementedError
  352. @cpython_api([PyTypeObjectPtr, PyMemberDef], PyObject)
  353. def PyDescr_NewMember(space, type, meth):
  354. raise NotImplementedError
  355. @cpython_api([PyTypeObjectPtr, wrapperbase, rffi.VOIDP], PyObject)
  356. def PyDescr_NewWrapper(space, type, wrapper, wrapped):
  357. raise NotImplementedError
  358. @cpython_api([PyTypeObjectPtr, PyMethodDef], PyObject)
  359. def PyDescr_NewClassMethod(space, type, method):
  360. raise NotImplementedError
  361. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  362. def PyDescr_IsData(space, descr):
  363. """Return true if the descriptor objects descr describes a data attribute, or
  364. false if it describes a method. descr must be a descriptor object; there is
  365. no error checking.
  366. """
  367. raise NotImplementedError
  368. @cpython_api([PyObject, PyObject], PyObject)
  369. def PyWrapper_New(space, w_d, w_self):
  370. raise NotImplementedError
  371. @cpython_api([PyObject, PyObject, rffi.INT_real], rffi.INT_real, error=-1)
  372. def PyDict_Merge(space, a, b, override):
  373. """Iterate over mapping object b adding key-value pairs to dictionary a.
  374. b may be a dictionary, or any object supporting PyMapping_Keys()
  375. and PyObject_GetItem(). If override is true, existing pairs in a
  376. will be replaced if a matching key is found in b, otherwise pairs will
  377. only be added if there is not a matching key in a. Return 0 on
  378. success or -1 if an exception was raised.
  379. """
  380. raise NotImplementedError
  381. @cpython_api([PyObject, PyObject, rffi.INT_real], rffi.INT_real, error=-1)
  382. def PyDict_MergeFromSeq2(space, a, seq2, override):
  383. """Update or merge into dictionary a, from the key-value pairs in seq2.
  384. seq2 must be an iterable object producing iterable objects of length 2,
  385. viewed as key-value pairs. In case of duplicate keys, the last wins if
  386. override is true, else the first wins. Return 0 on success or -1
  387. if an exception was raised. Equivalent Python (except for the return
  388. value):
  389. def PyDict_MergeFromSeq2(a, seq2, override):
  390. for key, value in seq2:
  391. if override or key not in a:
  392. a[key] = value
  393. """
  394. raise NotImplementedError
  395. @cpython_api([rffi.INT_real], PyObject)
  396. def PyErr_SetFromWindowsErr(space, ierr):
  397. """This is a convenience function to raise WindowsError. If called with
  398. ierr of 0, the error code returned by a call to GetLastError()
  399. is used instead. It calls the Win32 function FormatMessage() to retrieve
  400. the Windows description of error code given by ierr or GetLastError(),
  401. then it constructs a tuple object whose first item is the ierr value and whose
  402. second item is the corresponding error message (gotten from
  403. FormatMessage()), and then calls PyErr_SetObject(PyExc_WindowsError,
  404. object). This function always returns NULL. Availability: Windows.
  405. Return value: always NULL."""
  406. raise NotImplementedError
  407. @cpython_api([PyObject, rffi.INT_real], PyObject)
  408. def PyErr_SetExcFromWindowsErr(space, type, ierr):
  409. """Similar to PyErr_SetFromWindowsErr(), with an additional parameter
  410. specifying the exception type to be raised. Availability: Windows.
  411. Return value: always NULL."""
  412. raise NotImplementedError
  413. @cpython_api([rffi.INT_real, rffi.CCHARP], PyObject)
  414. def PyErr_SetFromWindowsErrWithFilename(space, ierr, filename):
  415. """Similar to PyErr_SetFromWindowsErr(), with the additional behavior that
  416. if filename is not NULL, it is passed to the constructor of
  417. WindowsError as a third parameter. Availability: Windows.
  418. Return value: always NULL."""
  419. raise NotImplementedError
  420. @cpython_api([PyObject, rffi.INT_real, rffi.CCHARP], PyObject)
  421. def PyErr_SetExcFromWindowsErrWithFilename(space, type, ierr, filename):
  422. """Similar to PyErr_SetFromWindowsErrWithFilename(), with an additional
  423. parameter specifying the exception type to be raised. Availability: Windows.
  424. Return value: always NULL."""
  425. raise NotImplementedError
  426. @cpython_api([PyObject, rffi.CCHARP, rffi.CCHARP, rffi.INT_real, rffi.CCHARP, PyObject], rffi.INT_real, error=-1)
  427. def PyErr_WarnExplicit(space, category, message, filename, lineno, module, registry):
  428. """Issue a warning message with explicit control over all warning attributes. This
  429. is a straightforward wrapper around the Python function
  430. warnings.warn_explicit(), see there for more information. The module
  431. and registry arguments may be set to NULL to get the default effect
  432. described there."""
  433. raise NotImplementedError
  434. @cpython_api([rffi.INT_real], rffi.INT_real, error=CANNOT_FAIL)
  435. def PySignal_SetWakeupFd(space, fd):
  436. """This utility function specifies a file descriptor to which a '\0' byte will
  437. be written whenever a signal is received. It returns the previous such file
  438. descriptor. The value -1 disables the feature; this is the initial state.
  439. This is equivalent to signal.set_wakeup_fd() in Python, but without any
  440. error checking. fd should be a valid file descriptor. The function should
  441. only be called from the main thread."""
  442. raise NotImplementedError
  443. @cpython_api([rffi.CCHARP, rffi.CCHARP, Py_ssize_t, Py_ssize_t, Py_ssize_t, rffi.CCHARP], PyObject)
  444. def PyUnicodeDecodeError_Create(space, encoding, object, length, start, end, reason):
  445. """Create a UnicodeDecodeError object with the attributes encoding,
  446. object, length, start, end and reason."""
  447. raise NotImplementedError
  448. @cpython_api([rffi.CCHARP, rffi.CWCHARP, Py_ssize_t, Py_ssize_t, Py_ssize_t, rffi.CCHARP], PyObject)
  449. def PyUnicodeEncodeError_Create(space, encoding, object, length, start, end, reason):
  450. """Create a UnicodeEncodeError object with the attributes encoding,
  451. object, length, start, end and reason."""
  452. raise NotImplementedError
  453. @cpython_api([rffi.CWCHARP, Py_ssize_t, Py_ssize_t, Py_ssize_t, rffi.CCHARP], PyObject)
  454. def PyUnicodeTranslateError_Create(space, object, length, start, end, reason):
  455. """Create a UnicodeTranslateError object with the attributes object,
  456. length, start, end and reason."""
  457. raise NotImplementedError
  458. @cpython_api([PyObject], PyObject)
  459. def PyUnicodeDecodeError_GetEncoding(space, exc):
  460. """Return the encoding attribute of the given exception object."""
  461. raise NotImplementedError
  462. @cpython_api([PyObject], PyObject)
  463. def PyUnicodeDecodeError_GetObject(space, exc):
  464. """Return the object attribute of the given exception object."""
  465. raise NotImplementedError
  466. @cpython_api([PyObject, Py_ssize_t], rffi.INT_real, error=-1)
  467. def PyUnicodeDecodeError_GetStart(space, exc, start):
  468. """Get the start attribute of the given exception object and place it into
  469. *start. start must not be NULL. Return 0 on success, -1 on
  470. failure."""
  471. raise NotImplementedError
  472. @cpython_api([PyObject, Py_ssize_t], rffi.INT_real, error=-1)
  473. def PyUnicodeDecodeError_SetStart(space, exc, start):
  474. """Set the start attribute of the given exception object to start. Return
  475. 0 on success, -1 on failure."""
  476. raise NotImplementedError
  477. @cpython_api([PyObject, Py_ssize_t], rffi.INT_real, error=-1)
  478. def PyUnicodeDecodeError_GetEnd(space, exc, end):
  479. """Get the end attribute of the given exception object and place it into
  480. *end. end must not be NULL. Return 0 on success, -1 on
  481. failure."""
  482. raise NotImplementedError
  483. @cpython_api([PyObject, Py_ssize_t], rffi.INT_real, error=-1)
  484. def PyUnicodeDecodeError_SetEnd(space, exc, end):
  485. """Set the end attribute of the given exception object to end. Return 0
  486. on success, -1 on failure."""
  487. raise NotImplementedError
  488. @cpython_api([PyObject], PyObject)
  489. def PyUnicodeDecodeError_GetReason(space, exc):
  490. """Return the reason attribute of the given exception object."""
  491. raise NotImplementedError
  492. @cpython_api([PyObject, rffi.CCHARP], rffi.INT_real, error=-1)
  493. def PyUnicodeDecodeError_SetReason(space, exc, reason):
  494. """Set the reason attribute of the given exception object to reason. Return
  495. 0 on success, -1 on failure."""
  496. raise NotImplementedError
  497. @cpython_api([rffi.CCHARP], rffi.INT_real, error=1)
  498. def Py_EnterRecursiveCall(space, where):
  499. """Marks a point where a recursive C-level call is about to be performed.
  500. If USE_STACKCHECK is defined, this function checks if the the OS
  501. stack overflowed using PyOS_CheckStack(). In this is the case, it
  502. sets a MemoryError and returns a nonzero value.
  503. The function then checks if the recursion limit is reached. If this is the
  504. case, a RuntimeError is set and a nonzero value is returned.
  505. Otherwise, zero is returned.
  506. where should be a string such as " in instance check" to be
  507. concatenated to the RuntimeError message caused by the recursion depth
  508. limit."""
  509. raise NotImplementedError
  510. @cpython_api([], lltype.Void)
  511. def Py_LeaveRecursiveCall(space):
  512. """Ends a Py_EnterRecursiveCall(). Must be called once for each
  513. successful invocation of Py_EnterRecursiveCall()."""
  514. raise NotImplementedError
  515. @cpython_api([PyFileObject], lltype.Void)
  516. def PyFile_IncUseCount(space, p):
  517. """Increments the PyFileObject's internal use count to indicate
  518. that the underlying FILE* is being used.
  519. This prevents Python from calling f_close() on it from another thread.
  520. Callers of this must call PyFile_DecUseCount() when they are
  521. finished with the FILE*. Otherwise the file object will
  522. never be closed by Python.
  523. The GIL must be held while calling this function.
  524. The suggested use is to call this after PyFile_AsFile() and before
  525. you release the GIL:
  526. FILE *fp = PyFile_AsFile(p);
  527. PyFile_IncUseCount(p);
  528. /* ... */
  529. Py_BEGIN_ALLOW_THREADS
  530. do_something(fp);
  531. Py_END_ALLOW_THREADS
  532. /* ... */
  533. PyFile_DecUseCount(p);
  534. """
  535. raise NotImplementedError
  536. @cpython_api([PyFileObject], lltype.Void)
  537. def PyFile_DecUseCount(space, p):
  538. """Decrements the PyFileObject's internal unlocked_count member to
  539. indicate that the caller is done with its own use of the FILE*.
  540. This may only be called to undo a prior call to PyFile_IncUseCount().
  541. The GIL must be held while calling this function (see the example
  542. above).
  543. """
  544. raise NotImplementedError
  545. @cpython_api([PyFileObject, rffi.CCHARP], rffi.INT_real, error=0)
  546. def PyFile_SetEncoding(space, p, enc):
  547. """Set the file's encoding for Unicode output to enc. Return 1 on success and 0
  548. on failure.
  549. """
  550. raise NotImplementedError
  551. @cpython_api([PyFileObject, rffi.CCHARP, rffi.CCHARP], rffi.INT_real, error=0)
  552. def PyFile_SetEncodingAndErrors(space, p, enc, errors):
  553. """Set the file's encoding for Unicode output to enc, and its error
  554. mode to err. Return 1 on success and 0 on failure.
  555. """
  556. raise NotImplementedError
  557. @cpython_api([], PyObject)
  558. def PyFloat_GetInfo(space):
  559. """Return a structseq instance which contains information about the
  560. precision, minimum and maximum values of a float. It's a thin wrapper
  561. around the header file float.h.
  562. """
  563. raise NotImplementedError
  564. @cpython_api([], rffi.DOUBLE, error=CANNOT_FAIL)
  565. def PyFloat_GetMax(space):
  566. """Return the maximum representable finite float DBL_MAX as C double.
  567. """
  568. raise NotImplementedError
  569. @cpython_api([], rffi.DOUBLE, error=CANNOT_FAIL)
  570. def PyFloat_GetMin(space):
  571. """Return the minimum normalized positive float DBL_MIN as C double.
  572. """
  573. raise NotImplementedError
  574. @cpython_api([], rffi.INT_real, error=CANNOT_FAIL)
  575. def PyFloat_ClearFreeList(space):
  576. """Clear the float free list. Return the number of items that could not
  577. be freed.
  578. """
  579. raise NotImplementedError
  580. @cpython_api([rffi.CCHARP, PyFloatObject], lltype.Void)
  581. def PyFloat_AsString(space, buf, v):
  582. """Convert the argument v to a string, using the same rules as
  583. str(). The length of buf should be at least 100.
  584. This function is unsafe to call because it writes to a buffer whose
  585. length it does not know.
  586. Use PyObject_Str() or PyOS_double_to_string() instead."""
  587. raise NotImplementedError
  588. @cpython_api([rffi.CCHARP, PyFloatObject], lltype.Void)
  589. def PyFloat_AsReprString(space, buf, v):
  590. """Same as PyFloat_AsString, except uses the same rules as
  591. repr(). The length of buf should be at least 100.
  592. This function is unsafe to call because it writes to a buffer whose
  593. length it does not know.
  594. Use PyObject_Repr() or PyOS_double_to_string() instead."""
  595. raise NotImplementedError
  596. @cpython_api([PyObject, PyObject], PyObject)
  597. def PyFunction_New(space, code, globals):
  598. """Return a new function object associated with the code object code. globals
  599. must be a dictionary with the global variables accessible to the function.
  600. The function's docstring, name and __module__ are retrieved from the code
  601. object, the argument defaults and closure are set to NULL."""
  602. raise NotImplementedError
  603. @cpython_api([PyObject], PyObject)
  604. def PyFunction_GetGlobals(space, op):
  605. """Return the globals dictionary associated with the function object op."""
  606. borrow_from()
  607. raise NotImplementedError
  608. @cpython_api([PyObject], PyObject)
  609. def PyFunction_GetModule(space, op):
  610. """Return the __module__ attribute of the function object op. This is normally
  611. a string containing the module name, but can be set to any other object by
  612. Python code."""
  613. borrow_from()
  614. raise NotImplementedError
  615. @cpython_api([PyObject], PyObject)
  616. def PyFunction_GetDefaults(space, op):
  617. """Return the argument default values of the function object op. This can be a
  618. tuple of arguments or NULL."""
  619. borrow_from()
  620. raise NotImplementedError
  621. @cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
  622. def PyFunction_SetDefaults(space, op, defaults):
  623. """Set the argument default values for the function object op. defaults must be
  624. Py_None or a tuple.
  625. Raises SystemError and returns -1 on failure."""
  626. raise NotImplementedError
  627. @cpython_api([PyObject], PyObject)
  628. def PyFunction_GetClosure(space, op):
  629. """Return the closure associated with the function object op. This can be NULL
  630. or a tuple of cell objects."""
  631. borrow_from()
  632. raise NotImplementedError
  633. @cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
  634. def PyFunction_SetClosure(space, op, closure):
  635. """Set the closure associated with the function object op. closure must be
  636. Py_None or a tuple of cell objects.
  637. Raises SystemError and returns -1 on failure."""
  638. raise NotImplementedError
  639. @cpython_api([PyTypeObjectPtr, Py_ssize_t], PyObject)
  640. def PyObject_GC_NewVar(space, type, size):
  641. """Analogous to PyObject_NewVar() but for container objects with the
  642. Py_TPFLAGS_HAVE_GC flag set.
  643. This function used an int type for size. This might require
  644. changes in your code for properly supporting 64-bit systems."""
  645. raise NotImplementedError
  646. @cpython_api([PyObject, Py_ssize_t], PyObject)
  647. def PyObject_GC_Resize(space, op, newsize):
  648. """Resize an object allocated by PyObject_NewVar(). Returns the
  649. resized object or NULL on failure.
  650. This function used an int type for newsize. This might
  651. require changes in your code for properly supporting 64-bit systems."""
  652. raise NotImplementedError
  653. @cpython_api([PyObject], lltype.Void)
  654. def _PyObject_GC_TRACK(space, op):
  655. """A macro version of PyObject_GC_Track(). It should not be used for
  656. extension modules."""
  657. raise NotImplementedError
  658. @cpython_api([PyObject], lltype.Void)
  659. def _PyObject_GC_UNTRACK(space, op):
  660. """A macro version of PyObject_GC_UnTrack(). It should not be used for
  661. extension modules."""
  662. raise NotImplementedError
  663. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  664. def PyGen_Check(space, ob):
  665. """Return true if ob is a generator object; ob must not be NULL."""
  666. raise NotImplementedError
  667. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  668. def PyGen_CheckExact(space, ob):
  669. """Return true if ob's type is PyGen_Type is a generator object; ob must not
  670. be NULL."""
  671. raise NotImplementedError
  672. @cpython_api([PyFrameObject], PyObject)
  673. def PyGen_New(space, frame):
  674. """Create and return a new generator object based on the frame object. A
  675. reference to frame is stolen by this function. The parameter must not be
  676. NULL."""
  677. raise NotImplementedError
  678. @cpython_api([rffi.CCHARP, PyObject, PyObject, PyObject], PyObject)
  679. def PyImport_ImportModuleEx(space, name, globals, locals, fromlist):
  680. """Import a module. This is best described by referring to the built-in
  681. Python function __import__(), as the standard __import__() function calls
  682. this function directly.
  683. The return value is a new reference to the imported module or top-level package,
  684. or NULL with an exception set on failure (before Python 2.4, the module may
  685. still be created in this case). Like for __import__(), the return value
  686. when a submodule of a package was requested is normally the top-level package,
  687. unless a non-empty fromlist was given.
  688. Failing imports remove incomplete module objects.
  689. The function is an alias for PyImport_ImportModuleLevel() with
  690. -1 as level, meaning relative import."""
  691. raise NotImplementedError
  692. @cpython_api([rffi.CCHARP, PyObject, PyObject, PyObject, rffi.INT_real], PyObject)
  693. def PyImport_ImportModuleLevel(space, name, globals, locals, fromlist, level):
  694. """Import a module. This is best described by referring to the built-in Python
  695. function __import__(), as the standard __import__() function calls
  696. this function directly.
  697. The return value is a new reference to the imported module or top-level package,
  698. or NULL with an exception set on failure. Like for __import__(),
  699. the return value when a submodule of a package was requested is normally the
  700. top-level package, unless a non-empty fromlist was given.
  701. """
  702. raise NotImplementedError
  703. @cpython_api([], lltype.Signed, error=CANNOT_FAIL)
  704. def PyImport_GetMagicNumber(space):
  705. """Return the magic number for Python bytecode files (a.k.a. .pyc and
  706. .pyo files). The magic number should be present in the first four bytes
  707. of the bytecode file, in little-endian byte order."""
  708. raise NotImplementedError
  709. @cpython_api([PyObject], PyObject)
  710. def PyImport_GetImporter(space, path):
  711. """Return an importer object for a sys.path/pkg.__path__ item
  712. path, possibly by fetching it from the sys.path_importer_cache
  713. dict. If it wasn't yet cached, traverse sys.path_hooks until a hook
  714. is found that can handle the path item. Return None if no hook could;
  715. this tells our caller it should fall back to the built-in import mechanism.
  716. Cache the result in sys.path_importer_cache. Return a new reference
  717. to the importer object.
  718. """
  719. raise NotImplementedError
  720. @cpython_api([], lltype.Void)
  721. def _PyImport_Init(space):
  722. """Initialize the import mechanism. For internal use only."""
  723. raise NotImplementedError
  724. @cpython_api([], lltype.Void)
  725. def PyImport_Cleanup(space):
  726. """Empty the module table. For internal use only."""
  727. raise NotImplementedError
  728. @cpython_api([], lltype.Void)
  729. def _PyImport_Fini(space):
  730. """Finalize the import mechanism. For internal use only."""
  731. raise NotImplementedError
  732. @cpython_api([rffi.CCHARP, rffi.CCHARP], PyObject)
  733. def _PyImport_FindExtension(space, name, filename):
  734. """For internal use only."""
  735. raise NotImplementedError
  736. @cpython_api([rffi.CCHARP, rffi.CCHARP], PyObject)
  737. def _PyImport_FixupExtension(space, name, filename):
  738. """For internal use only."""
  739. raise NotImplementedError
  740. @cpython_api([rffi.CCHARP], rffi.INT_real, error=-1)
  741. def PyImport_ImportFrozenModule(space, name):
  742. """Load a frozen module named name. Return 1 for success, 0 if the
  743. module is not found, and -1 with an exception set if the initialization
  744. failed. To access the imported module on a successful load, use
  745. PyImport_ImportModule(). (Note the misnomer --- this function would
  746. reload the module if it was already imported.)"""
  747. raise NotImplementedError
  748. @cpython_api([rffi.CCHARP, rffi.VOIDP], rffi.INT_real, error=-1)
  749. def PyImport_AppendInittab(space, name, initfunc):
  750. """Add a single module to the existing table of built-in modules. This is a
  751. convenience wrapper around PyImport_ExtendInittab(), returning -1 if
  752. the table could not be extended. The new module can be imported by the name
  753. name, and uses the function initfunc as the initialization function called
  754. on the first attempted import. This should be called before
  755. Py_Initialize()."""
  756. raise NotImplementedError
  757. @cpython_api([_inittab], rffi.INT_real, error=-1)
  758. def PyImport_ExtendInittab(space, newtab):
  759. """Add a collection of modules to the table of built-in modules. The newtab
  760. array must end with a sentinel entry which contains NULL for the name
  761. field; failure to provide the sentinel value can result in a memory fault.
  762. Returns 0 on success or -1 if insufficient memory could be allocated to
  763. extend the internal table. In the event of failure, no modules are added to the
  764. internal table. This should be called before Py_Initialize()."""
  765. raise NotImplementedError
  766. @cpython_api([], lltype.Void)
  767. def Py_Initialize(space):
  768. """Initialize the Python interpreter. In an application embedding Python,
  769. this should be called before using any other Python/C API functions; with
  770. the exception of Py_SetProgramName(), PyEval_InitThreads(),
  771. PyEval_ReleaseLock(), and PyEval_AcquireLock(). This initializes the table
  772. of loaded modules (sys.modules), and creates the fundamental modules
  773. __builtin__, __main__ and sys. It also initializes the module search path
  774. (sys.path). It does not set sys.argv; use PySys_SetArgvEx() for that. This
  775. is a no-op when called for a second time (without calling Py_Finalize()
  776. first). There is no return value; it is a fatal error if the initialization
  777. fails."""
  778. raise NotImplementedError
  779. @cpython_api([rffi.INT_real], lltype.Void)
  780. def Py_InitializeEx(space, initsigs):
  781. """This function works like Py_Initialize() if initsigs is 1. If
  782. initsigs is 0, it skips initialization registration of signal handlers, which
  783. might be useful when Python is embedded.
  784. """
  785. raise NotImplementedError
  786. @cpython_api([], lltype.Void)
  787. def Py_Finalize(space):
  788. """Undo all initializations made by Py_Initialize() and subsequent use of
  789. Python/C API functions, and destroy all sub-interpreters (see
  790. Py_NewInterpreter() below) that were created and not yet destroyed since
  791. the last call to Py_Initialize(). Ideally, this frees all memory
  792. allocated by the Python interpreter. This is a no-op when called for a second
  793. time (without calling Py_Initialize() again first). There is no return
  794. value; errors during finalization are ignored.
  795. This function is provided for a number of reasons. An embedding application
  796. might want to restart Python without having to restart the application itself.
  797. An application that has loaded the Python interpreter from a dynamically
  798. loadable library (or DLL) might want to free all memory allocated by Python
  799. before unloading the DLL. During a hunt for memory leaks in an application a
  800. developer might want to free all memory allocated by Python before exiting from
  801. the application.
  802. Bugs and caveats: The destruction of modules and objects in modules is done
  803. in random order; this may cause destructors (__del__() methods) to fail
  804. when they depend on other objects (even functions) or modules. Dynamically
  805. loaded extension modules loaded by Python are not unloaded. Small amounts of
  806. memory allocated by the Python interpreter may not be freed (if you find a leak,
  807. please report it). Memory tied up in circular references between objects is not
  808. freed. Some memory allocated by extension modules may not be freed. Some
  809. extensions may not work properly if their initialization routine is called more
  810. than once; this can happen if an application calls Py_Initialize() and
  811. Py_Finalize() more than once."""
  812. raise NotImplementedError
  813. @cpython_api([rffi.CCHARP], lltype.Void)
  814. def Py_SetProgramName(space, name):
  815. """This function should be called before Py_Initialize() is called for the
  816. first time, if it is called at all. It tells the interpreter the value of
  817. the argv[0] argument to the main() function of the program. This is used by
  818. Py_GetPath() and some other functions below to find the Python run-time
  819. libraries relative to the interpreter executable. The default value is
  820. 'python'. The argument should point to a zero-terminated character string
  821. in static storage whose contents will not change for the duration of the
  822. program's execution. No code in the Python interpreter will change the
  823. contents of this storage."""
  824. raise NotImplementedError
  825. @cpython_api([], rffi.CCHARP)
  826. def Py_GetPrefix(space):
  827. """Return the prefix for installed platform-independent files. This is derived
  828. through a number of complicated rules from the program name set with
  829. Py_SetProgramName() and some environment variables; for example, if the
  830. program name is '/usr/local/bin/python', the prefix is '/usr/local'. The
  831. returned string points into static storage; the caller should not modify its
  832. value. This corresponds to the prefix variable in the top-level
  833. Makefile and the --prefix argument to the configure
  834. script at build time. The value is available to Python code as sys.prefix.
  835. It is only useful on Unix. See also the next function."""
  836. raise NotImplementedError
  837. @cpython_api([], rffi.CCHARP)
  838. def Py_GetExecPrefix(space):
  839. """Return the exec-prefix for installed platform-dependent files. This is
  840. derived through a number of complicated rules from the program name set with
  841. Py_SetProgramName() and some environment variables; for example, if the
  842. program name is '/usr/local/bin/python', the exec-prefix is
  843. '/usr/local'. The returned string points into static storage; the caller
  844. should not modify its value. This corresponds to the exec_prefix
  845. variable in the top-level Makefile and the --exec-prefix
  846. argument to the configure script at build time. The value is
  847. available to Python code as sys.exec_prefix. It is only useful on Unix.
  848. Background: The exec-prefix differs from the prefix when platform dependent
  849. files (such as executables and shared libraries) are installed in a different
  850. directory tree. In a typical installation, platform dependent files may be
  851. installed in the /usr/local/plat subtree while platform independent may
  852. be installed in /usr/local.
  853. Generally speaking, a platform is a combination of hardware and software
  854. families, e.g. Sparc machines running the Solaris 2.x operating system are
  855. considered the same platform, but Intel machines running Solaris 2.x are another
  856. platform, and Intel machines running Linux are yet another platform. Different
  857. major revisions of the same operating system generally also form different
  858. platforms. Non-Unix operating systems are a different story; the installation
  859. strategies on those systems are so different that the prefix and exec-prefix are
  860. meaningless, and set to the empty string. Note that compiled Python bytecode
  861. files are platform independent (but not independent from the Python version by
  862. which they were compiled!).
  863. System administrators will know how to configure the mount or
  864. automount programs to share /usr/local between platforms
  865. while having /usr/local/plat be a different filesystem for each
  866. platform."""
  867. raise NotImplementedError
  868. @cpython_api([], rffi.CCHARP)
  869. def Py_GetProgramFullPath(space):
  870. """Return the full program name of the Python executable; this is computed
  871. as a side-effect of deriving the default module search path from the program
  872. name (set by Py_SetProgramName() above). The returned string points into
  873. static storage; the caller should not modify its value. The value is
  874. available to Python code as sys.executable."""
  875. raise NotImplementedError
  876. @cpython_api([], rffi.CCHARP)
  877. def Py_GetPath(space):
  878. """Return the default module search path; this is computed from the program
  879. name (set by Py_SetProgramName() above) and some environment variables. The
  880. returned string consists of a series of directory names separated by a
  881. platform dependent delimiter character. The delimiter character is ':' on
  882. Unix and Mac OS X, ';' on Windows. The returned string points into static
  883. storage; the caller should not modify its value. The list sys.path is
  884. initialized with this value on interpreter startup; it can be (and usually
  885. is) modified later to change the search path for loading modules.
  886. XXX should give the exact rules"""
  887. raise NotImplementedError
  888. @cpython_api([], rffi.CCHARP)
  889. def Py_GetPlatform(space):
  890. """Return the platform identifier for the current platform. On Unix, this
  891. is formed from the"official" name of the operating system, converted to lower
  892. case, followed by the major revision number; e.g., for Solaris 2.x, which is
  893. also known as SunOS 5.x, the value is 'sunos5'. On Mac OS X, it is
  894. 'darwin'. On Windows, it is 'win'. The returned string points into
  895. static storage; the caller should not modify its value. The value is available
  896. to Python code as sys.platform."""
  897. raise NotImplementedError
  898. @cpython_api([], rffi.CCHARP)
  899. def Py_GetCopyright(space):
  900. """Return the official copyright string for the current Python version, for example
  901. 'Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam'
  902. The returned string points into static storage; the caller should not modify its
  903. value. The value is available to Python code as sys.copyright."""
  904. raise NotImplementedError
  905. @cpython_api([], rffi.CCHARP)
  906. def Py_GetCompiler(space):
  907. """Return an indication of the compiler used to build the current Python version,
  908. in square brackets, for example:
  909. "[GCC 2.7.2.2]"
  910. The returned string points into static storage; the caller should not modify its
  911. value. The value is available to Python code as part of the variable
  912. sys.version."""
  913. raise NotImplementedError
  914. @cpython_api([], rffi.CCHARP)
  915. def Py_GetBuildInfo(space):
  916. """Return information about the sequence number and build date and time of the
  917. current Python interpreter instance, for example
  918. "\#67, Aug 1 1997, 22:34:28"
  919. The returned string points into static storage; the caller should not modify its
  920. value. The value is available to Python code as part of the variable
  921. sys.version."""
  922. raise NotImplementedError
  923. @cpython_api([rffi.INT_real, rffi.CCHARPP, rffi.INT_real], lltype.Void)
  924. def PySys_SetArgvEx(space, argc, argv, updatepath):
  925. """Set sys.argv based on argc and argv. These parameters are similar to
  926. those passed to the program's main() function with the difference that the
  927. first entry should refer to the script file to be executed rather than the
  928. executable hosting the Python interpreter. If there isn't a script that
  929. will be run, the first entry in argv can be an empty string. If this
  930. function fails to initialize sys.argv, a fatal condition is signalled using
  931. Py_FatalError().
  932. If updatepath is zero, this is all the function does. If updatepath
  933. is non-zero, the function also modifies sys.path according to the
  934. following algorithm:
  935. If the name of an existing script is passed in argv[0], the absolute
  936. path of the directory where the script is located is prepended to
  937. sys.path.
  938. Otherwise (that is, if argc is 0 or argv[0] doesn't point
  939. to an existing file name), an empty string is prepended to
  940. sys.path, which is the same as prepending the current working
  941. directory (".").
  942. It is recommended that applications embedding the Python interpreter
  943. for purposes other than executing a single script pass 0 as updatepath,
  944. and update sys.path themselves if desired.
  945. See CVE-2008-5983.
  946. On versions before 2.6.6, you can achieve the same effect by manually
  947. popping the first sys.path element after having called
  948. PySys_SetArgv(), for example using:
  949. PyRun_SimpleString("import sys; sys.path.pop(0)\n");
  950. XXX impl. doesn't seem consistent in allowing 0/NULL for the params;
  951. check w/ Guido."""
  952. raise NotImplementedError
  953. @cpython_api([rffi.INT_real, rffi.CCHARPP], lltype.Void)
  954. def PySys_SetArgv(space, argc, argv):
  955. """This function works like PySys_SetArgvEx() with updatepath set to 1."""
  956. raise NotImplementedError
  957. @cpython_api([rffi.CCHARP], lltype.Void)
  958. def Py_SetPythonHome(space, home):
  959. """Set the default "home" directory, that is, the location of the standard
  960. Python libraries. See PYTHONHOME for the meaning of the
  961. argument string.
  962. The argument should point to a zero-terminated character string in static
  963. storage whose contents will not change for the duration of the program's
  964. execution. No code in the Python interpreter will change the contents of
  965. this storage."""
  966. raise NotImplementedError
  967. @cpython_api([], rffi.CCHARP)
  968. def Py_GetPythonHome(space):
  969. """Return the default "home", that is, the value set by a previous call to
  970. Py_SetPythonHome(), or the value of the PYTHONHOME
  971. environment variable if it is set."""
  972. raise NotImplementedError
  973. @cpython_api([], lltype.Void)
  974. def PyEval_ReInitThreads(space):
  975. """This function is called from PyOS_AfterFork() to ensure that newly
  976. created child processes don't hold locks referring to threads which
  977. are not running in the child process."""
  978. raise NotImplementedError
  979. @cpython_api([], PyInterpreterState)
  980. def PyInterpreterState_New(space):
  981. """Create a new interpreter state object. The global interpreter lock need not
  982. be held, but may be held if it is necessary to serialize calls to this
  983. function."""
  984. raise NotImplementedError
  985. @cpython_api([PyInterpreterState], lltype.Void)
  986. def PyInterpreterState_Clear(space, interp):
  987. """Reset all information in an interpreter state object. The global interpreter
  988. lock must be held."""
  989. raise NotImplementedError
  990. @cpython_api([PyInterpreterState], lltype.Void)
  991. def PyInterpreterState_Delete(space, interp):
  992. """Destroy an interpreter state object. The global interpreter lock need not be
  993. held. The interpreter state must have been reset with a previous call to
  994. PyInterpreterState_Clear()."""
  995. raise NotImplementedError
  996. @cpython_api([], PyObject)
  997. def PyThreadState_GetDict(space):
  998. """Return a dictionary in which extensions can store thread-specific state
  999. information. Each extension should use a unique key to use to store state in
  1000. the dictionary. It is okay to call this function when no current thread state
  1001. is available. If this function returns NULL, no exception has been raised and
  1002. the caller should assume no current thread state is available.
  1003. Previously this could only be called when a current thread is active, and NULL
  1004. meant that an exception was raised."""
  1005. borrow_from()
  1006. raise NotImplementedError
  1007. @cpython_api([lltype.Signed, PyObject], rffi.INT_real, error=CANNOT_FAIL)
  1008. def PyThreadState_SetAsyncExc(space, id, exc):
  1009. """Asynchronously raise an exception in a thread. The id argument is the thread
  1010. id of the target thread; exc is the exception object to be raised. This
  1011. function does not steal any references to exc. To prevent naive misuse, you
  1012. must write your own C extension to call this. Must be called with the GIL held.
  1013. Returns the number of thread states modified; this is normally one, but will be
  1014. zero if the thread id isn't found. If exc is NULL, the pending
  1015. exception (if any) for the thread is cleared. This raises no exceptions.
  1016. """
  1017. raise NotImplementedError
  1018. @cpython_api([], lltype.Void)
  1019. def PyEval_AcquireLock(space):
  1020. """Acquire the global interpreter lock. The lock must have been created earlier.
  1021. If this thread already has the lock, a deadlock ensues.
  1022. This function does not change the current thread state. Please use
  1023. PyEval_RestoreThread() or PyEval_AcquireThread()
  1024. instead."""
  1025. raise NotImplementedError
  1026. @cpython_api([], lltype.Void)
  1027. def PyEval_ReleaseLock(space):
  1028. """Release the global interpreter lock. The lock must have been created earlier.
  1029. This function does not change the current thread state. Please use
  1030. PyEval_SaveThread() or PyEval_ReleaseThread()
  1031. instead."""
  1032. raise NotImplementedError
  1033. @cpython_api([], PyThreadState)
  1034. def Py_NewInterpreter(space):
  1035. """Create a new sub-interpreter. This is an (almost) totally separate
  1036. environment for the execution of Python code. In particular, the new
  1037. interpreter has separate, independent versions of all imported modules,
  1038. including the fundamental modules builtins, __main__ and sys. The table of
  1039. loaded modules (sys.modules) and the module search path (sys.path) are also
  1040. separate. The new environment has no sys.argv variable. It has new standard
  1041. I/O stream file objects sys.stdin, sys.stdout and sys.stderr (however these
  1042. refer to the same underlying file descriptors).
  1043. The return value points to the first thread state created in the new
  1044. sub-interpreter. This thread state is made in the current thread state.
  1045. Note that no actual thread is created; see the discussion of thread states
  1046. below. If creation of the new interpreter is unsuccessful, NULL is
  1047. returned; no exception is set since the exception state is stored in the
  1048. current thread state and there may not be a current thread state. (Like all
  1049. other Python/C API functions, the global interpreter lock must be held before
  1050. calling this function and is still held when it returns; however, unlike most
  1051. other Python/C API functions, there needn't be a current thread state on
  1052. entry.)
  1053. Extension modules are shared between (sub-)interpreters as follows: the first
  1054. time a particular extension is imported, it is initialized normally, and a
  1055. (shallow) copy of its module's dictionary is squirreled away. When the same
  1056. extension is imported by another (sub-)interpreter, a new module is initialized
  1057. and filled with the contents of this copy; the extension's init function is
  1058. not called. Note that this is different from what happens when an extension is
  1059. imported after the interpreter has been completely re-initialized by calling
  1060. Py_Finalize() and Py_Initialize(); in that case, the extension's
  1061. initmodule function is called again."""
  1062. raise NotImplementedError
  1063. @cpython_api([PyThreadState], lltype.Void)
  1064. def Py_EndInterpreter(space, tstate):
  1065. """Destroy the (sub-)interpreter represented by the given thread state. The
  1066. given thread state must be the current thread state. See the discussion of
  1067. thread states below. When the call returns, the current thread state is
  1068. NULL. All thread states associated with this interpreter are destroyed.
  1069. (The global interpreter lock must be held before calling this function and is
  1070. still held when it returns.) Py_Finalize() will destroy all sub-interpreters
  1071. that haven't been explicitly destroyed at that point."""
  1072. raise NotImplementedError
  1073. @cpython_api([Py_tracefunc, PyObject], lltype.Void)
  1074. def PyEval_SetProfile(space, func, obj):
  1075. """Set the profiler function to func. The obj parameter is passed to the
  1076. function as its first parameter, and may be any Python object, or NULL. If
  1077. the profile function needs to maintain state, using a different value for obj
  1078. for each thread provides a convenient and thread-safe place to store it. The
  1079. profile function is called for all monitored events except the line-number
  1080. events."""
  1081. raise NotImplementedError
  1082. @cpython_api([Py_tracefunc, PyObject], lltype.Void)
  1083. def PyEval_SetTrace(space, func, obj):
  1084. """Set the tracing function to func. This is similar to
  1085. PyEval_SetProfile(), except the tracing function does receive line-number
  1086. events."""
  1087. raise NotImplementedError
  1088. @cpython_api([PyObject], PyObject)
  1089. def PyEval_GetCallStats(space, self):
  1090. """Return a tuple of function call counts. There are constants defined for the
  1091. positions within the tuple:
  1092. Name
  1093. Value
  1094. PCALL_ALL
  1095. 0
  1096. PCALL_FUNCTION
  1097. 1
  1098. PCALL_FAST_FUNCTION
  1099. 2
  1100. PCALL_FASTER_FUNCTION
  1101. 3
  1102. PCALL_METHOD
  1103. 4
  1104. PCALL_BOUND_METHOD
  1105. 5
  1106. PCALL_CFUNCTION
  1107. 6
  1108. PCALL_TYPE
  1109. 7
  1110. PCALL_GENERATOR
  1111. 8
  1112. PCALL_OTHER
  1113. 9
  1114. PCALL_POP
  1115. 10
  1116. PCALL_FAST_FUNCTION means no argument tuple needs to be created.
  1117. PCALL_FASTER_FUNCTION means that the fast-path frame setup code is used.
  1118. If there is a method call where the call can be optimized by changing
  1119. the argument tuple and calling the function directly, it gets recorded
  1120. twice.
  1121. This function is only present if Python is compiled with CALL_PROFILE
  1122. defined."""
  1123. raise NotImplementedError
  1124. @cpython_api([PyInterpreterState], PyThreadState)
  1125. def PyInterpreterState_ThreadHead(space, interp):
  1126. """Return the a pointer to the first PyThreadState object in the list of
  1127. threads associated with the interpreter interp.
  1128. """
  1129. raise NotImplementedError
  1130. @cpython_api([PyThreadState], PyThreadState)
  1131. def PyThreadState_Next(space, tstate):
  1132. """Return the next thread state object after tstate from the list of all such
  1133. objects belonging to the same PyInterpreterState object.
  1134. """
  1135. raise NotImplementedError
  1136. @cpython_api([PyObject], rffi.ULONGLONG, error=-1)
  1137. def PyInt_AsUnsignedLongLongMask(space, io):
  1138. """Will first attempt to cast the object to a PyIntObject or
  1139. PyLongObject, if it is not already one, and then return its value as
  1140. unsigned long long, without checking for overflow.
  1141. """
  1142. raise NotImplementedError
  1143. @cpython_api([], rffi.INT_real, error=CANNOT_FAIL)
  1144. def PyInt_ClearFreeList(space):
  1145. """Clear the integer free list. Return the number of items that could not
  1146. be freed.
  1147. """
  1148. raise NotImplementedError
  1149. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  1150. def PySeqIter_Check(space, op):
  1151. """Return true if the type of op is PySeqIter_Type.
  1152. """
  1153. raise NotImplementedError
  1154. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  1155. def PyCallIter_Check(space, op):
  1156. """Return true if the type of op is PyCallIter_Type.
  1157. """
  1158. raise NotImplementedError
  1159. @cpython_api([PyObject, Py_ssize_t, Py_ssize_t], PyObject)
  1160. def PyList_GetSlice(space, list, low, high):
  1161. """Return a list of the objects in list containing the objects between low
  1162. and high. Return NULL and set an exception if unsuccessful. Analogous
  1163. to list[low:high]. Negative indices, as when slicing from Python, are not
  1164. supported.
  1165. This function used an int for low and high. This might
  1166. require changes in your code for properly supporting 64-bit systems."""
  1167. raise NotImplementedError
  1168. @cpython_api([Py_ssize_t], PyObject)
  1169. def PyLong_FromSsize_t(space, v):
  1170. """Return a new PyLongObject object from a C Py_ssize_t, or
  1171. NULL on failure.
  1172. """
  1173. raise NotImplementedError
  1174. @cpython_api([rffi.SIZE_T], PyObject)
  1175. def PyLong_FromSize_t(space, v):
  1176. """Return a new PyLongObject object from a C size_t, or
  1177. NULL on failure.
  1178. """
  1179. raise NotImplementedError
  1180. @cpython_api([rffi.CWCHARP, Py_ssize_t, rffi.INT_real], PyObject)
  1181. def PyLong_FromUnicode(space, u, length, base):
  1182. """Convert a sequence of Unicode digits to a Python long integer value. The first
  1183. parameter, u, points to the first character of the Unicode string, length
  1184. gives the number of characters, and base is the radix for the conversion. The
  1185. radix must be in the range [2, 36]; if it is out of range, ValueError
  1186. will be raised.
  1187. This function used an int for length. This might require
  1188. changes in your code for properly supporting 64-bit systems."""
  1189. raise NotImplementedError
  1190. @cpython_api([PyObject], Py_ssize_t, error=-1)
  1191. def PyLong_AsSsize_t(space, pylong):
  1192. """Return a C Py_ssize_t representation of the contents of pylong. If
  1193. pylong is greater than PY_SSIZE_T_MAX, an OverflowError is raised
  1194. and -1 will be returned.
  1195. """
  1196. raise NotImplementedError
  1197. @cpython_api([PyObject, rffi.CCHARP], rffi.INT_real, error=-1)
  1198. def PyMapping_DelItemString(space, o, key):
  1199. """Remove the mapping for object key from the object o. Return -1 on
  1200. failure. This is equivalent to the Python statement del o[key]."""
  1201. raise NotImplementedError
  1202. @cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
  1203. def PyMapping_DelItem(space, o, key):
  1204. """Remove the mapping for object key from the object o. Return -1 on
  1205. failure. This is equivalent to the Python statement del o[key]."""
  1206. raise NotImplementedError
  1207. @cpython_api([lltype.Signed, FILE, rffi.INT_real], lltype.Void)
  1208. def PyMarshal_WriteLongToFile(space, value, file, version):
  1209. """Marshal a long integer, value, to file. This will only write
  1210. the least-significant 32 bits of value; regardless of the size of the
  1211. native long type.
  1212. version indicates the file format."""
  1213. raise NotImplementedError
  1214. @cpython_api([PyObject, FILE, rffi.INT_real], lltype.Void)
  1215. def PyMarshal_WriteObjectToFile(space, value, file, version):
  1216. """Marshal a Python object, value, to file.
  1217. version indicates the file format."""
  1218. raise NotImplementedError
  1219. @cpython_api([PyObject, rffi.INT_real], PyObject)
  1220. def PyMarshal_WriteObjectToString(space, value, version):
  1221. """Return a string object containing the marshalled representation of value.
  1222. version indicates the file format."""
  1223. raise NotImplementedError
  1224. @cpython_api([FILE], lltype.Signed, error=CANNOT_FAIL)
  1225. def PyMarshal_ReadLongFromFile(space, file):
  1226. """Return a C long from the data stream in a FILE* opened
  1227. for reading. Only a 32-bit value can be read in using this function,
  1228. regardless of the native size of long."""
  1229. raise NotImplementedError
  1230. @cpython_api([FILE], rffi.INT_real, error=CANNOT_FAIL)
  1231. def PyMarshal_ReadShortFromFile(space, file):
  1232. """Return a C short from the data stream in a FILE* opened
  1233. for reading. Only a 16-bit value can be read in using this function,
  1234. regardless of the native size of short."""
  1235. raise NotImplementedError
  1236. @cpython_api([FILE], PyObject)
  1237. def PyMarshal_ReadObjectFromFile(space, file):
  1238. """Return a Python object from the data stream in a FILE* opened for
  1239. reading. On error, sets the appropriate exception (EOFError or
  1240. TypeError) and returns NULL."""
  1241. raise NotImplementedError
  1242. @cpython_api([FILE], PyObject)
  1243. def PyMarshal_ReadLastObjectFromFile(space, file):
  1244. """Return a Python object from the data stream in a FILE* opened for
  1245. reading. Unlike PyMarshal_ReadObjectFromFile(), this function
  1246. assumes that no further objects will be read from the file, allowing it to
  1247. aggressively load file data into memory so that the de-serialization can
  1248. operate from data in memory rather than reading a byte at a time from the
  1249. file. Only use these variant if you are certain that you won't be reading
  1250. anything else from the file. On error, sets the appropriate exception
  1251. (EOFError or TypeError) and returns NULL."""
  1252. raise NotImplementedError
  1253. @cpython_api([rffi.CCHARP, Py_ssize_t], PyObject)
  1254. def PyMarshal_ReadObjectFromString(space, string, len):
  1255. """Return a Python object from the data stream in a character buffer
  1256. containing len bytes pointed to by string. On error, sets the
  1257. appropriate exception (EOFError or TypeError) and returns
  1258. NULL.
  1259. This function used an int type for len. This might require
  1260. changes in your code for properly supporting 64-bit systems."""
  1261. raise NotImplementedError
  1262. @cpython_api([], rffi.INT_real, error=CANNOT_FAIL)
  1263. def PyMethod_ClearFreeList(space):
  1264. """Clear the free list. Return the total number of freed items.
  1265. """
  1266. raise NotImplementedError
  1267. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  1268. def PyModule_CheckExact(space, p):
  1269. """Return true if p is a module object, but not a subtype of
  1270. PyModule_Type.
  1271. """
  1272. raise NotImplementedError
  1273. @cpython_api([rffi.CCHARP], PyObject)
  1274. def PyModule_New(space, name):
  1275. """Return a new module object with the __name__ attribute set to name. Only
  1276. the module's __doc__ and __name__ attributes are filled in; the caller is
  1277. responsible for providing a __file__ attribute."""
  1278. raise NotImplementedError
  1279. @cpython_api([PyObject], rffi.CCHARP)
  1280. def PyModule_GetFilename(space, module):
  1281. """Return the name of the file from which module was loaded using module's
  1282. __file__ attribute. If this is not defined, or if it is not a string, raise
  1283. SystemError and return NULL."""
  1284. raise NotImplementedError
  1285. @cpython_api([PyObject, rffi.INT], rffi.INT_real, error=-1)
  1286. def PyModule_AddIntMacro(space, module, macro):
  1287. """Add an int constant to module. The name and the value are taken from
  1288. macro. For example PyModule_AddConstant(module, AF_INET) adds the int
  1289. constant AF_INET with the value of AF_INET to module.
  1290. Return -1 on error, 0 on success.
  1291. """
  1292. raise NotImplementedError
  1293. @cpython_api([PyObject, rffi.CCHARP], rffi.INT_real, error=-1)
  1294. def PyModule_AddStringMacro(space, module, macro):
  1295. """Add a string constant to module.
  1296. """
  1297. raise NotImplementedError
  1298. @cpython_api([PyObjectP, PyObjectP], rffi.INT_real, error=-1)
  1299. def PyNumber_Coerce(space, p1, p2):
  1300. """This function takes the addresses of two variables of type PyObject*. If
  1301. the objects pointed to by *p1 and *p2 have the same type, increment their
  1302. reference count and return 0 (success). If the objects can be converted to a
  1303. common numeric type, replace *p1 and *p2 by their converted value (with
  1304. 'new' reference counts), and return 0. If no conversion is possible, or if
  1305. some other error occurs, return -1 (failure) and don't increment the
  1306. reference counts. The call PyNumber_Coerce(&o1, &o2) is equivalent to the
  1307. Python statement o1, o2 = coerce(o1, o2)."""
  1308. raise NotImplementedError
  1309. @cpython_api([PyObjectP, PyObjectP], rffi.INT_real, error=-1)
  1310. def PyNumber_CoerceEx(space, p1, p2):
  1311. """This function is similar to PyNumber_Coerce(), except that it returns
  1312. 1 when the conversion is not possible and when no error is raised.
  1313. Reference counts are still not increased in this case."""
  1314. raise NotImplementedError
  1315. @cpython_api([PyObject, rffi.INT_real], PyObject)
  1316. def PyNumber_ToBase(space, n, base):
  1317. """Returns the integer n converted to base as a string with a base
  1318. marker of '0b', '0o', or '0x' if applicable. When
  1319. base is not 2, 8, 10, or 16, the format is 'x#num' where x is the
  1320. base. If n is not an int object, it is converted with
  1321. PyNumber_Index() first.
  1322. """
  1323. raise NotImplementedError
  1324. @cpython_api([PyObject], PyObject)
  1325. def PyObject_Bytes(space, o):
  1326. """Compute a bytes representation of object o. In 2.x, this is just a alias
  1327. for PyObject_Str()."""
  1328. raise NotImplementedError
  1329. @cpython_api([PyObject], lltype.Signed, error=-1)
  1330. def PyObject_HashNotImplemented(space, o):
  1331. """Set a TypeError indicating that type(o) is not hashable and return -1.
  1332. This function receives special treatment when stored in a tp_hash slot,
  1333. allowing a type to explicitly indicate to the interpreter that it is not
  1334. hashable.
  1335. """
  1336. raise NotImplementedError
  1337. @cpython_api([], PyFrameObject)
  1338. def PyEval_GetFrame(space):
  1339. """Return the current thread state's frame, which is NULL if no frame is
  1340. currently executing."""
  1341. borrow_from()
  1342. raise NotImplementedError
  1343. @cpython_api([PyFrameObject], rffi.INT_real, error=CANNOT_FAIL)
  1344. def PyFrame_GetLineNumber(space, frame):
  1345. """Return the line number that frame is currently executing."""
  1346. raise NotImplementedError
  1347. @cpython_api([], rffi.INT_real, error=CANNOT_FAIL)
  1348. def PyEval_GetRestricted(space):
  1349. """If there is a current frame and it is executing in restricted mode, return true,
  1350. otherwise false."""
  1351. raise NotImplementedError
  1352. @cpython_api([PyObject], rffi.CCHARP)
  1353. def PyEval_GetFuncName(space, func):
  1354. """Return the name of func if it is a function, class or instance object, else the
  1355. name of funcs type."""
  1356. raise NotImplementedError
  1357. @cpython_api([PyObject], rffi.CCHARP)
  1358. def PyEval_GetFuncDesc(space, func):
  1359. """Return a description string, depending on the type of func.
  1360. Return values include "()" for functions and methods, " constructor",
  1361. " instance", and " object". Concatenated with the result of
  1362. PyEval_GetFuncName(), the result will be a description of
  1363. func."""
  1364. raise NotImplementedError
  1365. @cpython_api([PyObject, PyObject], PyObject)
  1366. def PySequence_InPlaceConcat(space, o1, o2):
  1367. """Return the concatenation of o1 and o2 on success, and NULL on failure.
  1368. The operation is done in-place when o1 supports it. This is the equivalent
  1369. of the Python expression o1 += o2."""
  1370. raise NotImplementedError
  1371. @cpython_api([PyObject, Py_ssize_t], PyObject)
  1372. def PySequence_InPlaceRepeat(space, o, count):
  1373. """Return the result of repeating sequence object o count times, or NULL on
  1374. failure. The operation is done in-place when o supports it. This is the
  1375. equivalent of the Python expression o *= count.
  1376. This function used an int type for count. This might require
  1377. changes in your code for properly supporting 64-bit systems."""
  1378. raise NotImplementedError
  1379. @cpython_api([PyObject, PyObject], Py_ssize_t, error=-1)
  1380. def PySequence_Count(space, o, value):
  1381. """Return the number of occurrences of value in o, that is, return the number
  1382. of keys for which o[key] == value. On failure, return -1. This is
  1383. equivalent to the Python expression o.count(value).
  1384. This function returned an int type. This might require changes
  1385. in your code for properly supporting 64-bit systems."""
  1386. raise NotImplementedError
  1387. @cpython_api([PyObject], PyObjectP)
  1388. def PySequence_Fast_ITEMS(space, o):
  1389. """Return the underlying array of PyObject pointers. Assumes that o was returned
  1390. by PySequence_Fast() and o is not NULL.
  1391. Note, if a list gets resized, the reallocation may relocate the items array.
  1392. So, only use the underlying array pointer in contexts where the sequence
  1393. cannot change.
  1394. """
  1395. raise NotImplementedError
  1396. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  1397. def PyFrozenSet_Check(space, p):
  1398. """Return true if p is a frozenset object or an instance of a
  1399. subtype.
  1400. """
  1401. raise NotImplementedError
  1402. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  1403. def PyAnySet_Check(space, p):
  1404. """Return true if p is a set object, a frozenset object, or an
  1405. instance of a subtype."""
  1406. raise NotImplementedError
  1407. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  1408. def PyAnySet_CheckExact(space, p):
  1409. """Return true if p is a set object or a frozenset object but
  1410. not an instance of a subtype."""
  1411. raise NotImplementedError
  1412. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  1413. def PyFrozenSet_CheckExact(space, p):
  1414. """Return true if p is a frozenset object but not an instance of a
  1415. subtype."""
  1416. raise NotImplementedError
  1417. @cpython_api([PyObject], PyObject)
  1418. def PyFrozenSet_New(space, iterable):
  1419. """Return a new frozenset containing objects returned by the iterable.
  1420. The iterable may be NULL to create a new empty frozenset. Return the new
  1421. set on success or NULL on failure. Raise TypeError if iterable is
  1422. not actually iterable.
  1423. Now guaranteed to return a brand-new frozenset. Formerly,
  1424. frozensets of zero-length were a singleton. This got in the way of
  1425. building-up new frozensets with PySet_Add()."""
  1426. raise NotImplementedError
  1427. @cpython_api([rffi.CCHARP, Py_ssize_t, rffi.CCHARP, rffi.CCHARP], PyObject)
  1428. def PyString_Decode(space, s, size, encoding, errors):
  1429. """Create an object by decoding size bytes of the encoded buffer s using the
  1430. codec registered for encoding. encoding and errors have the same meaning
  1431. as the parameters of the same name in the unicode() built-in function.
  1432. The codec to be used is looked up using the Python codec registry. Return
  1433. NULL if an exception was raised by the codec.
  1434. This function is not available in 3.x and does not have a PyBytes alias.
  1435. This function used an int type for size. This might require
  1436. changes in your code for properly supporting 64-bit systems."""
  1437. raise NotImplementedError
  1438. @cpython_api([PyObject, rffi.CCHARP, rffi.CCHARP], PyObject)
  1439. def PyString_AsDecodedObject(space, str, encoding, errors):
  1440. """Decode a string object by passing it to the codec registered for encoding and
  1441. return the result as Python object. encoding and errors have the same
  1442. meaning as the parameters of the same name in the string encode() method.
  1443. The codec to be used is looked up using the Python codec registry. Return NULL
  1444. if an exception was raised by the codec.
  1445. This function is not available in 3.x and does not have a PyBytes alias."""
  1446. raise NotImplementedError
  1447. @cpython_api([rffi.CCHARP, Py_ssize_t, rffi.CCHARP, rffi.CCHARP], PyObject)
  1448. def PyString_Encode(space, s, size, encoding, errors):
  1449. """Encode the char buffer of the given size by passing it to the codec
  1450. registered for encoding and return a Python object. encoding and errors
  1451. have the same meaning as the parameters of the same name in the string
  1452. encode() method. The codec to be used is looked up using the Python codec
  1453. registry. Return NULL if an exception was raised by the codec.
  1454. This function is not available in 3.x and does not have a PyBytes alias.
  1455. This function used an int type for size. This might require
  1456. changes in your code for properly supporting 64-bit systems."""
  1457. raise NotImplementedError
  1458. @cpython_api([FILE, rffi.CCHARP], rffi.INT_real, error=CANNOT_FAIL)
  1459. def Py_FdIsInteractive(space, fp, filename):
  1460. """Return true (nonzero) if the standard I/O file fp with name filename is
  1461. deemed interactive. This is the case for files for which isatty(fileno(fp))
  1462. is true. If the global flag Py_InteractiveFlag is true, this function
  1463. also returns true if the filename pointer is NULL or if the name is equal to
  1464. one of the strings '<stdin>' or '???'."""
  1465. raise NotImplementedError
  1466. @cpython_api([], lltype.Void)
  1467. def PyOS_AfterFork(space):
  1468. """Function to update some internal state after a process fork; this should be
  1469. called in the new process if the Python interpreter will continue to be used.
  1470. If a new executable is loaded into the new process, this function does not need
  1471. to be called."""
  1472. raise NotImplementedError
  1473. @cpython_api([], rffi.INT_real, error=CANNOT_FAIL)
  1474. def PyOS_CheckStack(space):
  1475. """Return true when the interpreter runs out of stack space. This is a reliable
  1476. check, but is only available when USE_STACKCHECK is defined (currently
  1477. on Windows using the Microsoft Visual C++ compiler). USE_STACKCHECK
  1478. will be defined automatically; you should never change the definition in your
  1479. own code."""
  1480. raise NotImplementedError
  1481. @cpython_api([rffi.CCHARP, FILE], FILE)
  1482. def PySys_GetFile(space, name, default):
  1483. """Return the FILE* associated with the object name in the
  1484. sys module, or def if name is not in the module or is not associated
  1485. with a FILE*."""
  1486. raise NotImplementedError
  1487. @cpython_api([], lltype.Void)
  1488. def PySys_ResetWarnOptions(space):
  1489. """Reset sys.warnoptions to an empty list."""
  1490. raise NotImplementedError
  1491. @cpython_api([rffi.CCHARP], lltype.Void)
  1492. def PySys_AddWarnOption(space, s):
  1493. """Append s to sys.warnoptions."""
  1494. raise NotImplementedError
  1495. @cpython_api([rffi.CCHARP], lltype.Void)
  1496. def PySys_SetPath(space, path):
  1497. """Set sys.path to a list object of paths found in path which should
  1498. be a list of paths separated with the platform's search path delimiter
  1499. (: on Unix, ; on Windows)."""
  1500. raise NotImplementedError
  1501. @cpython_api([rffi.INT_real], lltype.Void)
  1502. def Py_Exit(space, status):
  1503. """Exit the current process. This calls Py_Finalize() and then calls the
  1504. standard C library function exit(status)."""
  1505. raise NotImplementedError
  1506. @cpython_api([], rffi.INT_real, error=CANNOT_FAIL)
  1507. def PyTuple_ClearFreeList(space):
  1508. """Clear the free list. Return the total number of freed items.
  1509. """
  1510. raise NotImplementedError
  1511. @cpython_api([], rffi.UINT, error=CANNOT_FAIL)
  1512. def PyType_ClearCache(space):
  1513. """Clear the internal lookup cache. Return the current version tag.
  1514. """
  1515. raise NotImplementedError
  1516. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  1517. def PyType_IS_GC(space, o):
  1518. """Return true if the type object includes support for the cycle detector; this
  1519. tests the type flag Py_TPFLAGS_HAVE_GC.
  1520. """
  1521. raise NotImplementedError
  1522. @cpython_api([], rffi.INT_real, error=CANNOT_FAIL)
  1523. def PyUnicode_ClearFreeList(space):
  1524. """Clear the free list. Return the total number of freed items.
  1525. """
  1526. raise NotImplementedError
  1527. @cpython_api([rffi.CCHARP], PyObject)
  1528. def PyUnicode_FromFormat(space, format):
  1529. """Take a C printf()-style format string and a variable number of
  1530. arguments, calculate the size of the resulting Python unicode string and return
  1531. a string with the values formatted into it. The variable arguments must be C
  1532. types and must correspond exactly to the format characters in the format
  1533. string. The following format characters are allowed:
  1534. Format Characters
  1535. Type
  1536. Comment
  1537. %%
  1538. n/a
  1539. The literal % character.
  1540. %c
  1541. int
  1542. A single character,
  1543. represented as an C int.
  1544. %d
  1545. int
  1546. Exactly equivalent to
  1547. printf("%d").
  1548. %u
  1549. unsigned int
  1550. Exactly equivalent to
  1551. printf("%u").
  1552. %ld
  1553. long
  1554. Exactly equivalent to
  1555. printf("%ld").
  1556. %lu
  1557. unsigned long
  1558. Exactly equivalent to
  1559. printf("%lu").
  1560. %zd
  1561. Py_ssize_t
  1562. Exactly equivalent to
  1563. printf("%zd").
  1564. %zu
  1565. size_t
  1566. Exactly equivalent to
  1567. printf("%zu").
  1568. %i
  1569. int
  1570. Exactly equivalent to
  1571. printf("%i").
  1572. %x
  1573. int
  1574. Exactly equivalent to
  1575. printf("%x").
  1576. %s
  1577. char*
  1578. A null-terminated C character
  1579. array.
  1580. %p
  1581. void*
  1582. The hex representation of a C
  1583. pointer. Mostly equivalent to
  1584. printf("%p") except that
  1585. it is guaranteed to start with
  1586. the literal 0x regardless
  1587. of what the platform's
  1588. printf yields.
  1589. %U
  1590. PyObject*
  1591. A unicode object.
  1592. %V
  1593. PyObject*, char *
  1594. A unicode object (which may be
  1595. NULL) and a null-terminated
  1596. C character array as a second
  1597. parameter (which will be used,
  1598. if the first parameter is
  1599. NULL).
  1600. %S
  1601. PyObject*
  1602. The result of calling
  1603. PyObject_Unicode().
  1604. %R
  1605. PyObject*
  1606. The result of calling
  1607. PyObject_Repr().
  1608. An unrecognized format character causes all the rest of the format string to be
  1609. copied as-is to the result string, and any extra arguments discarded.
  1610. """
  1611. raise NotImplementedError
  1612. @cpython_api([rffi.CCHARP, va_list], PyObject)
  1613. def PyUnicode_FromFormatV(space, format, vargs):
  1614. """Identical to PyUnicode_FromFormat() except that it takes exactly two
  1615. arguments.
  1616. """
  1617. raise NotImplementedError
  1618. @cpython_api([rffi.CWCHARP, Py_ssize_t, rffi.CCHARP, rffi.CCHARP], PyObject)
  1619. def PyUnicode_Encode(space, s, size, encoding, errors):
  1620. """Encode the Py_UNICODE buffer of the given size and return a Python
  1621. string object. encoding and errors have the same meaning as the parameters
  1622. of the same name in the Unicode encode() method. The codec to be used is
  1623. looked up using the Python codec registry. Return NULL if an exception was
  1624. raised by the codec.
  1625. This function used an int type for size. This might require
  1626. changes in your code for properly supporting 64-bit systems."""
  1627. raise NotImplementedError
  1628. @cpython_api([rffi.CCHARP, Py_ssize_t, rffi.CCHARP, Py_ssize_t], PyObject)
  1629. def PyUnicode_DecodeUTF8Stateful(space, s, size, errors, consumed):
  1630. """If consumed is NULL, behave like PyUnicode_DecodeUTF8(). If
  1631. consumed is not NULL, trailing incomplete UTF-8 byte sequences will not be
  1632. treated as an error. Those bytes will not be decoded and the number of bytes
  1633. that have been decoded will be stored in consumed.
  1634. This function used an int type for size. This might require
  1635. changes in your code for properly supporting 64-bit systems."""
  1636. raise NotImplementedError
  1637. @cpython_api([rffi.CCHARP, Py_ssize_t, rffi.CCHARP, rffi.INTP], PyObject)
  1638. def PyUnicode_DecodeUTF32(space, s, size, errors, byteorder):
  1639. """Decode length bytes from a UTF-32 encoded buffer string and return the
  1640. corresponding Unicode object. errors (if non-NULL) defines the error
  1641. handling. It defaults to "strict".
  1642. If byteorder is non-NULL, the decoder starts decoding using the given byte
  1643. order:
  1644. *byteorder == -1: little endian
  1645. *byteorder == 0: native order
  1646. *byteorder == 1: big endian
  1647. If *byteorder is zero, and the first four bytes of the input data are a
  1648. byte order mark (BOM), the decoder switches to this byte order and the BOM is
  1649. not copied into the resulting Unicode string. If *byteorder is -1 or
  1650. 1, any byte order mark is copied to the output.
  1651. After completion, *byteorder is set to the current byte order at the end
  1652. of input data.
  1653. In a narrow build codepoints outside the BMP will be decoded as surrogate pairs.
  1654. If byteorder is NULL, the codec starts in native order mode.
  1655. Return NULL if an exception was raised by the codec.
  1656. """
  1657. raise NotImplementedError
  1658. @cpython_api([rffi.CCHARP, Py_ssize_t, rffi.CCHARP, rffi.INTP, Py_ssize_t], PyObject)
  1659. def PyUnicode_DecodeUTF32Stateful(space, s, size, errors, byteorder, consumed):
  1660. """If consumed is NULL, behave like PyUnicode_DecodeUTF32(). If
  1661. consumed is not NULL, PyUnicode_DecodeUTF32Stateful() will not treat
  1662. trailing incomplete UTF-32 byte sequences (such as a number of bytes not divisible
  1663. by four) as an error. Those bytes will not be decoded and the number of bytes
  1664. that have been decoded will be stored in consumed.
  1665. """
  1666. raise NotImplementedError
  1667. @cpython_api([rffi.CWCHARP, Py_ssize_t, rffi.CCHARP, rffi.INT_real], PyObject)
  1668. def PyUnicode_EncodeUTF32(space, s, size, errors, byteorder):
  1669. """Return a Python bytes object holding the UTF-32 encoded value of the Unicode
  1670. data in s. Output is written according to the following byte order:
  1671. byteorder == -1: little endian
  1672. byteorder == 0: native byte order (writes a BOM mark)
  1673. byteorder == 1: big endian
  1674. If byteorder is 0, the output string will always start with the Unicode BOM
  1675. mark (U+FEFF). In the other two modes, no BOM mark is prepended.
  1676. If Py_UNICODE_WIDE is not defined, surrogate pairs will be output
  1677. as a single codepoint.
  1678. Return NULL if an exception was raised by the codec.
  1679. """
  1680. raise NotImplementedError
  1681. @cpython_api([PyObject], PyObject)
  1682. def PyUnicode_AsUTF32String(space, unicode):
  1683. """Return a Python string using the UTF-32 encoding in native byte order. The
  1684. string always starts with a BOM mark. Error handling is "strict". Return
  1685. NULL if an exception was raised by the codec.
  1686. """
  1687. raise NotImplementedError
  1688. @cpython_api([rffi.CCHARP, Py_ssize_t, rffi.CCHARP, rffi.INTP, Py_ssize_t], PyObject)
  1689. def PyUnicode_DecodeUTF16Stateful(space, s, size, errors, byteorder, consumed):
  1690. """If consumed is NULL, behave like PyUnicode_DecodeUTF16(). If
  1691. consumed is not NULL, PyUnicode_DecodeUTF16Stateful() will not treat
  1692. trailing incomplete UTF-16 byte sequences (such as an odd number of bytes or a
  1693. split surrogate pair) as an error. Those bytes will not be decoded and the
  1694. number of bytes that have been decoded will be stored in consumed.
  1695. This function used an int type for size and an int *
  1696. type for consumed. This might require changes in your code for
  1697. properly supporting 64-bit systems."""
  1698. raise NotImplementedError
  1699. @cpython_api([rffi.CWCHARP, Py_ssize_t, rffi.CCHARP, rffi.INT_real], PyObject)
  1700. def PyUnicode_EncodeUTF16(space, s, size, errors, byteorder):
  1701. """Return a Python string object holding the UTF-16 encoded value of the Unicode
  1702. data in s. Output is written according to the following byte order:
  1703. byteorder == -1: little endian
  1704. byteorder == 0: native byte order (writes a BOM mark)
  1705. byteorder == 1: big endian
  1706. If byteorder is 0, the output string will always start with the Unicode BOM
  1707. mark (U+FEFF). In the other two modes, no BOM mark is prepended.
  1708. If Py_UNICODE_WIDE is defined, a single Py_UNICODE value may get
  1709. represented as a surrogate pair. If it is not defined, each Py_UNICODE
  1710. values is interpreted as an UCS-2 character.
  1711. Return NULL if an exception was raised by the codec.
  1712. This function used an int type for size. This might require
  1713. changes in your code for properly supporting 64-bit systems."""
  1714. raise NotImplementedError
  1715. @cpython_api([PyObject], PyObject)
  1716. def PyUnicode_AsUTF16String(space, unicode):
  1717. """Return a Python string using the UTF-16 encoding in native byte order. The
  1718. string always starts with a BOM mark. Error handling is "strict". Return
  1719. NULL if an exception was raised by the codec."""
  1720. raise NotImplementedError
  1721. @cpython_api([rffi.CCHARP, Py_ssize_t, rffi.CCHARP], PyObject)
  1722. def PyUnicode_DecodeUTF7(space, s, size, errors):
  1723. """Create a Unicode object by decoding size bytes of the UTF-7 encoded string
  1724. s. Return NULL if an exception was raised by the codec."""
  1725. raise NotImplementedError
  1726. @cpython_api([rffi.CCHARP, Py_ssize_t, rffi.CCHARP, Py_ssize_t], PyObject)
  1727. def PyUnicode_DecodeUTF7Stateful(space, s, size, errors, consumed):
  1728. """If consumed is NULL, behave like PyUnicode_DecodeUTF7(). If
  1729. consumed is not NULL, trailing incomplete UTF-7 base-64 sections will not
  1730. be treated as an error. Those bytes will not be decoded and the number of
  1731. bytes that have been decoded will be stored in consumed."""
  1732. raise NotImplementedError
  1733. @cpython_api([rffi.CWCHARP, Py_ssize_t, rffi.INT_real, rffi.INT_real, rffi.CCHARP], PyObject)
  1734. def PyUnicode_EncodeUTF7(space, s, size, base64SetO, base64WhiteSpace, errors):
  1735. """Encode the Py_UNICODE buffer of the given size using UTF-7 and
  1736. return a Python bytes object. Return NULL if an exception was raised by
  1737. the codec.
  1738. If base64SetO is nonzero, "Set O" (punctuation that has no otherwise
  1739. special meaning) will be encoded in base-64. If base64WhiteSpace is
  1740. nonzero, whitespace will be encoded in base-64. Both are set to zero for the
  1741. Python "utf-7" codec."""
  1742. raise NotImplementedError
  1743. @cpython_api([rffi.CCHARP, Py_ssize_t, rffi.CCHARP], PyObject)
  1744. def PyUnicode_DecodeUnicodeEscape(space, s, size, errors):
  1745. """Create a Unicode object by decoding size bytes of the Unicode-Escape encoded
  1746. string s. Return NULL if an exception was raised by the codec.
  1747. This function used an int type for size. This might require
  1748. changes in your code for properly supporting 64-bit systems."""
  1749. raise NotImplementedError
  1750. @cpython_api([rffi.CWCHARP, Py_ssize_t], PyObject)
  1751. def PyUnicode_EncodeUnicodeEscape(space, s, size):
  1752. """Encode the Py_UNICODE buffer of the given size using Unicode-Escape and
  1753. return a Python string object. Return NULL if an exception was raised by the
  1754. codec.
  1755. This function used an int type for size. This might require
  1756. changes in your code for properly supporting 64-bit systems."""
  1757. raise NotImplementedError
  1758. @cpython_api([rffi.CCHARP, Py_ssize_t, rffi.CCHARP], PyObject)
  1759. def PyUnicode_DecodeRawUnicodeEscape(space, s, size, errors):
  1760. """Create a Unicode object by decoding size bytes of the Raw-Unicode-Escape
  1761. encoded string s. Return NULL if an exception was raised by the codec.
  1762. This function used an int type for size. This might require
  1763. changes in your code for properly supporting 64-bit systems."""
  1764. raise NotImplementedError
  1765. @cpython_api([rffi.CWCHARP, Py_ssize_t, rffi.CCHARP], PyObject)
  1766. def PyUnicode_EncodeRawUnicodeEscape(space, s, size, errors):
  1767. """Encode the Py_UNICODE buffer of the given size using Raw-Unicode-Escape
  1768. and return a Python string object. Return NULL if an exception was raised by
  1769. the codec.
  1770. This function used an int type for size. This might require
  1771. changes in your code for properly supporting 64-bit systems."""
  1772. raise NotImplementedError
  1773. @cpython_api([PyObject], PyObject)
  1774. def PyUnicode_AsRawUnicodeEscapeString(space, unicode):
  1775. """Encode a Unicode object using Raw-Unicode-Escape and return the result as
  1776. Python string object. Error handling is "strict". Return NULL if an exception
  1777. was raised by the codec."""
  1778. raise NotImplementedError
  1779. @cpython_api([rffi.CCHARP, Py_ssize_t, PyObject, rffi.CCHARP], PyObject)
  1780. def PyUnicode_DecodeCharmap(space, s, size, mapping, errors):
  1781. """Create a Unicode object by decoding size bytes of the encoded string s using
  1782. the given mapping object. Return NULL if an exception was raised by the
  1783. codec. If mapping is NULL latin-1 decoding will be done. Else it can be a
  1784. dictionary mapping byte or a unicode string, which is treated as a lookup table.
  1785. Byte values greater that the length of the string and U+FFFE "characters" are
  1786. treated as "undefined mapping".
  1787. Allowed unicode string as mapping argument.
  1788. This function used an int type for size. This might require
  1789. changes in your code for properly supporting 64-bit systems."""
  1790. raise NotImplementedError
  1791. @cpython_api([rffi.CWCHARP, Py_ssize_t, PyObject, rffi.CCHARP], PyObject)
  1792. def PyUnicode_EncodeCharmap(space, s, size, mapping, errors):
  1793. """Encode the Py_UNICODE buffer of the given size using the given
  1794. mapping object and return a Python string object. Return NULL if an
  1795. exception was raised by the codec.
  1796. This function used an int type for size. This might require
  1797. changes in your code for properly supporting 64-bit systems."""
  1798. raise NotImplementedError
  1799. @cpython_api([PyObject, PyObject], PyObject)
  1800. def PyUnicode_AsCharmapString(space, unicode, mapping):
  1801. """Encode a Unicode object using the given mapping object and return the result
  1802. as Python string object. Error handling is "strict". Return NULL if an
  1803. exception was raised by the codec."""
  1804. raise NotImplementedError
  1805. @cpython_api([rffi.CWCHARP, Py_ssize_t, PyObject, rffi.CCHARP], PyObject)
  1806. def PyUnicode_TranslateCharmap(space, s, size, table, errors):
  1807. """Translate a Py_UNICODE buffer of the given length by applying a
  1808. character mapping table to it and return the resulting Unicode object. Return
  1809. NULL when an exception was raised by the codec.
  1810. The mapping table must map Unicode ordinal integers to Unicode ordinal
  1811. integers or None (causing deletion of the character).
  1812. Mapping tables need only provide the __getitem__() interface; dictionaries
  1813. and sequences work well. Unmapped character ordinals (ones which cause a
  1814. LookupError) are left untouched and are copied as-is.
  1815. This function used an int type for size. This might require
  1816. changes in your code for properly supporting 64-bit systems."""
  1817. raise NotImplementedError
  1818. @cpython_api([rffi.CCHARP, rffi.INT_real, rffi.CCHARP, rffi.INTP], PyObject)
  1819. def PyUnicode_DecodeMBCSStateful(space, s, size, errors, consumed):
  1820. """If consumed is NULL, behave like PyUnicode_DecodeMBCS(). If
  1821. consumed is not NULL, PyUnicode_DecodeMBCSStateful() will not decode
  1822. trailing lead byte and the number of bytes that have been decoded will be stored
  1823. in consumed.
  1824. """
  1825. raise NotImplementedError
  1826. @cpython_api([PyObject, PyObject], PyObject)
  1827. def PyUnicode_Concat(space, left, right):
  1828. """Concat two strings giving a new Unicode string."""
  1829. raise NotImplementedError
  1830. @cpython_api([PyObject, PyObject, rffi.CCHARP], PyObject)
  1831. def PyUnicode_Translate(space, str, table, errors):
  1832. """Translate a string by applying a character mapping table to it and return the
  1833. resulting Unicode object.
  1834. The mapping table must map Unicode ordinal integers to Unicode ordinal integers
  1835. or None (causing deletion of the character).
  1836. Mapping tables need only provide the __getitem__() interface; dictionaries
  1837. and sequences work well. Unmapped character ordinals (ones which cause a
  1838. LookupError) are left untouched and are copied as-is.
  1839. errors has the usual meaning for codecs. It may be NULL which indicates to
  1840. use the default error handling."""
  1841. raise NotImplementedError
  1842. @cpython_api([PyObject, PyObject, rffi.INT_real], PyObject)
  1843. def PyUnicode_RichCompare(space, left, right, op):
  1844. """Rich compare two unicode strings and return one of the following:
  1845. NULL in case an exception was raised
  1846. Py_True or Py_False for successful comparisons
  1847. Py_NotImplemented in case the type combination is unknown
  1848. Note that Py_EQ and Py_NE comparisons can cause a
  1849. UnicodeWarning in case the conversion of the arguments to Unicode fails
  1850. with a UnicodeDecodeError.
  1851. Possible values for op are Py_GT, Py_GE, Py_EQ,
  1852. Py_NE, Py_LT, and Py_LE."""
  1853. raise NotImplementedError
  1854. @cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
  1855. def PyUnicode_Contains(space, container, element):
  1856. """Check whether element is contained in container and return true or false
  1857. accordingly.
  1858. element has to coerce to a one element Unicode string. -1 is returned if
  1859. there was an error."""
  1860. raise NotImplementedError
  1861. @cpython_api([rffi.INT_real, rffi.CCHARPP], rffi.INT_real, error=2)
  1862. def Py_Main(space, argc, argv):
  1863. """The main program for the standard interpreter. This is made available for
  1864. programs which embed Python. The argc and argv parameters should be
  1865. prepared exactly as those which are passed to a C program's main()
  1866. function. It is important to note that the argument list may be modified (but
  1867. the contents of the strings pointed to by the argument list are not). The return
  1868. value will be the integer passed to the sys.exit() function, 1 if the
  1869. interpreter exits due to an exception, or 2 if the parameter list does not
  1870. represent a valid Python command line.
  1871. Note that if an otherwise unhandled SystemError is raised, this
  1872. function will not return 1, but exit the process, as long as
  1873. Py_InspectFlag is not set."""
  1874. raise NotImplementedError
  1875. @cpython_api([FILE, rffi.CCHARP], rffi.INT_real, error=-1)
  1876. def PyRun_AnyFile(space, fp, filename):
  1877. """This is a simplified interface to PyRun_AnyFileExFlags() below, leaving
  1878. closeit set to 0 and flags set to NULL."""
  1879. raise NotImplementedError
  1880. @cpython_api([FILE, rffi.CCHARP, PyCompilerFlags], rffi.INT_real, error=-1)
  1881. def PyRun_AnyFileFlags(space, fp, filename, flags):
  1882. """This is a simplified interface to PyRun_AnyFileExFlags() below, leaving
  1883. the closeit argument set to 0."""
  1884. raise NotImplementedError
  1885. @cpython_api([FILE, rffi.CCHARP, rffi.INT_real], rffi.INT_real, error=-1)
  1886. def PyRun_AnyFileEx(space, fp, filename, closeit):
  1887. """This is a simplified interface to PyRun_AnyFileExFlags() below, leaving
  1888. the flags argument set to NULL."""
  1889. raise NotImplementedError
  1890. @cpython_api([FILE, rffi.CCHARP, rffi.INT_real, PyCompilerFlags], rffi.INT_real, error=-1)
  1891. def PyRun_AnyFileExFlags(space, fp, filename, closeit, flags):
  1892. """If fp refers to a file associated with an interactive device (console or
  1893. terminal input or Unix pseudo-terminal), return the value of
  1894. PyRun_InteractiveLoop(), otherwise return the result of
  1895. PyRun_SimpleFile(). If filename is NULL, this function uses
  1896. "???" as the filename."""
  1897. raise NotImplementedError
  1898. @cpython_api([rffi.CCHARP, PyCompilerFlags], rffi.INT_real, error=-1)
  1899. def PyRun_SimpleStringFlags(space, command, flags):
  1900. """Executes the Python source code from command in the __main__ module
  1901. according to the flags argument. If __main__ does not already exist, it
  1902. is created. Returns 0 on success or -1 if an exception was raised. If
  1903. there was an error, there is no way to get the exception information. For the
  1904. meaning of flags, see below.
  1905. Note that if an otherwise unhandled SystemError is raised, this
  1906. function will not return -1, but exit the process, as long as
  1907. Py_InspectFlag is not set."""
  1908. raise NotImplementedError
  1909. @cpython_api([FILE, rffi.CCHARP], rffi.INT_real, error=-1)
  1910. def PyRun_SimpleFile(space, fp, filename):
  1911. """This is a simplified interface to PyRun_SimpleFileExFlags() below,
  1912. leaving closeit set to 0 and flags set to NULL."""
  1913. raise NotImplementedError
  1914. @cpython_api([FILE, rffi.CCHARP, PyCompilerFlags], rffi.INT_real, error=-1)
  1915. def PyRun_SimpleFileFlags(space, fp, filename, flags):
  1916. """This is a simplified interface to PyRun_SimpleFileExFlags() below,
  1917. leaving closeit set to 0."""
  1918. raise NotImplementedError
  1919. @cpython_api([FILE, rffi.CCHARP, rffi.INT_real], rffi.INT_real, error=-1)
  1920. def PyRun_SimpleFileEx(space, fp, filename, closeit):
  1921. """This is a simplified interface to PyRun_SimpleFileExFlags() below,
  1922. leaving flags set to NULL."""
  1923. raise NotImplementedError
  1924. @cpython_api([FILE, rffi.CCHARP, rffi.INT_real, PyCompilerFlags], rffi.INT_real, error=-1)
  1925. def PyRun_SimpleFileExFlags(space, fp, filename, closeit, flags):
  1926. """Similar to PyRun_SimpleStringFlags(), but the Python source code is read
  1927. from fp instead of an in-memory string. filename should be the name of the
  1928. file. If closeit is true, the file is closed before PyRun_SimpleFileExFlags
  1929. returns."""
  1930. raise NotImplementedError
  1931. @cpython_api([FILE, rffi.CCHARP], rffi.INT_real, error=-1)
  1932. def PyRun_InteractiveOne(space, fp, filename):
  1933. """This is a simplified interface to PyRun_InteractiveOneFlags() below,
  1934. leaving flags set to NULL."""
  1935. raise NotImplementedError
  1936. @cpython_api([FILE, rffi.CCHARP, PyCompilerFlags], rffi.INT_real, error=-1)
  1937. def PyRun_InteractiveOneFlags(space, fp, filename, flags):
  1938. """Read and execute a single statement from a file associated with an
  1939. interactive device according to the flags argument. The user will be
  1940. prompted using sys.ps1 and sys.ps2. Returns 0 when the input was
  1941. executed successfully, -1 if there was an exception, or an error code
  1942. from the errcode.h include file distributed as part of Python if
  1943. there was a parse error. (Note that errcode.h is not included by
  1944. Python.h, so must be included specifically if needed.)"""
  1945. raise NotImplementedError
  1946. @cpython_api([FILE, rffi.CCHARP], rffi.INT_real, error=-1)
  1947. def PyRun_InteractiveLoop(space, fp, filename):
  1948. """This is a simplified interface to PyRun_InteractiveLoopFlags() below,
  1949. leaving flags set to NULL."""
  1950. raise NotImplementedError
  1951. @cpython_api([FILE, rffi.CCHARP, PyCompilerFlags], rffi.INT_real, error=-1)
  1952. def PyRun_InteractiveLoopFlags(space, fp, filename, flags):
  1953. """Read and execute statements from a file associated with an interactive device
  1954. until EOF is reached. The user will be prompted using sys.ps1 and
  1955. sys.ps2. Returns 0 at EOF."""
  1956. raise NotImplementedError
  1957. @cpython_api([rffi.CCHARP, rffi.INT_real], _node)
  1958. def PyParser_SimpleParseString(space, str, start):
  1959. """This is a simplified interface to
  1960. PyParser_SimpleParseStringFlagsFilename() below, leaving filename set
  1961. to NULL and flags set to 0."""
  1962. raise NotImplementedError
  1963. @cpython_api([rffi.CCHARP, rffi.INT_real, rffi.INT_real], _node)
  1964. def PyParser_SimpleParseStringFlags(space, str, start, flags):
  1965. """This is a simplified interface to
  1966. PyParser_SimpleParseStringFlagsFilename() below, leaving filename set
  1967. to NULL."""
  1968. raise NotImplementedError
  1969. @cpython_api([rffi.CCHARP, rffi.CCHARP, rffi.INT_real, rffi.INT_real], _node)
  1970. def PyParser_SimpleParseStringFlagsFilename(space, str, filename, start, flags):
  1971. """Parse Python source code from str using the start token start according to
  1972. the flags argument. The result can be used to create a code object which can
  1973. be evaluated efficiently. This is useful if a code fragment must be evaluated
  1974. many times."""
  1975. raise NotImplementedError
  1976. @cpython_api([FILE, rffi.CCHARP, rffi.INT_real], _node)
  1977. def PyParser_SimpleParseFile(space, fp, filename, start):
  1978. """This is a simplified interface to PyParser_SimpleParseFileFlags() below,
  1979. leaving flags set to 0"""
  1980. raise NotImplementedError
  1981. @cpython_api([FILE, rffi.CCHARP, rffi.INT_real, rffi.INT_real], _node)
  1982. def PyParser_SimpleParseFileFlags(space, fp, filename, start, flags):
  1983. """Similar to PyParser_SimpleParseStringFlagsFilename(), but the Python
  1984. source code is read from fp instead of an in-memory string."""
  1985. raise NotImplementedError
  1986. @cpython_api([FILE, rffi.CCHARP, rffi.INT_real, PyObject, PyObject, rffi.INT_real], PyObject)
  1987. def PyRun_FileEx(space, fp, filename, start, globals, locals, closeit):
  1988. """This is a simplified interface to PyRun_FileExFlags() below, leaving
  1989. flags set to NULL."""
  1990. raise NotImplementedError
  1991. @cpython_api([FILE, rffi.CCHARP, rffi.INT_real, PyObject, PyObject, PyCompilerFlags], PyObject)
  1992. def PyRun_FileFlags(space, fp, filename, start, globals, locals, flags):
  1993. """This is a simplified interface to PyRun_FileExFlags() below, leaving
  1994. closeit set to 0."""
  1995. raise NotImplementedError
  1996. @cpython_api([FILE, rffi.CCHARP, rffi.INT_real, PyObject, PyObject, rffi.INT_real, PyCompilerFlags], PyObject)
  1997. def PyRun_FileExFlags(space, fp, filename, start, globals, locals, closeit, flags):
  1998. """Similar to PyRun_StringFlags(), but the Python source code is read from
  1999. fp instead of an in-memory string. filename should be the name of the file.
  2000. If closeit is true, the file is closed before PyRun_FileExFlags()
  2001. returns."""
  2002. raise NotImplementedError
  2003. @cpython_api([PyCodeObject, PyObject, PyObject, PyObjectP, rffi.INT_real, PyObjectP, rffi.INT_real, PyObjectP, rffi.INT_real, PyObject], PyObject)
  2004. def PyEval_EvalCodeEx(space, co, globals, locals, args, argcount, kws, kwcount, defs, defcount, closure):
  2005. """Evaluate a precompiled code object, given a particular environment for its
  2006. evaluation. This environment consists of dictionaries of global and local
  2007. variables, arrays of arguments, keywords and defaults, and a closure tuple of
  2008. cells."""
  2009. raise NotImplementedError
  2010. @cpython_api([PyFrameObject], PyObject)
  2011. def PyEval_EvalFrame(space, f):
  2012. """Evaluate an execution frame. This is a simplified interface to
  2013. PyEval_EvalFrameEx, for backward compatibility."""
  2014. raise NotImplementedError
  2015. @cpython_api([PyFrameObject, rffi.INT_real], PyObject)
  2016. def PyEval_EvalFrameEx(space, f, throwflag):
  2017. """This is the main, unvarnished function of Python interpretation. It is
  2018. literally 2000 lines long. The code object associated with the execution
  2019. frame f is executed, interpreting bytecode and executing calls as needed.
  2020. The additional throwflag parameter can mostly be ignored - if true, then
  2021. it causes an exception to immediately be thrown; this is used for the
  2022. throw() methods of generator objects."""
  2023. raise NotImplementedError
  2024. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  2025. def PyWeakref_Check(space, ob):
  2026. """Return true if ob is either a reference or proxy object.
  2027. """
  2028. raise NotImplementedError
  2029. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  2030. def PyWeakref_CheckRef(space, ob):
  2031. """Return true if ob is a reference object.
  2032. """
  2033. raise NotImplementedError
  2034. @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
  2035. def PyWeakref_CheckProxy(space, ob):
  2036. """Return true if ob is a proxy object.
  2037. """
  2038. raise NotImplementedError