Repository: numpy/numpy
File: numpy/_core/src/umath/ufunc_object.c (C)

Code before:
    char *in = (char *)&cin, *out = (char *)&cout;
    char *data[] = {in, out};
    int ret = -2;
    PyArray_Descr *dt;
    /*
     * For supported input, get input pointer and descriptor. Otherwise, bail.
     */
    if (obj == Py_False || obj == Py_True) {
        *(npy_bool *)in = (obj == Py_True);
        dt = PyArray_DescrFromType(NPY_BOOL);
    }
    else if (PyFloat_CheckExact(obj)) {
        *(double *)in = PyFloat_AS_DOUBLE(obj);
        dt = PyArray_DescrFromType(NPY_FLOAT64);
    }
    else if (PyLong_CheckExact(obj)) {
        int overflow;
        long val = PyLong_AsLongAndOverflow(obj, &overflow);
        if (overflow) {
            return -2;  // bail, main code perhaps deals with this.
        }
        if (error_converting(val)) {
            return -1;  // should never happen; pass on it if does.
        }
        *(npy_int64 *)in = (npy_int64)val;
        dt = PyArray_DescrFromType(NPY_INT64);
    }
    else if (PyComplex_CheckExact(obj)) {
        Py_complex oop = PyComplex_AsCComplex(obj);
        if (error_converting(oop.real)) {
            return -1;  // should never happen; pass on it if does.
        }
        *(double *)in = oop.real;
        *(double *)(in+sizeof(double)) = oop.imag;
        dt = PyArray_DescrFromType(NPY_COMPLEX128);
    }
    else if (is_anyscalar_exact(obj)) {
        dt = PyArray_DescrFromScalar(obj);
        if (!PyDataType_ISNUMBER(dt)) {
            goto bail;
        }
        data[0] = scalar_value(obj, dt);
    }
    else {
        return -2;
    }
    /*
     * Check the ufunc supports our descriptor, bailing (return -2) if not.
     */
    // Try getting info from the (private) cache.  Fall back if not found,
    // so that the the dtype gets registered and things will work next time.

Review comment (suggestion):
This needs to be `INTP` (I think we also have DEFAULT_INT maybe if you prefer). Fortunately, we can assume `INTP >= LONG` though, I think.

(Interesting that the tests didn't notice...)

Code after:
    char *in = (char *)&cin, *out = (char *)&cout;
    char *data[] = {in, out};
    int ret = -2;
    PyArray_Descr *dt;
    /*
     * For supported input, get input pointer and descriptor. Otherwise, bail.
     */
    if (obj == Py_False || obj == Py_True) {
        *(npy_bool *)in = (obj == Py_True);
        dt = PyArray_DescrFromType(NPY_BOOL);
    }
    else if (PyFloat_CheckExact(obj)) {
        *(double *)in = PyFloat_AS_DOUBLE(obj);
        dt = PyArray_DescrFromType(NPY_FLOAT64);
    }
    else if (PyLong_CheckExact(obj)) {
        int overflow;
        npy_intp val = PyLong_AsLongAndOverflow(obj, &overflow);
        if (overflow) {
            return -2;  // bail, main code perhaps deals with this.
        }
        if (error_converting(val)) {
            return -1;  // should never happen; pass on it if does.
        }
        *(npy_intp *)in = val;
        dt = PyArray_DescrFromType(NPY_INTP);
    }
    else if (PyComplex_CheckExact(obj)) {
        Py_complex oop = PyComplex_AsCComplex(obj);
        if (error_converting(oop.real)) {
            return -1;  // should never happen; pass on it if does.
        }
        *(double *)in = oop.real;
        *(double *)(in+sizeof(double)) = oop.imag;
        dt = PyArray_DescrFromType(NPY_COMPLEX128);
    }
    else if (is_anyscalar_exact(obj)) {
        dt = PyArray_DescrFromScalar(obj);
        if (!PyDataType_ISNUMBER(dt)) {
            goto bail;
        }
        data[0] = scalar_value(obj, dt);
    }
    else {
        return -2;
    }
    /*
     * Check the ufunc supports our descriptor, bailing (return -2) if not.
     */
    // Try getting info from the (private) cache.  Fall back if not found,
    // so that the the dtype gets registered and things will work next time.