Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a11cc68

Browse files
committed
Enhance Py_NewRef() tests
1 parent f9e807c commit a11cc68

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

runtests.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/test_pythoncapi_compat_cext.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@ test_object(PyObject *self, PyObject *ignored)
1717
if (obj == NULL) {
1818
return NULL;
1919
}
20+
Py_ssize_t refcnt = Py_REFCNT(obj);
2021

2122
// Py_NewRef() and Py_XNewRef()
22-
Py_ssize_t refcnt = Py_REFCNT(obj);
23-
PyObject *obj2 = Py_NewRef(obj);
23+
PyObject *ref = Py_NewRef(obj);
24+
assert(ref == obj);
25+
assert(Py_REFCNT(obj) == (refcnt + 1));
26+
Py_DECREF(ref);
27+
28+
// Py_XNewRef()
29+
PyObject *xref = Py_XNewRef(obj);
30+
assert(xref == obj);
2431
assert(Py_REFCNT(obj) == (refcnt + 1));
25-
PyObject *obj3 = Py_XNewRef(obj);
26-
assert(Py_REFCNT(obj) == (refcnt + 2));
32+
Py_DECREF(xref);
33+
2734
assert(Py_XNewRef(NULL) == NULL);
28-
Py_DECREF(obj2);
29-
Py_DECREF(obj3);
30-
assert(Py_REFCNT(obj) == refcnt);
3135

3236
// test Py_SET_REFCNT
3337
Py_SET_REFCNT(obj, Py_REFCNT(obj));
@@ -39,6 +43,7 @@ test_object(PyObject *self, PyObject *ignored)
3943
int is_type = Py_IS_TYPE(obj, Py_TYPE(obj));
4044
assert(is_type);
4145

46+
assert(Py_REFCNT(obj) == refcnt);
4247
Py_DECREF(obj);
4348
Py_RETURN_NONE;
4449
}

0 commit comments

Comments
 (0)