@@ -428,28 +428,33 @@ create_quad_ldexp_ufunc(PyObject *numpy, const char *ufunc_name)
428428 };
429429
430430 if (PyUFunc_AddLoopFromSpec (ufunc, &Spec) < 0 ) {
431+ Py_DECREF (ufunc);
431432 return -1 ;
432433 }
433434
434435 PyObject *promoter_capsule =
435436 PyCapsule_New ((void *)&quad_ldexp_promoter, " numpy._ufunc_promoter" , NULL );
436437 if (promoter_capsule == NULL ) {
438+ Py_DECREF (ufunc);
437439 return -1 ;
438440 }
439441
440442 PyObject *DTypes = PyTuple_Pack (3 , &QuadPrecDType, &PyArrayDescr_Type, &PyArrayDescr_Type);
441443 if (DTypes == 0 ) {
442444 Py_DECREF (promoter_capsule);
445+ Py_DECREF (ufunc);
443446 return -1 ;
444447 }
445448
446449 if (PyUFunc_AddPromoter (ufunc, DTypes, promoter_capsule) < 0 ) {
447450 Py_DECREF (promoter_capsule);
448451 Py_DECREF (DTypes);
452+ Py_DECREF (ufunc);
449453 return -1 ;
450454 }
451455 Py_DECREF (promoter_capsule);
452456 Py_DECREF (DTypes);
457+ Py_DECREF (ufunc);
453458 return 0 ;
454459}
455460
@@ -485,12 +490,14 @@ create_quad_binary_2out_ufunc(PyObject *numpy, const char *ufunc_name)
485490 };
486491
487492 if (PyUFunc_AddLoopFromSpec (ufunc, &Spec) < 0 ) {
493+ Py_DECREF (ufunc);
488494 return -1 ;
489495 }
490496
491497 PyObject *promoter_capsule =
492498 PyCapsule_New ((void *)&quad_ufunc_promoter, " numpy._ufunc_promoter" , NULL );
493499 if (promoter_capsule == NULL ) {
500+ Py_DECREF (ufunc);
494501 return -1 ;
495502 }
496503
@@ -499,12 +506,14 @@ create_quad_binary_2out_ufunc(PyObject *numpy, const char *ufunc_name)
499506 &PyArrayDescr_Type, &PyArrayDescr_Type);
500507 if (DTypes == 0 ) {
501508 Py_DECREF (promoter_capsule);
509+ Py_DECREF (ufunc);
502510 return -1 ;
503511 }
504512
505513 if (PyUFunc_AddPromoter (ufunc, DTypes, promoter_capsule) < 0 ) {
506514 Py_DECREF (promoter_capsule);
507515 Py_DECREF (DTypes);
516+ Py_DECREF (ufunc);
508517 return -1 ;
509518 }
510519 Py_DECREF (DTypes);
@@ -514,16 +523,19 @@ create_quad_binary_2out_ufunc(PyObject *numpy, const char *ufunc_name)
514523 &PyArrayDescr_Type, &PyArrayDescr_Type);
515524 if (DTypes == 0 ) {
516525 Py_DECREF (promoter_capsule);
526+ Py_DECREF (ufunc);
517527 return -1 ;
518528 }
519529
520530 if (PyUFunc_AddPromoter (ufunc, DTypes, promoter_capsule) < 0 ) {
521531 Py_DECREF (promoter_capsule);
522532 Py_DECREF (DTypes);
533+ Py_DECREF (ufunc);
523534 return -1 ;
524535 }
525536 Py_DECREF (promoter_capsule);
526537 Py_DECREF (DTypes);
538+ Py_DECREF (ufunc);
527539 return 0 ;
528540}
529541
@@ -557,25 +569,29 @@ create_quad_binary_ufunc(PyObject *numpy, const char *ufunc_name)
557569 };
558570
559571 if (PyUFunc_AddLoopFromSpec (ufunc, &Spec) < 0 ) {
572+ Py_DECREF (ufunc);
560573 return -1 ;
561574 }
562575
563576 PyObject *promoter_capsule =
564577 PyCapsule_New ((void *)&quad_ufunc_promoter, " numpy._ufunc_promoter" , NULL );
565578 if (promoter_capsule == NULL ) {
579+ Py_DECREF (ufunc);
566580 return -1 ;
567581 }
568582
569583 // Register promoter for (QuadPrecDType, Any, Any)
570584 PyObject *DTypes = PyTuple_Pack (3 , &QuadPrecDType, &PyArrayDescr_Type, &PyArrayDescr_Type);
571585 if (DTypes == 0 ) {
572586 Py_DECREF (promoter_capsule);
587+ Py_DECREF (ufunc);
573588 return -1 ;
574589 }
575590
576591 if (PyUFunc_AddPromoter (ufunc, DTypes, promoter_capsule) < 0 ) {
577592 Py_DECREF (promoter_capsule);
578593 Py_DECREF (DTypes);
594+ Py_DECREF (ufunc);
579595 return -1 ;
580596 }
581597 Py_DECREF (DTypes);
@@ -584,16 +600,19 @@ create_quad_binary_ufunc(PyObject *numpy, const char *ufunc_name)
584600 DTypes = PyTuple_Pack (3 , &PyArrayDescr_Type, &QuadPrecDType, &PyArrayDescr_Type);
585601 if (DTypes == 0 ) {
586602 Py_DECREF (promoter_capsule);
603+ Py_DECREF (ufunc);
587604 return -1 ;
588605 }
589606
590607 if (PyUFunc_AddPromoter (ufunc, DTypes, promoter_capsule) < 0 ) {
591608 Py_DECREF (promoter_capsule);
592609 Py_DECREF (DTypes);
610+ Py_DECREF (ufunc);
593611 return -1 ;
594612 }
595613 Py_DECREF (promoter_capsule);
596614 Py_DECREF (DTypes);
615+ Py_DECREF (ufunc);
597616 return 0 ;
598617}
599618
0 commit comments