Skip to content

Commit 10447ae

Browse files
authored
Refactor postsetattrbehavior calls (#228)
1 parent 399399a commit 10447ae

File tree

1 file changed

+9
-29
lines changed

1 file changed

+9
-29
lines changed

atom/src/postsetattrbehavior.cpp

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,9 @@ int
6464
object_method_old_new_handler(
6565
Member* member, CAtom* atom, PyObject* oldvalue, PyObject* newvalue )
6666
{
67-
cppy::ptr callable( PyObject_GetAttr( pyobject_cast( atom ), member->post_setattr_context ) );
68-
if( !callable )
69-
return -1;
70-
cppy::ptr args( PyTuple_New( 2 ) );
71-
if( !args )
72-
return -1;
73-
PyTuple_SET_ITEM( args.get(), 0, cppy::incref( oldvalue ) );
74-
PyTuple_SET_ITEM( args.get(), 1, cppy::incref( newvalue ) );
75-
if( !callable.call( args ) )
67+
PyObject* args[] = { pyobject_cast( atom ), oldvalue, newvalue };
68+
cppy::ptr ok( PyObject_VectorcallMethod( member->post_setattr_context, args, 3 | PY_VECTORCALL_ARGUMENTS_OFFSET, 0 ) );
69+
if( !ok )
7670
return -1;
7771
return 0;
7872
}
@@ -82,16 +76,9 @@ int
8276
object_method_name_old_new_handler(
8377
Member* member, CAtom* atom, PyObject* oldvalue, PyObject* newvalue )
8478
{
85-
cppy::ptr callable( PyObject_GetAttr( pyobject_cast( atom ), member->post_setattr_context ) );
86-
if( !callable )
87-
return -1;
88-
cppy::ptr args( PyTuple_New( 3 ) );
89-
if( !args )
90-
return -1;
91-
PyTuple_SET_ITEM( args.get(), 0, cppy::incref( member->name ) );
92-
PyTuple_SET_ITEM( args.get(), 1, cppy::incref( oldvalue ) );
93-
PyTuple_SET_ITEM( args.get(), 2, cppy::incref( newvalue ) );
94-
if( !callable.call( args ) )
79+
PyObject* args[] = { pyobject_cast( atom ), member->name, oldvalue, newvalue };
80+
cppy::ptr ok( PyObject_VectorcallMethod( member->post_setattr_context, args, 4 | PY_VECTORCALL_ARGUMENTS_OFFSET, 0 ) );
81+
if( !ok )
9582
return -1;
9683
return 0;
9784
}
@@ -101,16 +88,9 @@ int
10188
member_method_object_old_new_handler(
10289
Member* member, CAtom* atom, PyObject* oldvalue, PyObject* newvalue )
10390
{
104-
cppy::ptr callable( PyObject_GetAttr( pyobject_cast( member ), member->post_setattr_context ) );
105-
if( !callable )
106-
return -1;
107-
cppy::ptr args( PyTuple_New( 3 ) );
108-
if( !args )
109-
return -1;
110-
PyTuple_SET_ITEM( args.get(), 0, cppy::incref( pyobject_cast( atom ) ) );
111-
PyTuple_SET_ITEM( args.get(), 1, cppy::incref( oldvalue ) );
112-
PyTuple_SET_ITEM( args.get(), 2, cppy::incref( newvalue ) );
113-
if( !callable.call( args ) )
91+
PyObject* args[] = { pyobject_cast( member ), pyobject_cast( atom ), oldvalue, newvalue };
92+
cppy::ptr ok( PyObject_VectorcallMethod( member->post_setattr_context, args, 4 | PY_VECTORCALL_ARGUMENTS_OFFSET, 0 ) );
93+
if( !ok )
11494
return -1;
11595
return 0;
11696
}

0 commit comments

Comments
 (0)