Skip to content

Commit 56b3d77

Browse files
committed
fix: add linter for thread-unsafe C API uses
1 parent 851ba15 commit 56b3d77

35 files changed

+1935
-89
lines changed

.github/workflows/mypy.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,21 @@ jobs:
7272
- name: Run Mypy
7373
run: |
7474
spin mypy
75+
# This job checks for suspicious C API usage that may break nogil compatibility.
76+
# It scans PR diffs for dangerous borrowed-referenced calls and fails if any are found.
77+
lint-capi:
78+
# To enable this workflow on a fork, comment out:
79+
if: github.repository == 'numpy/numpy'
80+
name: "C API Borrowed Ref Lint"
81+
runs-on: ubuntu-latest
82+
steps:
83+
- uses: actions/checkout@v3
84+
with:
85+
fetch-depth: 0
86+
submodules: recursive
87+
- name: Run API Borrowed Ref Linter
88+
run: |
89+
pip install -r requirements/build_requirements.txt
90+
pip install -r requirements/test_requirements.txt
91+
pip install ruff
92+
spin lint

numpy/_core/include/numpy/npy_3kcompat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static inline PyObject*
242242
npy_PyFile_OpenFile(PyObject *filename, const char *mode)
243243
{
244244
PyObject *open;
245-
open = PyDict_GetItemString(PyEval_GetBuiltins(), "open");
245+
open = PyDict_GetItemString(PyEval_GetBuiltins(), "open"); // noqa: borrowed-ref OK
246246
if (open == NULL) {
247247
return NULL;
248248
}

numpy/_core/src/common/npy_cpu_dispatch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ NPY_VISIBILITY_HIDDEN void
3333
npy_cpu_dispatch_trace(const char *fname, const char *signature,
3434
const char **dispatch_info)
3535
{
36-
PyObject *func_dict = PyDict_GetItemString(npy_static_pydata.cpu_dispatch_registry, fname);
36+
PyObject *func_dict = PyDict_GetItemString(npy_static_pydata.cpu_dispatch_registry, fname); // noqa: borrowed-ref OK
3737
if (func_dict == NULL) {
3838
func_dict = PyDict_New();
3939
if (func_dict == NULL) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy