So I have a C program which uses an embedded CPython interpreter to execute Python code. The problem is that if the Python code has an error, the line number information provided by the interpreter is sort of useless, because each call to PyEval_EvalCodeEx
begins counting lines at 1. So, I'd like to give the Python interpreter a context, in terms of line numbers, whenever I execute code.
Is there a way to do this? Looking at the definition of PyEval_EvalCodeEx
, which is ultimately the lowest level function for code execution that is exposed by the Python C-API, I don't see any opportunity to pass in line number information.
The docs simply read:
PyObject* PyEval_EvalCodeEx(PyObject *co, PyObject *globals, PyObject *locals, PyObject **args, int argcount, PyObject **kws, int kwcount, PyObject **defs, int defcount, PyObject *closure)
Evaluate a precompiled code object, given a particular environment for its evaluation. This environment consists of dictionaries of global and local variables, arrays of arguments, keywords and defaults, and a closure tuple of cells.
So is this simply not possible to do?