Skip to content

Commit 27c005d

Browse files
committed
Change print of gc.
1 parent b880e61 commit 27c005d

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

source/loaders/py_loader/source/py_loader_impl.c

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4130,29 +4130,39 @@ value py_loader_impl_error_value_from_exception(loader_impl_py py_impl, PyObject
41304130
void py_loader_impl_gc_print(loader_impl_py py_impl)
41314131
{
41324132
static const char garbage_format_str[] = "Python Garbage Collector:\n%s";
4133-
static const char separator_str[] = "\n";
4133+
PyObject *garbage_repr, *garbage_list = PyObject_GetAttrString(py_impl->gc_module, "garbage");
4134+
const char *garbage_str;
41344135

4135-
PyObject *garbage_list, *separator, *garbage_str_obj;
4136+
if (garbage_list == NULL)
4137+
{
4138+
goto error_garbage_list;
4139+
}
41364140

4137-
garbage_list = PyObject_GetAttrString(py_impl->gc_module, "garbage");
4141+
garbage_repr = PyObject_Repr(garbage_list);
41384142

4139-
#if PY_MAJOR_VERSION == 2
4140-
separator = PyString_FromString(separator_str);
4141-
4142-
garbage_str_obj = PyString_Join(separator, garbage_list);
4143+
if (garbage_repr == NULL)
4144+
{
4145+
goto error_garbage_repr;
4146+
}
41434147

4144-
log_write("metacall", LOG_LEVEL_DEBUG, garbage_format_str, PyString_AsString(garbage_str_obj));
4145-
#elif PY_MAJOR_VERSION == 3
4146-
separator = PyUnicode_FromString(separator_str);
4148+
garbage_str = PyUnicode_AsUTF8(garbage_repr);
41474149

4148-
garbage_str_obj = PyUnicode_Join(separator, garbage_list);
4150+
if (garbage_str == NULL)
4151+
{
4152+
goto error_garbage_str;
4153+
}
41494154

4150-
log_write("metacall", LOG_LEVEL_DEBUG, garbage_format_str, PyUnicode_AsUTF8(garbage_str_obj));
4151-
#endif
4155+
log_write("metacall", LOG_LEVEL_DEBUG, garbage_format_str, garbage_str);
41524156

4157+
error_garbage_str:
4158+
Py_DECREF(garbage_repr);
4159+
error_garbage_repr:
41534160
Py_DECREF(garbage_list);
4154-
Py_DECREF(separator);
4155-
Py_DECREF(garbage_str_obj);
4161+
error_garbage_list:
4162+
if (PyErr_Occurred() != NULL)
4163+
{
4164+
py_loader_impl_error_print(py_impl);
4165+
}
41564166
}
41574167

41584168
void py_loader_impl_sys_path_print(PyObject *sys_path_list)

0 commit comments

Comments
 (0)