Exemplo n.º 1
0
static PyObject *Nuitka_Method_tp_richcompare( struct Nuitka_MethodObject *a, struct Nuitka_MethodObject *b, int op )
{
    if ( op != Py_EQ && op != Py_NE )
    {
        return INCREASE_REFCOUNT( Py_NotImplemented );
    }


    if ( Nuitka_Method_Check( (PyObject *)a ) == false || Nuitka_Method_Check( (PyObject *)b ) == false )
    {
        return INCREASE_REFCOUNT( Py_NotImplemented );
    }

    bool result = a->m_function->m_counter == b->m_function->m_counter;

    // If the underlying function objects are the same, check the objects, which
    // may be NULL in case of unbound methods, which would be the same again.
    if ( result )
    {
        if ( a->m_object == NULL )
        {
            result = b->m_object == NULL;
        }
        else if ( b->m_object == NULL )
        {
            result = 0;
        }
        else
        {
            int res = PyObject_RichCompareBool(
                a->m_object,
                b->m_object,
                Py_EQ
            );

            result = res != 0;
        }
    }

    if ( op == Py_EQ )
    {
        return INCREASE_REFCOUNT( BOOL_FROM( result ) );
    }
    else
    {
        return INCREASE_REFCOUNT( BOOL_FROM( !result ) );
    }
}
Exemplo n.º 2
0
NUITKA_MAY_BE_UNUSED static PyObject *TO_BOOL( PyObject *value )
{
    int res = CHECK_IF_TRUE( value );

    if (unlikely( res == -1 )) return NULL;
    return BOOL_FROM( res != 0 );
}