🌐 AI搜索 & 代理 主页
Skip to content

Commit ae1ddd4

Browse files
authored
Merge pull request #29287 from charris/backport-29286
BUG: handle case in mapiter where descriptors might get replaced (#29286)
2 parents 9ebfca5 + 2332242 commit ae1ddd4

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

numpy/_core/src/multiarray/alloc.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
/* Do not enable the alloc cache if the GIL is disabled, or if ASAN or MSAN
3131
* instrumentation is enabled. The cache makes ASAN use-after-free or MSAN
3232
* use-of-uninitialized-memory warnings less useful. */
33-
#define USE_ALLOC_CACHE 1
3433
#ifdef Py_GIL_DISABLED
35-
# define USE_ALLOC_CACHE 0
34+
#define USE_ALLOC_CACHE 0
3635
#elif defined(__has_feature)
37-
# if __has_feature(address_sanitizer) || __has_feature(memory_sanitizer)
38-
# define USE_ALLOC_CACHE 0
39-
# endif
36+
#if __has_feature(address_sanitizer) || __has_feature(memory_sanitizer)
37+
#define USE_ALLOC_CACHE 0
38+
#endif
39+
#endif
40+
#ifndef USE_ALLOC_CACHE
41+
#define USE_ALLOC_CACHE 1
4042
#endif
4143

4244
# define NBUCKETS 1024 /* number of buckets for data*/

numpy/_core/src/multiarray/mapping.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3013,6 +3013,8 @@ PyArray_MapIterNew(npy_index_info *indices , int index_num, int index_type,
30133013
if (extra_op == NULL) {
30143014
goto fail;
30153015
}
3016+
// extra_op_dtype might have been replaced, so get a new reference
3017+
extra_op_dtype = PyArray_DESCR(extra_op);
30163018
}
30173019

30183020
/*

numpy/_core/tests/test_stringdtype.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,18 @@ def test_fancy_indexing(string_list):
518518
assert_array_equal(a, b)
519519
assert a[0] == 'd' * 25
520520

521+
# see gh-29279
522+
data = [
523+
["AAAAAAAAAAAAAAAAA"],
524+
["BBBBBBBBBBBBBBBBBBBBBBBBBBBBB"],
525+
["CCCCCCCCCCCCCCCCC"],
526+
["DDDDDDDDDDDDDDDDD"],
527+
]
528+
sarr = np.array(data, dtype=np.dtypes.StringDType())
529+
uarr = np.array(data, dtype="U30")
530+
for ind in [[0], [1], [2], [3], [[0, 0]], [[1, 1, 3]], [[1, 1]]]:
531+
assert_array_equal(sarr[ind], uarr[ind])
532+
521533

522534
def test_creation_functions():
523535
assert_array_equal(np.zeros(3, dtype="T"), ["", "", ""])

0 commit comments

Comments
 (0)