This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pablogsal
Recipients gvanrossum, lukasz.langa, pablogsal
Date 2019-02-01.20:21:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1549052481.79.0.274596395553.issue35879@roundup.psfhosted.org>
In-reply-to
Content
Hummmm.... I may be missing something but these is what I am seeing:

BASELINE
--------

❯ ./python.exe -m test test_type_comments -R 10:10
Run tests sequentially
0:00:00 load avg: 2.30 [1/1] test_type_comments
beginning 20 repetitions
12345678901234567890
....................
test_type_comments leaked [37, 37, 37, 37, 37, 37, 37, 37, 37, 37] references, sum=370
test_type_comments leaked [11, 12, 11, 11, 11, 11, 11, 11, 11, 11] memory blocks, sum=111
test_type_comments failed

== Tests result: FAILURE ==

1 test failed:
    test_type_comments

Total duration: 1 sec 28 ms
Tests result: FAILURE


EXTRA_DECREF
------------
❯ git --no-pager diff
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index 1a56e90bca..cb3036dbba 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -2791,6 +2791,7 @@ ast2obj_stmt(void* _o)
         if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1)
             goto failed;
         Py_DECREF(value);
+        Py_DECREF(value);
         break;
     case AsyncFunctionDef_kind:
         result = PyType_GenericNew(AsyncFunctionDef_type, NULL, NULL);

~/github/cpython master ✗
❯ ./python.exe -m test test_type_comments -R 10:10
Run tests sequentially
0:00:00 load avg: 2.12 [1/1] test_type_comments
beginning 20 repetitions
12345678901234567890
....................
test_type_comments leaked [8, 9, 8, 8, 8, 8, 8, 8, 8, 8] memory blocks, sum=81
test_type_comments failed

== Tests result: FAILURE ==

1 test failed:
    test_type_comments

Total duration: 976 ms
Tests result: FAILURE


So my interpretation is that there are still leaks somewhere or, but the extra-decref resolves the reference leaks somehow. Probably the extra DECREF here is not the proper fix, but is as far as I went when I started debugging this morning. Also, if you change one test to do the parsing in a loop:


     def test_funcdef(self):
-        tree = self.parse(funcdef)
+        for _ in range(100000):
+            tree = self.parse(funcdef)
         self.assertEqual(tree.body[0].type_comment, "() -> int")


And you ran test_type_comments.py with PYTHONDUMPREFS=1:

WITHOUT EXTRA DECREF
--------------------

  65 wrapper_descriptor
  75 str
  82 str
  85 str
  86 str
  92 str
 110 str
 416 str
200015 str


WITH EXTRA DECREF
-----------------

PYTHONDUMPREFS=1 ./python.exe -m test test_type_comments |& cut -d " " -f 3 | uniq -c | sort -n
....
  85 str
  86 str
  92 str
 110 str
 416 str
History
Date User Action Args
2019-02-01 20:21:23pablogsalsetrecipients: + pablogsal, gvanrossum, lukasz.langa
2019-02-01 20:21:21pablogsalsetmessageid: <1549052481.79.0.274596395553.issue35879@roundup.psfhosted.org>
2019-02-01 20:21:21pablogsallinkissue35879 messages
2019-02-01 20:21:21pablogsalcreate