]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix sys.getdxp() when configured with --enable-pystats. (GH-31251)
authorMark Shannon <mark@hotpy.org>
Thu, 10 Feb 2022 12:14:57 +0000 (12:14 +0000)
committerGitHub <noreply@github.com>
Thu, 10 Feb 2022 12:14:57 +0000 (12:14 +0000)
Python/ceval.c

index 958ca11409c322788bd97749d38523a41cdf9278..7e19043c7aa64ef839a5d05b119feb454f1e2989 100644 (file)
@@ -7459,7 +7459,7 @@ _Py_GetDXProfile(PyObject *self, PyObject *args)
     int i;
     PyObject *l = PyList_New(257);
     if (l == NULL) return NULL;
-    for (i = 0; i < 257; i++) {
+    for (i = 0; i < 256; i++) {
         PyObject *x = getarray(_py_stats.opcode_stats[i].pair_count);
         if (x == NULL) {
             Py_DECREF(l);
@@ -7467,6 +7467,22 @@ _Py_GetDXProfile(PyObject *self, PyObject *args)
         }
         PyList_SET_ITEM(l, i, x);
     }
+    PyObject *counts = PyList_New(256);
+    if (counts == NULL) {
+        Py_DECREF(l);
+        return NULL;
+    }
+    for (i = 0; i < 256; i++) {
+        PyObject *x = PyLong_FromUnsignedLongLong(
+            _py_stats.opcode_stats[i].execution_count);
+        if (x == NULL) {
+            Py_DECREF(counts);
+            Py_DECREF(l);
+            return NULL;
+        }
+        PyList_SET_ITEM(counts, i, x);
+    }
+    PyList_SET_ITEM(l, 256, counts);
     return l;
 }