Skip to content

Commit

Permalink
Refactor postsetattrbehavior calls (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
frmdstryr authored Jan 20, 2025
1 parent 399399a commit 10447ae
Showing 1 changed file with 9 additions and 29 deletions.
38 changes: 9 additions & 29 deletions atom/src/postsetattrbehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,9 @@ int
object_method_old_new_handler(
Member* member, CAtom* atom, PyObject* oldvalue, PyObject* newvalue )
{
cppy::ptr callable( PyObject_GetAttr( pyobject_cast( atom ), member->post_setattr_context ) );
if( !callable )
return -1;
cppy::ptr args( PyTuple_New( 2 ) );
if( !args )
return -1;
PyTuple_SET_ITEM( args.get(), 0, cppy::incref( oldvalue ) );
PyTuple_SET_ITEM( args.get(), 1, cppy::incref( newvalue ) );
if( !callable.call( args ) )
PyObject* args[] = { pyobject_cast( atom ), oldvalue, newvalue };
cppy::ptr ok( PyObject_VectorcallMethod( member->post_setattr_context, args, 3 | PY_VECTORCALL_ARGUMENTS_OFFSET, 0 ) );
if( !ok )
return -1;
return 0;
}
Expand All @@ -82,16 +76,9 @@ int
object_method_name_old_new_handler(
Member* member, CAtom* atom, PyObject* oldvalue, PyObject* newvalue )
{
cppy::ptr callable( PyObject_GetAttr( pyobject_cast( atom ), member->post_setattr_context ) );
if( !callable )
return -1;
cppy::ptr args( PyTuple_New( 3 ) );
if( !args )
return -1;
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 ) );
if( !callable.call( args ) )
PyObject* args[] = { pyobject_cast( atom ), member->name, oldvalue, newvalue };
cppy::ptr ok( PyObject_VectorcallMethod( member->post_setattr_context, args, 4 | PY_VECTORCALL_ARGUMENTS_OFFSET, 0 ) );
if( !ok )
return -1;
return 0;
}
Expand All @@ -101,16 +88,9 @@ int
member_method_object_old_new_handler(
Member* member, CAtom* atom, PyObject* oldvalue, PyObject* newvalue )
{
cppy::ptr callable( PyObject_GetAttr( pyobject_cast( member ), member->post_setattr_context ) );
if( !callable )
return -1;
cppy::ptr args( PyTuple_New( 3 ) );
if( !args )
return -1;
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 ) );
if( !callable.call( args ) )
PyObject* args[] = { pyobject_cast( member ), pyobject_cast( atom ), oldvalue, newvalue };
cppy::ptr ok( PyObject_VectorcallMethod( member->post_setattr_context, args, 4 | PY_VECTORCALL_ARGUMENTS_OFFSET, 0 ) );
if( !ok )
return -1;
return 0;
}
Expand Down

0 comments on commit 10447ae

Please sign in to comment.