@@ -296,8 +296,7 @@ quad_ldexp_resolve_descriptors(PyObject *self, PyArray_DTypeMeta *const dtypes[]
296296 Py_INCREF (given_descrs[0 ]);
297297 loop_descrs[0 ] = given_descrs[0 ];
298298
299- // Input 1: Use NPY_INTP (int64 on 64-bit, int32 on 32-bit) to match platform integer size
300- // This ensures we can handle the full range of PyArray_PyLongDType without data loss
299+ // Input 1: Use NPY_INTP to match the registered PyArray_IntpDType
301300 loop_descrs[1 ] = PyArray_DescrFromType (NPY_INTP );
302301
303302 // Output: QuadPrecDType with same backend as input
@@ -408,7 +407,7 @@ create_quad_ldexp_ufunc(PyObject *numpy, const char *ufunc_name)
408407 return -1 ;
409408 }
410409
411- PyArray_DTypeMeta *dtypes[3 ] = {&QuadPrecDType, &PyArray_PyLongDType , &QuadPrecDType};
410+ PyArray_DTypeMeta *dtypes[3 ] = {&QuadPrecDType, &PyArray_IntpDType , &QuadPrecDType};
412411
413412 PyType_Slot slots[] = {
414413 {NPY_METH_resolve_descriptors, (void *)&quad_ldexp_resolve_descriptors},
@@ -429,28 +428,33 @@ create_quad_ldexp_ufunc(PyObject *numpy, const char *ufunc_name)
429428 };
430429
431430 if (PyUFunc_AddLoopFromSpec (ufunc, &Spec) < 0 ) {
431+ Py_DECREF (ufunc);
432432 return -1 ;
433433 }
434434
435435 PyObject *promoter_capsule =
436- PyCapsule_New ((void *)&quad_ufunc_promoter , " numpy._ufunc_promoter" , NULL );
436+ PyCapsule_New ((void *)&quad_ldexp_promoter , " numpy._ufunc_promoter" , NULL );
437437 if (promoter_capsule == NULL ) {
438+ Py_DECREF (ufunc);
438439 return -1 ;
439440 }
440441
441- PyObject *DTypes = PyTuple_Pack (3 , &PyArrayDescr_Type , &PyArray_PyLongDType , &PyArrayDescr_Type);
442+ PyObject *DTypes = PyTuple_Pack (3 , &QuadPrecDType , &PyArrayDescr_Type , &PyArrayDescr_Type);
442443 if (DTypes == 0 ) {
443444 Py_DECREF (promoter_capsule);
445+ Py_DECREF (ufunc);
444446 return -1 ;
445447 }
446448
447449 if (PyUFunc_AddPromoter (ufunc, DTypes, promoter_capsule) < 0 ) {
448450 Py_DECREF (promoter_capsule);
449451 Py_DECREF (DTypes);
452+ Py_DECREF (ufunc);
450453 return -1 ;
451454 }
452455 Py_DECREF (promoter_capsule);
453456 Py_DECREF (DTypes);
457+ Py_DECREF (ufunc);
454458 return 0 ;
455459}
456460
@@ -486,29 +490,52 @@ create_quad_binary_2out_ufunc(PyObject *numpy, const char *ufunc_name)
486490 };
487491
488492 if (PyUFunc_AddLoopFromSpec (ufunc, &Spec) < 0 ) {
493+ Py_DECREF (ufunc);
489494 return -1 ;
490495 }
491496
492497 PyObject *promoter_capsule =
493498 PyCapsule_New ((void *)&quad_ufunc_promoter, " numpy._ufunc_promoter" , NULL );
494499 if (promoter_capsule == NULL ) {
500+ Py_DECREF (ufunc);
495501 return -1 ;
496502 }
497503
498- PyObject *DTypes = PyTuple_Pack (4 , &PyArrayDescr_Type, &PyArrayDescr_Type,
504+ // Register promoter for (QuadPrecDType, Any, Any, Any)
505+ PyObject *DTypes = PyTuple_Pack (4 , &QuadPrecDType, &PyArrayDescr_Type,
499506 &PyArrayDescr_Type, &PyArrayDescr_Type);
500507 if (DTypes == 0 ) {
501508 Py_DECREF (promoter_capsule);
509+ Py_DECREF (ufunc);
510+ return -1 ;
511+ }
512+
513+ if (PyUFunc_AddPromoter (ufunc, DTypes, promoter_capsule) < 0 ) {
514+ Py_DECREF (promoter_capsule);
515+ Py_DECREF (DTypes);
516+ Py_DECREF (ufunc);
517+ return -1 ;
518+ }
519+ Py_DECREF (DTypes);
520+
521+ // Register promoter for (Any, QuadPrecDType, Any, Any)
522+ DTypes = PyTuple_Pack (4 , &PyArrayDescr_Type, &QuadPrecDType,
523+ &PyArrayDescr_Type, &PyArrayDescr_Type);
524+ if (DTypes == 0 ) {
525+ Py_DECREF (promoter_capsule);
526+ Py_DECREF (ufunc);
502527 return -1 ;
503528 }
504529
505530 if (PyUFunc_AddPromoter (ufunc, DTypes, promoter_capsule) < 0 ) {
506531 Py_DECREF (promoter_capsule);
507532 Py_DECREF (DTypes);
533+ Py_DECREF (ufunc);
508534 return -1 ;
509535 }
510536 Py_DECREF (promoter_capsule);
511537 Py_DECREF (DTypes);
538+ Py_DECREF (ufunc);
512539 return 0 ;
513540}
514541
@@ -542,28 +569,50 @@ create_quad_binary_ufunc(PyObject *numpy, const char *ufunc_name)
542569 };
543570
544571 if (PyUFunc_AddLoopFromSpec (ufunc, &Spec) < 0 ) {
572+ Py_DECREF (ufunc);
545573 return -1 ;
546574 }
547575
548576 PyObject *promoter_capsule =
549577 PyCapsule_New ((void *)&quad_ufunc_promoter, " numpy._ufunc_promoter" , NULL );
550578 if (promoter_capsule == NULL ) {
579+ Py_DECREF (ufunc);
551580 return -1 ;
552581 }
553582
554- PyObject *DTypes = PyTuple_Pack (3 , &PyArrayDescr_Type, &PyArrayDescr_Type, &PyArrayDescr_Type);
583+ // Register promoter for (QuadPrecDType, Any, Any)
584+ PyObject *DTypes = PyTuple_Pack (3 , &QuadPrecDType, &PyArrayDescr_Type, &PyArrayDescr_Type);
585+ if (DTypes == 0 ) {
586+ Py_DECREF (promoter_capsule);
587+ Py_DECREF (ufunc);
588+ return -1 ;
589+ }
590+
591+ if (PyUFunc_AddPromoter (ufunc, DTypes, promoter_capsule) < 0 ) {
592+ Py_DECREF (promoter_capsule);
593+ Py_DECREF (DTypes);
594+ Py_DECREF (ufunc);
595+ return -1 ;
596+ }
597+ Py_DECREF (DTypes);
598+
599+ // Register promoter for (Any, QuadPrecDType, Any)
600+ DTypes = PyTuple_Pack (3 , &PyArrayDescr_Type, &QuadPrecDType, &PyArrayDescr_Type);
555601 if (DTypes == 0 ) {
556602 Py_DECREF (promoter_capsule);
603+ Py_DECREF (ufunc);
557604 return -1 ;
558605 }
559606
560607 if (PyUFunc_AddPromoter (ufunc, DTypes, promoter_capsule) < 0 ) {
561608 Py_DECREF (promoter_capsule);
562609 Py_DECREF (DTypes);
610+ Py_DECREF (ufunc);
563611 return -1 ;
564612 }
565613 Py_DECREF (promoter_capsule);
566614 Py_DECREF (DTypes);
615+ Py_DECREF (ufunc);
567616 return 0 ;
568617}
569618
0 commit comments