diff options
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r-- | Doc/whatsnew/3.10.rst | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index 7ed80fb..5e510d8 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -1696,9 +1696,9 @@ Removed that were only being used by the old parser, including ``node.h``, ``parser.h``, ``graminit.h`` and ``grammar.h``. -* Removed the Public C API functions :c:func:`PyParser_SimpleParseStringFlags`, - :c:func:`PyParser_SimpleParseStringFlagsFilename`, - :c:func:`PyParser_SimpleParseFileFlags` and :c:func:`PyNode_Compile` +* Removed the Public C API functions ``PyParser_SimpleParseStringFlags``, + ``PyParser_SimpleParseStringFlagsFilename``, + ``PyParser_SimpleParseFileFlags`` and ``PyNode_Compile`` that were deprecated in 3.9 due to the switch to the new PEG parser. * Removed the ``formatter`` module, which was deprecated in Python 3.4. @@ -1812,6 +1812,41 @@ Changes in the Python API also inherits the current builtins. (Contributed by Victor Stinner in :issue:`42990`.) +Changes in the C API +-------------------- + +* The C API functions ``PyParser_SimpleParseStringFlags``, + ``PyParser_SimpleParseStringFlagsFilename``, + ``PyParser_SimpleParseFileFlags``, ``PyNode_Compile`` and the type + used by these functions, ``struct _node``, were removed due to the switch + to the new PEG parser. + + Source should be now be compiled directly to a code object using, for + example, :c:func:`Py_CompileString`. The resulting code object can then be + evaluated using, for example, :c:func:`PyEval_EvalCode`. + + Specifically: + + * A call to ``PyParser_SimpleParseStringFlags`` followed by + ``PyNode_Compile`` can be replaced by calling :c:func:`Py_CompileString`. + + * There is no direct replacement for ``PyParser_SimpleParseFileFlags``. + To compile code from a ``FILE *`` argument, you will need to read + the file in C and pass the resulting buffer to :c:func:`Py_CompileString`. + + * To compile a file given a ``char *`` filename, explicitly open the file, read + it and compile the result. One way to do this is using the :py:mod:`io` + module with :c:func:`PyImport_ImportModule`, :c:func:`PyObject_CallMethod`, + :c:func:`PyBytes_AsString` and :c:func:`Py_CompileString`, + as sketched below. (Declarations and error handling are omitted.) :: + + io_module = Import_ImportModule("io"); + fileobject = PyObject_CallMethod(io_module, "open", "ss", filename, "rb"); + source_bytes_object = PyObject_CallMethod(fileobject, "read", ""); + result = PyObject_CallMethod(fileobject, "close", ""); + source_buf = PyBytes_AsString(source_bytes_object); + code = Py_CompileString(source_buf, filename, Py_file_input); + CPython bytecode changes ======================== |