src/oputil.c
/**
 * I thought it better to make the function call a bit more complex, so as to
 * have the iteration logic unified in a single place
 */
I thought it better to make the function call a bit more complex, so as to
have the iteration logic unified in a single place
I thought it better to make the function call a bit more complex so as to have the iteration logic unified in a single place
int
pycbc_oputil_sequence_next(pycbc_seqtype_t seqtype,
                           PyObject *seqobj,
                           Py_ssize_t *dictpos,
                           int ii,
                           PyObject **key,
                           PyObject **value,
                           pycbc_stack_context_handle context )
{
    if (seqtype & PYCBC_SEQTYPE_DICT) {
        int rv = PyDict_Next(seqobj, dictpos, key, value);
        if (rv < 1) {
            PYCBC_EXC_WRAP_OBJ(PYCBC_EXC_INTERNAL,
                               0, "Couldn't iterate", seqobj);
            return -1;
        }
        Py_XINCREF(*key);
        Py_XINCREF(*value);
        return 0;
    }
    *value = NULL;
    if (seqtype & PYCBC_SEQTYPE_LIST) {
        *key = PyList_GET_ITEM(seqobj, ii);
        Py_INCREF(*key);
    } else if (seqtype & PYCBC_SEQTYPE_TUPLE) {
        *key = PyTuple_GET_ITEM(seqobj, ii);
        Py_INCREF(*key);
    } else {
        *key = PyIter_Next(seqobj);
        if (!*key) {
            PYCBC_EXC_WRAP_OBJ(PYCBC_EXC_ARGUMENTS, 0,
                               "PyIter_Next returned NULL", seqobj);
            return -1;
        }
    }
    return 0;
}
int pycbc_oputil_sequence_next ( pycbc_seqtype_t seqtype , PyObject * seqobj , Py_ssize_t * dictpos , int ii , PyObject * * key , PyObject * * value , pycbc_stack_context_handle context ) { if ( seqtype & PYCBC_SEQTYPE_DICT ) { int rv = PyDict_Next ( seqobj , dictpos , key , value ) ; if ( rv < 1 ) { PYCBC_EXC_WRAP_OBJ ( PYCBC_EXC_INTERNAL , 0 , " " , seqobj ) ; return -1 ; } Py_XINCREF ( * key ) ; Py_XINCREF ( * value ) ; return 0 ; } * value = NULL ; if ( seqtype & PYCBC_SEQTYPE_LIST ) { * key = PyList_GET_ITEM ( seqobj , ii ) ; Py_INCREF ( * key ) ; } else if ( seqtype & PYCBC_SEQTYPE_TUPLE ) { * key = PyTuple_GET_ITEM ( seqobj , ii ) ; Py_INCREF ( * key ) ; } else { * key = PyIter_Next ( seqobj ) ; if ( ! * key ) { PYCBC_EXC_WRAP_OBJ ( PYCBC_EXC_ARGUMENTS , 0 , " " , seqobj ) ; return -1 ; } } return 0 ; }
I thought it better to make the function call a bit more complex, so as to
 have the iteration logic unified in a single place
I thought it better to make the function call a bit more complex so as to have the iteration logic unified in a single place