From bc5c7edf476cbfbb0204a75cb61600055e32d57b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCmer=20Cip?= Date: Mon, 16 Mar 2026 14:07:54 +0300 Subject: [PATCH 1/5] update gh workflows --- .github/workflows/main.yml | 18 ++++++++++++++++++ yappi/_yappi.c | 38 ++++++++++++++++++++++++++++++++++---- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5bd41cd..e163969 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,3 +26,21 @@ jobs: run: python -m pip install .[test] - name: run tests run: python run_tests.py + + build-debug: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] + steps: + - uses: actions/checkout@v4 + - name: Set up debug Python ${{ matrix.python-version }} + uses: deadsnakes/action@v3.2.0 + with: + python-version: ${{ matrix.python-version }} + debug: true + - name: Install test dependencies + run: python -m pip install .[test] + - name: Run tests (debug build) + run: python run_tests.py diff --git a/yappi/_yappi.c b/yappi/_yappi.c index b0fd36b..a46d4d9 100644 --- a/yappi/_yappi.c +++ b/yappi/_yappi.c @@ -461,9 +461,21 @@ _current_context_id(PyThreadState *ts) ytid = PyDict_GetItemString(ts->dict, "_yappi_tid"); if (!ytid) { ytid = PyLong_FromLongLong(ycurthreadindex++); - PyDict_SetItemString(ts->dict, "_yappi_tid", ytid); + if (!ytid) { + PyErr_Clear(); + return 0; + } + if (PyDict_SetItemString(ts->dict, "_yappi_tid", ytid) < 0) { + Py_DECREF(ytid); + PyErr_Clear(); + return 0; + } } rc = PyLong_AsVoidPtr(ytid); + if (PyErr_Occurred()) { + PyErr_Clear(); + return 0; + } return rc; } @@ -601,15 +613,21 @@ _ccode2pit(void *cco, uintptr_t current_tag) name = PyStr_FromString(cfn->m_ml->ml_name); if (name != NULL) { obj_type = PyObject_Type(cfn->m_self); + if (obj_type == NULL) { + PyErr_Clear(); + Py_DECREF(name); + goto fallback_name; + } // use method descriptor instead of instance methods for builtin - // objects. Othwerwise, there might be some errors since we INCREF + // objects. Otherwise, there might be some errors since we INCREF // on the bound method. See: https://github.com/sumerc/yappi/issues/60 method_descriptor = PyObject_GetAttr(obj_type, name); if (method_descriptor) { pit->fn_descriptor = method_descriptor; Py_INCREF(method_descriptor); } + PyErr_Clear(); // get name from type+name mo = _PyType_Lookup((PyTypeObject *)obj_type, name); @@ -625,6 +643,7 @@ _ccode2pit(void *cco, uintptr_t current_tag) PyErr_Clear(); } +fallback_name: if (pit->fn_descriptor == NULL) { pit->fn_descriptor = (PyObject *)cfn; Py_INCREF(cfn); @@ -1652,17 +1671,26 @@ enum_context_stats(PyObject *self, PyObject *args) int _pit_filtered(_pit *pt, _ctxfuncenumarg *eargs) { _fast_func_stat_filter filter; + int cmp; filter = eargs->enum_args->func_filter; if (filter.name) { - if (!PyObject_RichCompareBool(pt->name, filter.name, Py_EQ)) { + cmp = PyObject_RichCompareBool(pt->name, filter.name, Py_EQ); + if (cmp == -1) { + PyErr_Clear(); + } + if (cmp != 1) { return 1; } } if (filter.modname) { - if (!PyObject_RichCompareBool(pt->modname, filter.modname, Py_EQ)) { + cmp = PyObject_RichCompareBool(pt->modname, filter.modname, Py_EQ); + if (cmp == -1) { + PyErr_Clear(); + } + if (cmp != 1) { return 1; } } @@ -1826,6 +1854,7 @@ _filterdict_to_statfilter(PyObject *filter_dict, _fast_func_stat_filter* filter) if (fv) { PyLong_AsVoidPtr(fv); if (PyErr_Occurred()) { + PyErr_Clear(); yerr("invalid tag passed to get_func_stats."); filter->tag = NULL; return 0; @@ -1836,6 +1865,7 @@ _filterdict_to_statfilter(PyObject *filter_dict, _fast_func_stat_filter* filter) if (fv) { PyLong_AsVoidPtr(fv); if (PyErr_Occurred()) { + PyErr_Clear(); yerr("invalid ctx_id passed to get_func_stats."); filter->ctx_id = NULL; return 0; From 6356863332cda9ab86aa6324e34c73de1d87f147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCmer=20Cip?= Date: Mon, 16 Mar 2026 14:19:46 +0300 Subject: [PATCH 2/5] fix _filterdict_to_statfilter --- yappi/_yappi.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/yappi/_yappi.c b/yappi/_yappi.c index a46d4d9..8b867ef 100644 --- a/yappi/_yappi.c +++ b/yappi/_yappi.c @@ -1856,6 +1856,7 @@ _filterdict_to_statfilter(PyObject *filter_dict, _fast_func_stat_filter* filter) if (PyErr_Occurred()) { PyErr_Clear(); yerr("invalid tag passed to get_func_stats."); + PyErr_SetString(YappiProfileError, "invalid tag passed to get_func_stats"); filter->tag = NULL; return 0; } @@ -1867,6 +1868,7 @@ _filterdict_to_statfilter(PyObject *filter_dict, _fast_func_stat_filter* filter) if (PyErr_Occurred()) { PyErr_Clear(); yerr("invalid ctx_id passed to get_func_stats."); + PyErr_SetString(YappiProfileError, "invalid ctx_id passed to get_func_stats"); filter->ctx_id = NULL; return 0; } From ce1b95ec263f25cc81f68cb055349a7f486d0973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCmer=20Cip?= Date: Mon, 16 Mar 2026 14:22:24 +0300 Subject: [PATCH 3/5] add assertion job --- .github/workflows/main.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e163969..342a5dd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,16 +29,12 @@ jobs: build-debug: runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] steps: - uses: actions/checkout@v4 - - name: Set up debug Python ${{ matrix.python-version }} + - name: Set up debug Python uses: deadsnakes/action@v3.2.0 with: - python-version: ${{ matrix.python-version }} + python-version: "3.13" debug: true - name: Install test dependencies run: python -m pip install .[test] From 1fa3096566ae39ea7d6b8a616545d77d9959878c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCmer=20Cip?= Date: Mon, 16 Mar 2026 14:25:11 +0300 Subject: [PATCH 4/5] rename GH workflows test: ci test: ci test: ci test: ci test:ci re-add 201 fix --- .github/workflows/main.yml | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 342a5dd..d84e9b2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,7 +7,7 @@ concurrency: cancel-in-progress: true jobs: - build: + test: runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -27,16 +27,25 @@ jobs: - name: run tests run: python run_tests.py - build-debug: + test-debug: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Set up debug Python - uses: deadsnakes/action@v3.2.0 + - name: Cache Python debug build + uses: actions/cache@v4 + id: cache-python with: - python-version: "3.13" - debug: true + path: ~/python-debug + key: python-3.12.12-pydebug + - name: Build Python 3.12 with --with-pydebug + if: steps.cache-python.outputs.cache-hit != 'true' + run: | + sudo apt-get update -qq && sudo apt-get install -y -qq build-essential zlib1g-dev libffi-dev libssl-dev libbz2-dev libreadline-dev libsqlite3-dev liblzma-dev + curl -sL https://www.python.org/ftp/python/3.12.12/Python-3.12.12.tgz | tar xz + cd Python-3.12.12 + ./configure --with-pydebug --prefix=$HOME/python-debug -q + make -j$(nproc) -s && make install -s - name: Install test dependencies - run: python -m pip install .[test] + run: ~/python-debug/bin/python3.12 -m pip install .[test] - name: Run tests (debug build) - run: python run_tests.py + run: ~/python-debug/bin/python3.12 run_tests.py From e0ab03688ac6acdf39cacadb26e9effa1b82a45b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCmer=20Cip?= Date: Mon, 16 Mar 2026 15:46:03 +0300 Subject: [PATCH 5/5] fix: debug ci test --- .github/workflows/main.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d84e9b2..537893a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -46,6 +46,10 @@ jobs: ./configure --with-pydebug --prefix=$HOME/python-debug -q make -j$(nproc) -s && make install -s - name: Install test dependencies - run: ~/python-debug/bin/python3.12 -m pip install .[test] + run: | + export PATH=$HOME/python-debug/bin:$PATH + python3.12 -m pip install .[test] - name: Run tests (debug build) - run: ~/python-debug/bin/python3.12 run_tests.py + run: | + export PATH=$HOME/python-debug/bin:$PATH + python3.12 run_tests.py