From ad7f0a0f9ffbc56781211a0e1f77e3c5fd879e6a Mon Sep 17 00:00:00 2001 From: frmdstryr Date: Sat, 18 Jan 2025 20:26:12 -0500 Subject: [PATCH] Refactor postvalidate calls --- atom/src/postvalidatebehavior.cpp | 35 ++++++------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/atom/src/postvalidatebehavior.cpp b/atom/src/postvalidatebehavior.cpp index dc0379a3..4d61b912 100644 --- a/atom/src/postvalidatebehavior.cpp +++ b/atom/src/postvalidatebehavior.cpp @@ -64,15 +64,8 @@ PyObject* object_method_old_new_handler( Member* member, CAtom* atom, PyObject* oldvalue, PyObject* newvalue ) { - cppy::ptr callable( PyObject_GetAttr( pyobject_cast( atom ), member->post_validate_context ) ); - if( !callable ) - return 0; - cppy::ptr args( PyTuple_New( 2 ) ); - if( !args ) - return 0; - PyTuple_SET_ITEM( args.get(), 0, cppy::incref( oldvalue ) ); - PyTuple_SET_ITEM( args.get(), 1, cppy::incref( newvalue ) ); - return callable.call( args ); + PyObject* args[] = { pyobject_cast( atom ), oldvalue, newvalue }; + return PyObject_VectorcallMethod( member->post_validate_context, args, 3 | PY_VECTORCALL_ARGUMENTS_OFFSET, 0 ); } @@ -80,16 +73,8 @@ PyObject* object_method_name_old_new_handler( Member* member, CAtom* atom, PyObject* oldvalue, PyObject* newvalue ) { - cppy::ptr callable( PyObject_GetAttr( pyobject_cast( atom ), member->post_validate_context ) ); - if( !callable ) - return 0; - cppy::ptr args( PyTuple_New( 3 ) ); - if( !args ) - return 0; - PyTuple_SET_ITEM( args.get(), 0, cppy::incref( member->name ) ); - PyTuple_SET_ITEM( args.get(), 1, cppy::incref( oldvalue ) ); - PyTuple_SET_ITEM( args.get(), 2, cppy::incref( newvalue ) ); - return callable.call( args ); + PyObject* args[] = { pyobject_cast( atom ), member->name, oldvalue, newvalue }; + return PyObject_VectorcallMethod( member->post_validate_context, args, 4 | PY_VECTORCALL_ARGUMENTS_OFFSET, 0 ); } @@ -97,16 +82,8 @@ PyObject* member_method_object_old_new_handler( Member* member, CAtom* atom, PyObject* oldvalue, PyObject* newvalue ) { - cppy::ptr callable( PyObject_GetAttr( pyobject_cast( member ), member->post_validate_context ) ); - if( !callable ) - return 0; - cppy::ptr args( PyTuple_New( 3 ) ); - if( !args ) - return 0; - PyTuple_SET_ITEM( args.get(), 0, cppy::incref( pyobject_cast( atom ) ) ); - PyTuple_SET_ITEM( args.get(), 1, cppy::incref( oldvalue ) ); - PyTuple_SET_ITEM( args.get(), 2, cppy::incref( newvalue ) ); - return callable.call( args ); + PyObject* args[] = { pyobject_cast( member ), pyobject_cast( atom ), oldvalue, newvalue }; + return PyObject_VectorcallMethod( member->post_validate_context, args, 4 | PY_VECTORCALL_ARGUMENTS_OFFSET, 0 ); }