GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — MAINT: add more comments, don't use subprocess in test · numpy/numpy@0c06127

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • numpy/_core
    • src/multiarray
      • descriptor.c
    • tests
      • test_dtype.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎numpy/_core/src/multiarray/descriptor.c‎

Copy file name to clipboardExpand all lines: numpy/_core/src/multiarray/descriptor.c
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,13 +2097,30 @@ arraydescr_dealloc(PyArray_Descr *self)
20972097
* reference (descriptors support neither weakrefs nor GC), so
20982098
* stealing the link is unobservable and each node still runs
20992099
* its own, now shallow, dealloc.
2100+
*
2101+
* If descriptors ever become heap types and/or GC types, we can
2102+
* use CPython's stack protection via the trashcan macros
2103+
* instead.
21002104
*/
21012105
PyArray_Descr *base = lself->subarray->base;
21022106
PyArray_free(lself->subarray);
2107+
/*
2108+
* The Py_REFCNT(..) == 1 check is intentional. This happens in
2109+
* a deallocator for a type that doesn't support weakrefs and
2110+
* isn't a GC type, so it's impossible for another thread to
2111+
* concurrently change the reference count if we observe the
2112+
* reference count is 1 here. We can't use
2113+
* PyUnstable_Object_IsUniquelyReferenced because that excludes
2114+
* objects on remote threads.
2115+
*/
21032116
while (base != NULL && Py_REFCNT(base) == 1 && PyDataType_HASSUBARRAY(base)) {
21042117
_PyArray_LegacyDescr *lbase = (_PyArray_LegacyDescr *)base;
2118+
// steal reference owned by lbase and stash it in base
2119+
// (Py_CLEAR without a DECREF)
21052120
base = lbase->subarray->base;
21062121
lbase->subarray->base = NULL;
2122+
// lbase no longer owns a reference to base, so its deallocator
2123+
// doesn't fire
21072124
Py_DECREF(lbase);
21082125
}
21092126
Py_XDECREF(base);
Collapse file

‎numpy/_core/tests/test_dtype.py‎

Copy file name to clipboardExpand all lines: numpy/_core/tests/test_dtype.py
+20-21Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import os
66
import pickle
77
import sys
8-
import textwrap
98
import types
109
import warnings
1110
from itertools import permutations
@@ -28,7 +27,7 @@
2827
assert_equal,
2928
assert_raises,
3029
)
31-
from numpy.testing._private.utils import requires_deep_recursion, run_subprocess
30+
from numpy.testing._private.utils import requires_deep_recursion
3231

3332

3433
def assert_dtype_equal(a, b):
@@ -902,25 +901,25 @@ def test_tuple_recursion(self):
902901
@pytest.mark.skipif(not HAS_SUBPROCESSES,
903902
reason="platform cannot start subprocesses")
904903
def test_deep_subarray_dtype_dealloc(self):
905-
script = textwrap.dedent("""
906-
import threading
907-
908-
import numpy as np
909-
910-
def build_and_drop():
911-
d = np.dtype(np.int32)
912-
for _ in range(200000):
913-
d = np.dtype((d, (1,)))
914-
held = d.base
915-
del d
916-
del held
917-
918-
threading.stack_size(1024 * 1024)
919-
t = threading.Thread(target=build_and_drop)
920-
t.start()
921-
t.join()
922-
""")
923-
run_subprocess([sys.executable, "-c", script], timeout=180)
904+
import threading
905+
906+
import numpy as np
907+
908+
def build_and_drop():
909+
d = np.dtype(np.int32)
910+
for _ in range(200000):
911+
d = np.dtype((d, (1,)))
912+
# hold a second reference so teardown exercises stopping
913+
# and resuming
914+
held = d.base
915+
del d
916+
del held
917+
918+
# small stack size to fail reliably if deallocation is recusive
919+
threading.stack_size(1024 * 1024)
920+
t = threading.Thread(target=build_and_drop)
921+
t.start()
922+
t.join()
924923

925924
@requires_deep_recursion
926925
def test_dict_recursion(self):

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.