[Python-checkins] cpython (merge 3.6 -> default): Merge 3.6 (issue #28003)

yury.selivanov python-checkins at python.org
Tue Nov 8 19:46:45 EST 2016


https://hg.python.org/cpython/rev/6f51b495656c
changeset:   105000:6f51b495656c
parent:      104998:88f0be352cb8
parent:      104999:9f32ef6b210b
user:        Yury Selivanov <yury at magic.io>
date:        Tue Nov 08 19:46:41 2016 -0500
summary:
  Merge 3.6 (issue #28003)

files:
  Objects/genobject.c |  62 +++++++++++++++++++++++++-------
  1 files changed, 48 insertions(+), 14 deletions(-)


diff --git a/Objects/genobject.c b/Objects/genobject.c
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -1503,14 +1503,14 @@
         _PyAsyncGenWrappedValue *o;
         o = ag_value_freelist[--ag_value_freelist_free];
         assert(_PyAsyncGenWrappedValue_CheckExact(o));
-        PyObject_Del(o);
+        PyObject_GC_Del(o);
     }
 
     while (ag_asend_freelist_free) {
         PyAsyncGenASend *o;
         o = ag_asend_freelist[--ag_asend_freelist_free];
         assert(Py_TYPE(o) == &_PyAsyncGenASend_Type);
-        PyObject_Del(o);
+        PyObject_GC_Del(o);
     }
 
     return ret;
@@ -1557,16 +1557,25 @@
 static void
 async_gen_asend_dealloc(PyAsyncGenASend *o)
 {
+    _PyObject_GC_UNTRACK((PyObject *)o);
     Py_CLEAR(o->ags_gen);
     Py_CLEAR(o->ags_sendval);
     if (ag_asend_freelist_free < _PyAsyncGen_MAXFREELIST) {
         assert(PyAsyncGenASend_CheckExact(o));
         ag_asend_freelist[ag_asend_freelist_free++] = o;
     } else {
-        PyObject_Del(o);
+        PyObject_GC_Del(o);
     }
 }
 
+static int
+async_gen_asend_traverse(PyAsyncGenASend *o, visitproc visit, void *arg)
+{
+    Py_VISIT(o->ags_gen);
+    Py_VISIT(o->ags_sendval);
+    return 0;
+}
+
 
 static PyObject *
 async_gen_asend_send(PyAsyncGenASend *o, PyObject *arg)
@@ -1668,9 +1677,9 @@
     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 */
     0,                                          /* tp_doc */
-    0,                                          /* tp_traverse */
+    (traverseproc)async_gen_asend_traverse,     /* tp_traverse */
     0,                                          /* tp_clear */
     0,                                          /* tp_richcompare */
     0,                                          /* tp_weaklistoffset */
@@ -1699,7 +1708,7 @@
         o = ag_asend_freelist[ag_asend_freelist_free];
         _Py_NewReference((PyObject *)o);
     } else {
-        o = PyObject_New(PyAsyncGenASend, &_PyAsyncGenASend_Type);
+        o = PyObject_GC_New(PyAsyncGenASend, &_PyAsyncGenASend_Type);
         if (o == NULL) {
             return NULL;
         }
@@ -1712,6 +1721,8 @@
     o->ags_sendval = sendval;
 
     o->ags_state = AWAITABLE_STATE_INIT;
+
+    _PyObject_GC_TRACK((PyObject*)o);
     return (PyObject*)o;
 }
 
@@ -1722,16 +1733,26 @@
 static void
 async_gen_wrapped_val_dealloc(_PyAsyncGenWrappedValue *o)
 {
+    _PyObject_GC_UNTRACK((PyObject *)o);
     Py_CLEAR(o->agw_val);
     if (ag_value_freelist_free < _PyAsyncGen_MAXFREELIST) {
         assert(_PyAsyncGenWrappedValue_CheckExact(o));
         ag_value_freelist[ag_value_freelist_free++] = o;
     } else {
-        PyObject_Del(o);
+        PyObject_GC_Del(o);
     }
 }
 
 
+static int
+async_gen_wrapped_val_traverse(_PyAsyncGenWrappedValue *o,
+                               visitproc visit, void *arg)
+{
+    Py_VISIT(o->agw_val);
+    return 0;
+}
+
+
 PyTypeObject _PyAsyncGenWrappedValue_Type = {
     PyVarObject_HEAD_INIT(&PyType_Type, 0)
     "async_generator_wrapped_value",            /* tp_name */
@@ -1753,9 +1774,9 @@
     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 */
     0,                                          /* tp_doc */
-    0,                                          /* tp_traverse */
+    (traverseproc)async_gen_wrapped_val_traverse, /* tp_traverse */
     0,                                          /* tp_clear */
     0,                                          /* tp_richcompare */
     0,                                          /* tp_weaklistoffset */
@@ -1787,13 +1808,15 @@
         assert(_PyAsyncGenWrappedValue_CheckExact(o));
         _Py_NewReference((PyObject*)o);
     } else {
-        o = PyObject_New(_PyAsyncGenWrappedValue, &_PyAsyncGenWrappedValue_Type);
+        o = PyObject_GC_New(_PyAsyncGenWrappedValue,
+                            &_PyAsyncGenWrappedValue_Type);
         if (o == NULL) {
             return NULL;
         }
     }
     o->agw_val = val;
     Py_INCREF(val);
+    _PyObject_GC_TRACK((PyObject*)o);
     return (PyObject*)o;
 }
 
@@ -1804,9 +1827,19 @@
 static void
 async_gen_athrow_dealloc(PyAsyncGenAThrow *o)
 {
+    _PyObject_GC_UNTRACK((PyObject *)o);
     Py_CLEAR(o->agt_gen);
     Py_CLEAR(o->agt_args);
-    PyObject_Del(o);
+    PyObject_GC_Del(o);
+}
+
+
+static int
+async_gen_athrow_traverse(PyAsyncGenAThrow *o, visitproc visit, void *arg)
+{
+    Py_VISIT(o->agt_gen);
+    Py_VISIT(o->agt_args);
+    return 0;
 }
 
 
@@ -1990,9 +2023,9 @@
     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 */
     0,                                          /* tp_doc */
-    0,                                          /* tp_traverse */
+    (traverseproc)async_gen_athrow_traverse,    /* tp_traverse */
     0,                                          /* tp_clear */
     0,                                          /* tp_richcompare */
     0,                                          /* tp_weaklistoffset */
@@ -2016,7 +2049,7 @@
 async_gen_athrow_new(PyAsyncGenObject *gen, PyObject *args)
 {
     PyAsyncGenAThrow *o;
-    o = PyObject_New(PyAsyncGenAThrow, &_PyAsyncGenAThrow_Type);
+    o = PyObject_GC_New(PyAsyncGenAThrow, &_PyAsyncGenAThrow_Type);
     if (o == NULL) {
         return NULL;
     }
@@ -2025,5 +2058,6 @@
     o->agt_state = AWAITABLE_STATE_INIT;
     Py_INCREF(gen);
     Py_XINCREF(args);
+    _PyObject_GC_TRACK((PyObject*)o);
     return (PyObject*)o;
 }

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list