diff options
author | 2016-04-16 14:47:12 -0700 | |
---|---|---|
committer | 2016-04-16 14:47:12 -0700 | |
commit | 2b601d39058dbcd0881ffaab40eeb4981f431fc8 (patch) | |
tree | 870e74f2a3ebea631b29bc5e4409fa4a002ac729 /Objects/sliceobject.c | |
parent | Issue #26783: test_os.WalkTests.test_walk_topdown did't test fwalk and bytes. (diff) | |
download | cpython-2b601d39058dbcd0881ffaab40eeb4981f431fc8.tar.gz cpython-2b601d39058dbcd0881ffaab40eeb4981f431fc8.tar.bz2 cpython-2b601d39058dbcd0881ffaab40eeb4981f431fc8.zip |
add gc support to slice (closes #26659)
Diffstat (limited to 'Objects/sliceobject.c')
-rw-r--r-- | Objects/sliceobject.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c index 104952333a5..bf5eb3aeee8 100644 --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -119,7 +119,7 @@ PySlice_New(PyObject *start, PyObject *stop, PyObject *step) slice_cache = NULL; _Py_NewReference((PyObject *)obj); } else { - obj = PyObject_New(PySliceObject, &PySlice_Type); + obj = PyObject_GC_New(PySliceObject, &PySlice_Type); if (obj == NULL) return NULL; } @@ -135,6 +135,7 @@ PySlice_New(PyObject *start, PyObject *stop, PyObject *step) obj->start = start; obj->stop = stop; + _PyObject_GC_TRACK(obj); return (PyObject *) obj; } @@ -288,13 +289,14 @@ Create a slice object. This is used for extended slicing (e.g. a[0:10:2])."); static void slice_dealloc(PySliceObject *r) { + _PyObject_GC_UNTRACK(r); Py_DECREF(r->step); Py_DECREF(r->start); Py_DECREF(r->stop); if (slice_cache == NULL) slice_cache = r; else - PyObject_Del(r); + PyObject_GC_Del(r); } static PyObject * @@ -586,6 +588,15 @@ slice_richcompare(PyObject *v, PyObject *w, int op) return res; } +static int +slice_traverse(PySliceObject *v, visitproc visit, void *arg) +{ + Py_VISIT(v->start); + Py_VISIT(v->stop); + Py_VISIT(v->step); + return 0; +} + PyTypeObject PySlice_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "slice", /* Name of this type */ @@ -606,9 +617,9 @@ PyTypeObject PySlice_Type = { PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ slice_doc, /* tp_doc */ - 0, /* tp_traverse */ + (traverseproc)slice_traverse, /* tp_traverse */ 0, /* tp_clear */ slice_richcompare, /* tp_richcompare */ 0, /* tp_weaklistoffset */ |