Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor postsetattrbehavior calls #228

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading