@@ -317,13 +317,16 @@ addUfuncs(PyObject *dictionary) {
317
317
static PyObject *
318
318
UMath_Tests_test_signature (PyObject * NPY_UNUSED (dummy ), PyObject * args )
319
319
{
320
- int nin , nout ;
320
+ int nin , nout , i ;
321
321
PyObject * signature , * sig_str ;
322
- PyObject * f ;
322
+ PyUFuncObject * f = NULL ;
323
+ PyObject * core_num_dims = NULL , * core_dim_ixs = NULL ;
323
324
int core_enabled ;
325
+ int core_num_ixs = 0 ;
324
326
325
- if (!PyArg_ParseTuple (args , "iiO" , & nin , & nout , & signature )) return NULL ;
326
-
327
+ if (!PyArg_ParseTuple (args , "iiO" , & nin , & nout , & signature )) {
328
+ return NULL ;
329
+ }
327
330
328
331
if (PyString_Check (signature )) {
329
332
sig_str = signature ;
@@ -334,17 +337,60 @@ UMath_Tests_test_signature(PyObject *NPY_UNUSED(dummy), PyObject *args)
334
337
return NULL ;
335
338
}
336
339
337
- f = PyUFunc_FromFuncAndDataAndSignature (NULL , NULL , NULL ,
340
+ f = (PyUFuncObject * )PyUFunc_FromFuncAndDataAndSignature (
341
+ NULL , NULL , NULL ,
338
342
0 , nin , nout , PyUFunc_None , "no name" ,
339
343
"doc:none" ,
340
344
1 , PyString_AS_STRING (sig_str ));
341
345
if (sig_str != signature ) {
342
346
Py_DECREF (sig_str );
343
347
}
344
- if (f == NULL ) return NULL ;
345
- core_enabled = ((PyUFuncObject * )f )-> core_enabled ;
348
+ if (f == NULL ) {
349
+ return NULL ;
350
+ }
351
+ core_enabled = f -> core_enabled ;
352
+ /*
353
+ * Don't presume core_num_dims and core_dim_ixs are defined;
354
+ * they currently are even if core_enabled=0, but there's no real
355
+ * reason they should be. So avoid segfaults if we change our mind.
356
+ */
357
+ if (f -> core_num_dims != NULL ) {
358
+ core_num_dims = PyTuple_New (f -> nargs );
359
+ if (core_num_dims == NULL ) {
360
+ goto fail ;
361
+ }
362
+ for (i = 0 ; i < f -> nargs ; i ++ ) {
363
+ PyObject * val = PyLong_FromLong (f -> core_num_dims [i ]);
364
+ PyTuple_SET_ITEM (core_num_dims , i , val );
365
+ core_num_ixs += f -> core_num_dims [i ];
366
+ }
367
+ }
368
+ else {
369
+ Py_INCREF (Py_None );
370
+ core_num_dims = Py_None ;
371
+ }
372
+ if (f -> core_dim_ixs != NULL ) {
373
+ core_dim_ixs = PyTuple_New (core_num_ixs );
374
+ if (core_num_dims == NULL ) {
375
+ goto fail ;
376
+ }
377
+ for (i = 0 ; i < core_num_ixs ; i ++ ) {
378
+ PyObject * val = PyLong_FromLong (f -> core_dim_ixs [i ]);
379
+ PyTuple_SET_ITEM (core_dim_ixs , i , val );
380
+ }
381
+ }
382
+ else {
383
+ Py_INCREF (Py_None );
384
+ core_dim_ixs = Py_None ;
385
+ }
346
386
Py_DECREF (f );
347
- return Py_BuildValue ("i" , core_enabled );
387
+ return Py_BuildValue ("iOO" , core_enabled , core_num_dims , core_dim_ixs );
388
+
389
+ fail :
390
+ Py_XDECREF (f );
391
+ Py_XDECREF (core_num_dims );
392
+ Py_XDECREF (core_dim_ixs );
393
+ return NULL ;
348
394
}
349
395
350
396
static PyMethodDef UMath_TestsMethods [] = {
0 commit comments