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 ) ); } }
static PyObject *Nuitka_Method_deepcopy( struct Nuitka_MethodObject *method, PyObject *memo ) { assert( Nuitka_Method_Check( (PyObject *)method )); static PyObject *module_copy = NULL; static PyObject *deepcopy_function = NULL; if ( module_copy == NULL ) { module_copy = PyImport_ImportModule( "copy" ); CHECK_OBJECT( module_copy ); deepcopy_function = PyObject_GetAttrString( module_copy, "deepcopy" ); CHECK_OBJECT( deepcopy_function ); } PyObject *object = PyObject_CallFunctionObjArgs( deepcopy_function, method->m_object, memo, NULL ); if (unlikely( object == NULL )) { return NULL; } return Nuitka_Method_New( method->m_function, object, method->m_class ); }
PyObject *CALL_FUNCTION_WITH_ARGS9( PyObject *called, PyObject *arg1, PyObject *arg2, PyObject *arg3, PyObject *arg4, PyObject *arg5, PyObject *arg6, PyObject *arg7, PyObject *arg8, PyObject *arg9 ) { assertObject( called ); // Check if arguments are valid objects in debug mode. #ifndef __NUITKA_NO_ASSERT__ PyObject *args_for_test[] = { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }; for( size_t i = 0; i < sizeof( args_for_test ) / sizeof( PyObject * ); i++ ) { assertObject( args_for_test[ i ] ); } #endif if ( Nuitka_Function_Check( called ) ) { if (unlikely( Py_EnterRecursiveCall( (char *)" while calling a Python object" ) )) { return NULL; } Nuitka_FunctionObject *function = (Nuitka_FunctionObject *)called; PyObject *result; PyObject *args[] = { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }; if ( function->m_direct_arg_parser ) { result = function->m_direct_arg_parser( function, args, sizeof( args ) / sizeof( PyObject * ) ); } else { result = function->m_code( function, args, sizeof( args ) / sizeof( PyObject * ), NULL ); } Py_LeaveRecursiveCall(); return result; } else if ( Nuitka_Method_Check( called ) ) { Nuitka_MethodObject *method = (Nuitka_MethodObject *)called; // Unbound method without arguments, let the error path be slow. if ( method->m_object != NULL ) { if (unlikely( Py_EnterRecursiveCall( (char *)" while calling a Python object" ) )) { return NULL; } PyObject *args[] = { method->m_object, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }; PyObject *result; if ( method->m_function->m_direct_arg_parser ) { result = method->m_function->m_direct_arg_parser( method->m_function, args, sizeof( args ) / sizeof( PyObject * ) ); } else { result = method->m_function->m_code( method->m_function, args, sizeof( args ) / sizeof( PyObject * ), NULL ); } Py_LeaveRecursiveCall(); return result; } } else if ( PyFunction_Check( called ) ) { PyObject *args[] = { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }; return fast_python_call( called, args, sizeof( args ) / sizeof( PyObject * ) ); } PyObject *args[] = { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }; PyObject *pos_args = MAKE_TUPLE( args, sizeof( args ) / sizeof( PyObject * ) ); PyObject *result = CALL_FUNCTION( called, pos_args, NULL ); Py_DECREF( pos_args ); return result; }