@@ -306,9 +306,7 @@ static struct _ufunc_dispatch {
306306 PyCFunctionWithKeywords ufunc_accumulate ;
307307 PyCFunctionWithKeywords ufunc_reduceat ;
308308 PyCFunctionWithKeywords ufunc_outer ;
309- #if NPY_API_VERSION >= 0x00000008
310309 PyCFunction ufunc_at ;
311- #endif
312310} ufunc_dispatch ;
313311
314312static int
@@ -324,10 +322,8 @@ init_ufunc_dispatch(int *numpy_uses_fastcall)
324322 if (strncmp (crnt_name , "accumulate" , 11 ) == 0 ) {
325323 ufunc_dispatch .ufunc_accumulate =
326324 (PyCFunctionWithKeywords )crnt -> ml_meth ;
327- #if NPY_API_VERSION >= 0x00000008
328325 } else if (strncmp (crnt_name , "at" , 3 ) == 0 ) {
329326 ufunc_dispatch .ufunc_at = crnt -> ml_meth ;
330- #endif
331327 } else {
332328 result = -1 ;
333329 }
@@ -347,10 +343,15 @@ init_ufunc_dispatch(int *numpy_uses_fastcall)
347343 } else if (strncmp (crnt_name , "reduceat" , 9 ) == 0 ) {
348344 ufunc_dispatch .ufunc_reduceat =
349345 (PyCFunctionWithKeywords )crnt -> ml_meth ;
346+ } else if (strncmp (crnt_name , "resolve_dtypes" , 15 ) == 0 ) {
347+ /* Ignored */
350348 } else {
351349 result = -1 ;
352350 }
353351 break ;
352+ case '_' :
353+ // We ignore private methods
354+ break ;
354355 default :
355356 result = -1 ; /* Unknown method */
356357 }
@@ -362,6 +363,9 @@ init_ufunc_dispatch(int *numpy_uses_fastcall)
362363 * numpy_uses_fastcall = crnt -> ml_flags & METH_FASTCALL ;
363364 }
364365 else if (* numpy_uses_fastcall != (crnt -> ml_flags & METH_FASTCALL )) {
366+ PyErr_Format (PyExc_RuntimeError ,
367+ "ufunc.%s() flags do not match numpy_uses_fastcall" ,
368+ crnt_name );
365369 return -1 ;
366370 }
367371 }
@@ -372,11 +376,13 @@ init_ufunc_dispatch(int *numpy_uses_fastcall)
372376 && (ufunc_dispatch .ufunc_accumulate != NULL )
373377 && (ufunc_dispatch .ufunc_reduceat != NULL )
374378 && (ufunc_dispatch .ufunc_outer != NULL )
375- #if NPY_API_VERSION >= 0x00000008
376379 && (ufunc_dispatch .ufunc_at != NULL )
377- #endif
378380 );
381+ } else {
382+ char const * const fmt = "Unexpected ufunc method %s()" ;
383+ PyErr_Format (PyExc_RuntimeError , fmt , crnt_name );
379384 }
385+
380386 return result ;
381387}
382388
@@ -446,13 +452,11 @@ dufunc_outer_fast(PyDUFuncObject * self,
446452}
447453
448454
449- #if NPY_API_VERSION >= 0x00000008
450455static PyObject *
451456dufunc_at (PyDUFuncObject * self , PyObject * args )
452457{
453458 return ufunc_dispatch .ufunc_at ((PyObject * )self -> ufunc , args );
454459}
455- #endif
456460
457461static PyObject *
458462dufunc__compile_for_args (PyDUFuncObject * self , PyObject * args ,
@@ -630,11 +634,9 @@ static struct PyMethodDef dufunc_methods[] = {
630634 {"outer" ,
631635 (PyCFunction )dufunc_outer ,
632636 METH_VARARGS | METH_KEYWORDS , NULL },
633- #if NPY_API_VERSION >= 0x00000008
634637 {"at" ,
635638 (PyCFunction )dufunc_at ,
636639 METH_VARARGS , NULL },
637- #endif
638640 {"_compile_for_args" ,
639641 (PyCFunction )dufunc__compile_for_args ,
640642 METH_VARARGS | METH_KEYWORDS ,
@@ -664,11 +666,9 @@ static struct PyMethodDef dufunc_methods_fast[] = {
664666 {"outer" ,
665667 (PyCFunction )dufunc_outer_fast ,
666668 METH_FASTCALL | METH_KEYWORDS , NULL },
667- #if NPY_API_VERSION >= 0x00000008
668669 {"at" ,
669670 (PyCFunction )dufunc_at ,
670671 METH_VARARGS , NULL },
671- #endif
672672 {"_compile_for_args" ,
673673 (PyCFunction )dufunc__compile_for_args ,
674674 METH_VARARGS | METH_KEYWORDS ,
@@ -837,9 +837,7 @@ MOD_INIT(_internal)
837837 if (PyModule_AddIntMacro (m , PyUFunc_One )
838838 || PyModule_AddIntMacro (m , PyUFunc_Zero )
839839 || PyModule_AddIntMacro (m , PyUFunc_None )
840- #if NPY_API_VERSION >= 0x00000007
841840 || PyModule_AddIntMacro (m , PyUFunc_ReorderableNone )
842- #endif
843841 )
844842 return MOD_ERROR_VAL ;
845843
0 commit comments