Skip to content

Commit

Permalink
Refactor postgetattr calls (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
frmdstryr authored Jan 20, 2025
1 parent 1f2a89a commit 7030a07
Showing 1 changed file with 5 additions and 26 deletions.
31 changes: 5 additions & 26 deletions atom/src/postgetattrbehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,44 +63,23 @@ delegate_handler( Member* member, CAtom* atom, PyObject* value )
PyObject*
object_method_value_handler( Member* member, CAtom* atom, PyObject* value )
{
cppy::ptr callable( PyObject_GetAttr( pyobject_cast( atom ), member->post_getattr_context ) );
if( !callable )
return 0;
cppy::ptr args( PyTuple_New( 1 ) );
if( !args )
return 0;
PyTuple_SET_ITEM( args.get(), 0, cppy::incref( value ) );
return callable.call( args );
return PyObject_CallMethodOneArg( pyobject_cast( atom ), member->post_getattr_context, value );
}


PyObject*
object_method_name_value_handler( Member* member, CAtom* atom, PyObject* value )
{
cppy::ptr callable( PyObject_GetAttr( pyobject_cast( atom ), member->post_getattr_context ) );
if( !callable )
return 0;
cppy::ptr args( PyTuple_New( 2 ) );
if( !args )
return 0;
PyTuple_SET_ITEM( args.get(), 0, cppy::incref( member->name ) );
PyTuple_SET_ITEM( args.get(), 1, cppy::incref( value ) );
return callable.call( args );
PyObject* args[] = { pyobject_cast( atom ), member->name, value };
return PyObject_VectorcallMethod( member->post_getattr_context, args, 3 | PY_VECTORCALL_ARGUMENTS_OFFSET, 0 );
}


PyObject*
member_method_object_value_handler( Member* member, CAtom* atom, PyObject* value )
{
cppy::ptr callable( PyObject_GetAttr( pyobject_cast( member ), member->post_getattr_context ) );
if( !callable )
return 0;
cppy::ptr args( PyTuple_New( 2 ) );
if( !args )
return 0;
PyTuple_SET_ITEM( args.get(), 0, cppy::incref( pyobject_cast( atom ) ) );
PyTuple_SET_ITEM( args.get(), 1, cppy::incref( value ) );
return callable.call( args );
PyObject* args[] = { pyobject_cast( member ), pyobject_cast( atom ), value };
return PyObject_VectorcallMethod( member->post_getattr_context, args, 3 | PY_VECTORCALL_ARGUMENTS_OFFSET, 0 );
}


Expand Down

0 comments on commit 7030a07

Please sign in to comment.