Skip to content
Prev Previous commit
Next Next commit
Rework negative reference test
  • Loading branch information
MonadChains committed Nov 1, 2022
commit 2202e4a6dea2afb2ae1fe5025c3cb026bd525411
5 changes: 4 additions & 1 deletion Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,7 @@ pyobject_print_noref_object(PyObject *self, PyObject *args)

test_string = PyUnicode_FromString("Spam spam spam");

Py_DECREF(test_string);
test_string -> ob_refcnt = 0;

snprintf(correct_string, 100, "<refcnt %zd at %p>", Py_REFCNT(test_string), (void *)test_string);

Expand All @@ -2079,6 +2079,9 @@ pyobject_print_noref_object(PyObject *self, PyObject *args)

fclose(fp);

test_string -> ob_refcnt = 1;
Py_DECREF(test_string);

return PyUnicode_FromString(correct_string);
}

Expand Down