]> granicus.if.org Git - python/commitdiff
bpo-32436: Fix a refleak; var GC tracking; a GCC warning (#5326)
authorYury Selivanov <yury@magic.io>
Thu, 25 Jan 2018 19:18:55 +0000 (14:18 -0500)
committerGitHub <noreply@github.com>
Thu, 25 Jan 2018 19:18:55 +0000 (14:18 -0500)
The refleak in question wasn't really important, as context vars
are usually created at the toplevel and live as long as the interpreter
lives, so the context var name isn't ever GCed anyways.

Python/context.c
Python/hamt.c

index 5439531cd1e2f71fd28b9c4a3fbd9ef6b6e62254..d90ed25c4d4068152583a8ebbba93516a72d35d8 100644 (file)
@@ -134,7 +134,9 @@ PyContextVar_New(const char *name, PyObject *def)
     if (pyname == NULL) {
         return NULL;
     }
-    return contextvar_new(pyname, def);
+    PyContextVar *var = contextvar_new(pyname, def);
+    Py_DECREF(pyname);
+    return var;
 }
 
 
@@ -741,8 +743,8 @@ contextvar_new(PyObject *name, PyObject *def)
     var->var_cached_tsid = 0;
     var->var_cached_tsver = 0;
 
-    if (_PyObject_GC_IS_TRACKED(name) ||
-            (def != NULL && _PyObject_GC_IS_TRACKED(def)))
+    if (_PyObject_GC_MAY_BE_TRACKED(name) ||
+            (def != NULL && _PyObject_GC_MAY_BE_TRACKED(def)))
     {
         PyObject_GC_Track(var);
     }
index df3b1092cbe58ce522a0328734b605bc97c9ac6e..79c42c0f43346e4c92c42989493ac2060af5426a 100644 (file)
@@ -449,7 +449,7 @@ hamt_bitcount(uint32_t i)
     */
     i = i - ((i >> 1) & 0x55555555);
     i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
-    return ((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
+    return (((i + (i >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
 }
 
 static inline uint32_t