Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd9333fa

Browse files
committed
FIX: GIL status
1 parenta6dc86a commitd9333fa

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

‎numpy/_core/src/multiarray/unique.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ unique_vstring(PyArrayObject *self, bool equal_nan)
206206
PyArray_Descr *descr =PyArray_DESCR(self);
207207
// NumPy API calls and Python object manipulations require holding the GIL.
208208
Py_INCREF(descr);
209+
210+
// variables for the vstring, this operation require holding the GIL.
211+
npy_string_allocator *in_allocator =NpyString_acquire_allocator((PyArray_StringDTypeObject *)descr);
209212
NPY_DISABLE_C_API;
210213

211214
// release the GIL
@@ -214,11 +217,6 @@ unique_vstring(PyArrayObject *self, bool equal_nan)
214217
// number of elements in the input array
215218
npy_intp isize =PyArray_SIZE(self);
216219

217-
// variables for the vstring
218-
npy_string_allocator *in_allocator =NpyString_acquire_allocator((PyArray_StringDTypeObject *)descr);
219-
auto in_allocator_dealloc =finally([&]() {
220-
NpyString_release_allocator(in_allocator);
221-
});
222220
auto hash = [equal_nan](const npy_static_string *value) ->size_t {
223221
if (value->buf ==NULL) {
224222
if (equal_nan) {
@@ -298,19 +296,13 @@ unique_vstring(PyArrayObject *self, bool equal_nan)
298296
// NumPy API calls and Python object manipulations require holding the GIL.
299297
Py_INCREF(res_descr);
300298
std::cerr <<"res_descr incremented successfully." << std::endl;
299+
npy_string_allocator *out_allocator =NpyString_acquire_allocator((PyArray_StringDTypeObject *)res_descr);
301300
NPY_DISABLE_C_API;
302301
PyThreadState *_save2 =PyEval_SaveThread();
303302
std::cerr <<"save2:" << (void*)_save2 << std::endl;
304-
auto save2_dealloc =finally([&]() {
305-
PyEval_RestoreThread(_save2);
306-
});
307303
std::cerr <<"save2_dealloc completed successfully." << std::endl;
308304

309-
npy_string_allocator *out_allocator =NpyString_acquire_allocator((PyArray_StringDTypeObject *)res_descr);
310305
std::cerr <<"out_allocator:" << (void*)out_allocator << std::endl;
311-
auto out_allocator_dealloc =finally([&]() {
312-
NpyString_release_allocator(out_allocator);
313-
});
314306
std::cerr <<"out_allocator_dealloc completed successfully." << std::endl;
315307

316308
char *odata =PyArray_BYTES((PyArrayObject *)res_obj);
@@ -332,6 +324,12 @@ unique_vstring(PyArrayObject *self, bool equal_nan)
332324
}
333325
}
334326
std::cerr <<"Packing loop completed successfully." << std::endl;
327+
PyEval_RestoreThread(_save2);
328+
NPY_ALLOW_C_API;
329+
// these operations require holding the GIL
330+
NpyString_release_allocator(in_allocator);
331+
NpyString_release_allocator(out_allocator);
332+
NPY_DISABLE_C_API;
335333

336334
return res_obj;
337335
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp