8000 API: Make new `resolve_dtypes_with_pyscalars` private for now · numpy/numpy@cdbea5e · GitHub
[go: up one dir, main page]

Skip to content

Commit cdbea5e

Browse files
committed
API: Make new resolve_dtypes_with_pyscalars private for now
Makign private by raising an error. Maybe a bit odd, but OTOH, it does advertise that we can make it public quite easily if we want to.
1 parent df219d0 commit cdbea5e

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

numpy/_core/src/multiarray/array_method.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,13 @@ fill_arraymethod_from_slots(
256256
for (PyType_Slot *slot = &spec->slots[0]; slot->slot != 0; slot++) {
257257
switch (slot->slot) {
258258
case NPY_METH_resolve_descriptors_with_scalars:
259+
if (!private) {
260+
PyErr_SetString(PyExc_RuntimeError,
261+
"the NPY_METH_resolve_descriptors_with_scalars "
262+
"slot private due to uncertainty about the right "
263+
"signature (see gh-24915)");
264+
return -1;
265+
}
259266
meth->resolve_descriptors_with_scalars = slot->pfunc;
260267
continue;
261268
case NPY_METH_resolve_descriptors:
@@ -269,7 +276,6 @@ fill_arraymethod_from_slots(
269276
* (as in: we should not worry about changing it, but of
270277
* course that would not break it immediately.)
271278
*/
272-
/* Only allow override for private functions initially */
273279
meth->get_strided_loop = slot->pfunc;
274280
continue;
275281
/* "Typical" loops, supported used by the default `get_loop` */

numpy/_core/src/umath/dispatching.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,21 @@ PyUFunc_AddLoop(PyUFuncObject *ufunc, PyObject *info, int ignore_duplicate)
152152
*/
153153
NPY_NO_EXPORT int
154154
PyUFunc_AddLoopFromSpec(PyObject *ufunc, PyArrayMethod_Spec *spec)
155+
{
156+
return PyUFunc_AddLoopFromSpec_int(ufunc, spec, 0);
157+
}
158+
159+
160+
NPY_NO_EXPORT int
161+
PyUFunc_AddLoopFromSpec_int(PyObject *ufunc, PyArrayMethod_Spec *spec, int priv)
155162
{
156163
if (!PyObject_TypeCheck(ufunc, &PyUFunc_Type)) {
157164
PyErr_SetString(PyExc_TypeError,
158165
"ufunc object passed is not a ufunc!");
159166
return -1;
160167
}
161168
PyBoundArrayMethodObject *bmeth =
162-
(PyBoundArrayMethodObject *)PyArrayMethod_FromSpec(spec);
169+
(PyBoundArrayMethodObject *)PyArrayMethod_FromSpec_int(spec, priv);
163170
if (bmeth == NULL) {
164171
return -1;
165172
}

numpy/_core/src/umath/dispatching.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ PyUFunc_AddLoop(PyUFuncObject *ufunc, PyObject *info, int ignore_duplicate);
2020
NPY_NO_EXPORT int
2121
PyUFunc_AddLoopFromSpec(PyObject *ufunc, PyArrayMethod_Spec *spec);
2222

23+
NPY_NO_EXPORT int
24+
PyUFunc_AddLoopFromSpec_int(PyObject *ufunc, PyArrayMethod_Spec *spec, int priv);
25+
2326
NPY_NO_EXPORT PyArrayMethodObject *
2427
promote_and_get_ufuncimpl(PyUFuncObject *ufunc,
2528
PyArrayObject *const ops[],

numpy/_core/src/umath/special_integer_comparisons.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,14 @@ add_dtype_loops(PyObject *umath, PyArrayMethod_Spec *spec, PyObject *info)
356356
/* Register the spec/loop for both forward and backward direction */
357357
spec->dtypes[0] = Int;
358358
spec->dtypes[1] = PyInt;
359-
int res = PyUFunc_AddLoopFromSpec((PyObject *)ufunc, spec);
359+
int res = PyUFunc_AddLoopFromSpec_int((PyObject *)ufunc, spec, 1);
360360
if (res < 0) {
361361
Py_DECREF(Int);
362362
goto fail;
363363
}
364364
spec->dtypes[0] = PyInt;
365365
spec->dtypes[1] = Int;
366-
res = PyUFunc_AddLoopFromSpec((PyObject *)ufunc, spec);
366+
res = PyUFunc_AddLoopFromSpec_int((PyObject *)ufunc, spec, 1);
367367
Py_DECREF(Int);
368368
if (res < 0) {
369369
goto fail;

0 commit comments

Comments
 (0)
0