◐ Shell
reader mode source ↗
Skip to content
Merged
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
14 changes: 14 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ Upgrade Operations
* Replace ``obj->ob_refcnt = refcnt;`` with ``Py_SET_REFCNT(obj, refcnt);``.
* Replace ``Py_REFCNT(obj) = refcnt;`` with ``Py_SET_REFCNT(obj, refcnt);``.

* ``PyObject_NEW``:

* Replace ``PyObject_NEW(...)`` with ``PyObject_New(...)``.
Expand Down @@ -156,6 +165,10 @@ Python 3.10

PyObject* Py_NewRef(PyObject *obj);
PyObject* Py_XNewRef(PyObject *obj);

int PyModule_AddObjectRef(PyObject *module, const char *name, PyObject *value);

Expand Down Expand Up @@ -324,6 +337,7 @@ Links
Changelog
=========

* 2021-04-01:

* Add ``Py_SETREF()``, ``Py_XSETREF()`` and ``Py_UNUSED()``.
Expand Down
17 changes: 17 additions & 0 deletions pythoncapi_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ static inline void _Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt)
} while (0)
#endif

// bpo-39573 added Py_SET_TYPE() to Python 3.9.0a4
#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)
static inline void
Expand Down
35 changes: 35 additions & 0 deletions tests/test_pythoncapi_compat_cext.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,40 @@ test_object(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
}


static PyObject *
test_steal_ref(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
{
Expand Down Expand Up @@ -358,6 +392,7 @@ test_module(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))

static struct PyMethodDef methods[] = {
{"test_object", test_object, METH_NOARGS, NULL},
{"test_steal_ref", test_steal_ref, METH_NOARGS, NULL},
#if !defined(PYPY_VERSION)
{"test_frame", test_frame, METH_NOARGS, NULL},
63 changes: 63 additions & 0 deletions tests/test_upgrade_pythoncapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def reformat(source):


class Tests(unittest.TestCase):
def _test_patch_file(self, tmp_dir):
# test Patcher.patcher()
source = """
Expand Down Expand Up @@ -473,6 +475,67 @@ def test_py_decref_assign(self):
}
""")


if __name__ == "__main__":
unittest.main()
Toggle all file notes Toggle all file annotations