8000 Pull request #69: Do not steal handle in coercion cache. · hpyproject/numpy-hpy@7dc6242 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7dc6242

Browse files
committed
Pull request numpy#69: Do not steal handle in coercion cache.
Merge in ~STEPAN.SINDELAR_ORACLE.COM/numpy-hpy from fa/final_fixes to labs-hpy-port * commit 'a280ef2dc1d5a15dc74534a65376c0a909a1e8f9': Fix: do not steal handle in coercing cache Reorder array slots to use right impls for magic methods
2 parents 7a07023 + a280ef2 commit 7dc6242

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

numpy/core/src/multiarray/array_coercion.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,8 @@ hnpy_new_coercion_cache(HPyContext *ctx,
704704
PyErr_NoMemory();
705705
return -1;
706706
}
707-
cache->converted_obj = converted_obj;
708-
cache->arr_or_sequence = arr_or_sequence;
707+
cache->converted_obj = HPy_Dup(ctx, converted_obj);
708+
cache->arr_or_sequence = HPy_Dup(ctx, arr_or_sequence);
709709
cache->sequence = sequence;
710710
cache->depth = ndim;
711711
cache->next = NULL;
@@ -727,7 +727,10 @@ npy_new_coercion_cache(
727727
Py_XDECREF(converted_obj); /* the object is stolen */
728728
HPy h_arr_or_sequence = HPy_FromPyObject(ctx, arr_or_sequence);
729729
Py_XDECREF(arr_or_sequence); /* the object is stolen */
730-
return hnpy_new_coercion_cache(ctx, h_converted_obj, h_arr_or_sequence, sequence, next_ptr, ndim);
730+
int res = hnpy_new_coercion_cache(ctx, h_converted_obj, h_arr_or_sequence, sequence, next_ptr, ndim);
731+
HPy_Close(ctx, h_converted_obj);
732+
HPy_Close(ctx, h_arr_or_sequence);
733+
return res;
731734
}
732735

733736
/**

numpy/core/src/multiarray/arrayobject.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,11 +2074,12 @@ static PyType_Slot PyArray_Type_slots[] = {
20742074
};
20752075

20762076
static HPyDef *array_defines[] = {
2077-
&array_length,
2078-
&mp_array_length,
2079-
&array_getbuffer,
20802077
&array_assign_subscript,
20812078
&array_subscript,
2079+
&mp_array_length,
2080+
2081+
&array_getbuffer,
2082+
&array_length,
20822083
&array_item,
20832084
&array_new,
20842085
&array_traverse,

0 commit comments

Comments
 (0)
0