Skip to content

gh-98928: Remove negative reference counter check section from PyObject_Print #98929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,33 +271,26 @@ PyObject_Print(PyObject *op, FILE *fp, int flags)
Py_END_ALLOW_THREADS
}
else {
if (Py_REFCNT(op) <= 0) {
Py_BEGIN_ALLOW_THREADS
fprintf(fp, "<refcnt %zd at %p>", Py_REFCNT(op), (void *)op);
Py_END_ALLOW_THREADS
PyObject *s;
if (flags & Py_PRINT_RAW)
s = PyObject_Str(op);
else
s = PyObject_Repr(op);
if (s == NULL) {
ret = -1;
}
else {
PyObject *s;
if (flags & Py_PRINT_RAW)
s = PyObject_Str(op);
else
s = PyObject_Repr(op);
if (s == NULL) {
assert(PyUnicode_Check(s));
const char *t;
Py_ssize_t len;
t = PyUnicode_AsUTF8AndSize(s, &len);
if (t == NULL) {
ret = -1;
}
else {
assert(PyUnicode_Check(s));
const char *t;
Py_ssize_t len;
t = PyUnicode_AsUTF8AndSize(s, &len);
if (t == NULL) {
ret = -1;
}
else {
fwrite(t, 1, len, fp);
}
Py_DECREF(s);
fwrite(t, 1, len, fp);
}
Py_DECREF(s);
}
}
if (ret == 0) {
Expand Down