[Lldb-commits] [lldb] [lldb] Reimplement PythonObject::Dump using the limited API (PR #152055)
Med Ismail Bennani via lldb-commits
lldb-commits at lists.llvm.org
Mon Aug 4 16:47:45 PDT 2025
================
@@ -131,23 +132,30 @@ void StructuredPythonObject::Serialize(llvm::json::OStream &s) const {
// PythonObject
void PythonObject::Dump(Stream &strm) const {
- if (m_py_obj) {
- FILE *file = llvm::sys::RetryAfterSignal(nullptr, ::tmpfile);
- if (file) {
- ::PyObject_Print(m_py_obj, file, 0);
- const long length = ftell(file);
- if (length) {
- ::rewind(file);
- std::vector<char> file_contents(length, '\0');
- const size_t length_read =
- ::fread(file_contents.data(), 1, file_contents.size(), file);
- if (length_read > 0)
- strm.Write(file_contents.data(), length_read);
- }
- ::fclose(file);
- }
- } else
- strm.PutCString("NULL");
+ if (!m_py_obj) {
+ strm << "NULL";
+ return;
+ }
+
+ PyObject *py_str = PyObject_Repr(m_py_obj);
+ if (!py_str)
+ return;
+
+ auto release_py_str = llvm::make_scope_exit([py_str] { Py_DECREF(py_str); });
+
+ PyObject *py_bytes = PyUnicode_AsEncodedString(py_str, "utf-8", "replace");
----------------
medismailben wrote:
"replace" :p
https://github.com/llvm/llvm-project/pull/152055
More information about the lldb-commits
mailing list