File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
numpy/_core/src/multiarray/stringdtype Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -633,11 +633,16 @@ PyArray_Descr *
633
633
stringdtype_finalize_descr (PyArray_Descr * dtype )
634
634
{
635
635
PyArray_StringDTypeObject * sdtype = (PyArray_StringDTypeObject * )dtype ;
636
+ // acquire the allocator lock in case the descriptor we want to finalize
637
+ // is shared between threads, see gh-28813
638
+ npy_string_allocator * allocator = NpyString_acquire_allocator (sdtype );
636
639
if (sdtype -> array_owned == 0 ) {
637
640
sdtype -> array_owned = 1 ;
641
+ NpyString_release_allocator (allocator );
638
642
Py_INCREF (dtype );
639
643
return dtype ;
640
644
}
645
+ NpyString_release_allocator (allocator );
641
646
PyArray_StringDTypeObject * ret = (PyArray_StringDTypeObject * )new_stringdtype_instance (
642
647
sdtype -> na_object , sdtype -> coerce );
643
648
ret -> array_owned = 1 ;
@@ -852,14 +857,17 @@ init_string_dtype(void)
852
857
return -1 ;
853
858
}
854
859
855
- PyArray_Descr * singleton =
856
- NPY_DT_CALL_default_descr (& PyArray_StringDType );
860
+ PyArray_StringDTypeObject * singleton =
861
+ ( PyArray_StringDTypeObject * ) NPY_DT_CALL_default_descr (& PyArray_StringDType );
857
862
858
863
if (singleton == NULL ) {
859
864
return -1 ;
860
865
}
861
866
862
- PyArray_StringDType .singleton = singleton ;
867
+ // never associate the singleton with an array
868
+ singleton -> array_owned = 1 ;
869
+
870
+ PyArray_StringDType .singleton = (PyArray_Descr * )singleton ;
863
871
PyArray_StringDType .type_num = NPY_VSTRING ;
864
872
865
873
for (int i = 0 ; PyArray_StringDType_casts [i ] != NULL ; i ++ ) {
You can’t perform that action at this time.
0 commit comments