The third default finder is the one that will load readline, so the custom
finder to disable the import of readline in GDB has to be placed before
this third default finder. */
- if (PyRun_SimpleString ("\
+ const char *code = "\
import sys\n\
from importlib.abc import MetaPathFinder\n\
\n\
raise ImportError(\"readline module disabled under GDB\")\n\
\n\
sys.meta_path.insert(2, GdbRemoveReadlineFinder())\n\
-") == 0)
+";
+ if (eval_python_command (code, Py_file_input) == 0)
PyOS_ReadlineFunctionPointer = gdbpy_readline_wrapper;
return 0;
gdb::unordered_map<val_type *, obj_type *> m_objects;
};
+extern int eval_python_command (const char *command, int start_symbol,
+ const char *filename = nullptr);
+
#endif /* GDB_PYTHON_PYTHON_INTERNAL_H */
NULL means that this is evaluating a string, not the contents of a
file. */
-static int
+int
eval_python_command (const char *command, int start_symbol,
- const char *filename = nullptr)
+ const char *filename)
{
PyObject *m, *d;
}
}
- /* Use this API because it is in Python 3.2. */
- gdbpy_ref<> code (Py_CompileStringExFlags (command,
- filename == nullptr
- ? "<string>"
- : filename,
- start_symbol,
- nullptr, -1));
+ /* Use this API because it is available with the Python limited API. */
+ gdbpy_ref<> code (Py_CompileString (command,
+ filename == nullptr
+ ? "<string>"
+ : filename,
+ start_symbol));
int result = -1;
if (code != nullptr)