@@ -1609,18 +1609,21 @@ static PyObject *
16091609methodcaller_vectorcall (
16101610 methodcallerobject * mc , PyObject * const * args , size_t nargsf , PyObject * kwnames )
16111611{
1612- printf ("methodcaller_vectorcall\n" );
1612+ // printf("methodcaller_vectorcall\n");
16131613 if (!_PyArg_CheckPositional ("methodcaller" , PyVectorcall_NARGS (nargsf ), 1 , 1 )
16141614 || !_PyArg_NoKwnames ("methodcaller" , kwnames )) {
16151615 return NULL ;
16161616 }
16171617 assert (mc -> vectorcall_args != NULL );
16181618
1619- Py_ssize_t number_of_arguments = 1 + PyTuple_GET_SIZE (mc -> args ) +
1620- (mc -> vectorcall_kwnames ? PyTuple_GET_SIZE (mc -> vectorcall_kwnames ):0 ) + 1 ;
1619+ Py_ssize_t number_of_arguments = PyTuple_GET_SIZE (mc -> args ) +
1620+ (mc -> vectorcall_kwnames ? PyTuple_GET_SIZE (mc -> vectorcall_kwnames ):0 );
1621+
1622+ //printf("methodcaller_vectorcall: number_of_arguments %ld\n", number_of_arguments);
16211623
16221624 PyObject * tmp_args [_METHODCALLER_MAX_ARGS ];
16231625 tmp_args [0 ] = args [0 ];
1626+ tmp_args [1 ] = Py_None ;
16241627 if (number_of_arguments ) {
16251628 assert (1 + number_of_arguments <= _METHODCALLER_MAX_ARGS );
16261629 memcpy (tmp_args + 1 , mc -> vectorcall_args , sizeof (PyObject * ) * number_of_arguments );
@@ -1630,7 +1633,7 @@ methodcaller_vectorcall(
16301633 (1 + PyTuple_GET_SIZE (mc -> args )) | PY_VECTORCALL_ARGUMENTS_OFFSET ,
16311634 mc -> vectorcall_kwnames );
16321635
1633- PyMem_Free ( tmp_args );
1636+ //printf("methodcaller_vectorcall done\n" );
16341637 return result ;
16351638}
16361639
@@ -1639,7 +1642,9 @@ static int _methodcaller_initialize_vectorcall(methodcallerobject* mc)
16391642 PyObject * args = mc -> args ;
16401643 PyObject * kwds = mc -> kwds ;
16411644
1642- Py_ssize_t nargs = 1 + PyTuple_GET_SIZE (args );
1645+ Py_ssize_t nargs = PyTuple_GET_SIZE (args );
1646+ // printf("_methodcaller_initialize_vectorcall: nargs %ld, vectorcall_args size \n", nargs, nargs + (kwds ? PyDict_Size(kwds) : 0));
1647+
16431648 mc -> vectorcall_args = PyMem_Calloc (
16441649 nargs + (kwds ? PyDict_Size (kwds ) : 0 ),
16451650 sizeof (PyObject * ));
@@ -1648,9 +1653,9 @@ static int _methodcaller_initialize_vectorcall(methodcallerobject* mc)
16481653 return -1 ;
16491654 }
16501655 /* The first item of vectorcall_args will be filled with obj later */
1651- if (nargs > 1 ) {
1652- memcpy (mc -> vectorcall_args + 1 , PySequence_Fast_ITEMS (args ),
1653- ( nargs - 1 ) * sizeof (PyObject * ));
1656+ if (nargs > 0 ) {
1657+ memcpy (mc -> vectorcall_args , PySequence_Fast_ITEMS (args ),
1658+ nargs * sizeof (PyObject * ));
16541659 }
16551660 if (kwds ) {
16561661 const Py_ssize_t nkwds = PyDict_Size (kwds );
@@ -1670,7 +1675,7 @@ static int _methodcaller_initialize_vectorcall(methodcallerobject* mc)
16701675 else {
16711676 mc -> vectorcall_kwnames = NULL ;
16721677 }
1673- // mc->vectorcall = (vectorcallfunc)methodcaller_vectorcall;
1678+ mc -> vectorcall = (vectorcallfunc )methodcaller_vectorcall ;
16741679
16751680 return 1 ;
16761681}
@@ -1707,37 +1712,33 @@ methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
17071712 _PyUnicode_InternMortal (interp , & name );
17081713 mc -> name = name ;
17091714
1715+ //printf("methodcaller_new: %ld \n", PyTuple_GET_SIZE(args));
17101716 mc -> args = PyTuple_GetSlice (args , 1 , PyTuple_GET_SIZE (args ));
17111717 if (mc -> args == NULL ) {
17121718 Py_DECREF (mc );
17131719 return NULL ;
17141720 }
17151721 mc -> kwds = Py_XNewRef (kwds );
1722+ mc -> vectorcall = NULL ;
17161723 mc -> vectorcall_args = NULL ;
17171724
17181725 Py_ssize_t vectorcall_size = PyTuple_GET_SIZE (args )
17191726 + (kwds ? PyDict_Size (kwds ) : 0 );
1720- printf ("methodcaller_new %d %d\n" , PyTuple_GET_SIZE (args ), vectorcall_size );
1721- if (vectorcall_size < (_METHODCALLER_MAX_ARGS - 10 )) {
1722- printf ("hih\n" );
1727+ if (vectorcall_size < (_METHODCALLER_MAX_ARGS )) {
17231728 if (_methodcaller_initialize_vectorcall (mc ) < 0 ) {
17241729 Py_XDECREF (mc -> args );
17251730 Py_XDECREF (mc -> kwds );
17261731 return NULL ;
17271732 }
17281733 }
17291734
1730- //mc->vectorcall = (vectorcallfunc)methodcaller_vectorcall;
1731-
17321735 PyObject_GC_Track (mc );
17331736 return (PyObject * )mc ;
17341737}
17351738
17361739static void
17371740methodcaller_clear (methodcallerobject * mc )
17381741{
1739- printf ("methodcaller_clear\n" );
1740-
17411742 Py_CLEAR (mc -> name );
17421743 Py_CLEAR (mc -> args );
17431744 Py_CLEAR (mc -> kwds );
@@ -1750,8 +1751,6 @@ methodcaller_clear(methodcallerobject *mc)
17501751static void
17511752methodcaller_dealloc (methodcallerobject * mc )
17521753{
1753- printf ("methodcaller_dealloc\n" );
1754-
17551754 PyTypeObject * tp = Py_TYPE (mc );
17561755 PyObject_GC_UnTrack (mc );
17571756 methodcaller_clear (mc );
@@ -1762,7 +1761,6 @@ methodcaller_dealloc(methodcallerobject *mc)
17621761static int
17631762methodcaller_traverse (methodcallerobject * mc , visitproc visit , void * arg )
17641763{
1765- printf ("methodcaller_traverse\n" );
17661764 Py_VISIT (mc -> name );
17671765 Py_VISIT (mc -> args );
17681766 Py_VISIT (mc -> kwds );
@@ -1774,7 +1772,6 @@ static PyObject *
17741772methodcaller_call (methodcallerobject * mc , PyObject * args , PyObject * kw )
17751773{
17761774 printf ("methodcaller_call\n" );
1777- return Py_None ;
17781775 PyObject * method , * obj , * result ;
17791776
17801777 if (!_PyArg_NoKeywords ("methodcaller" , kw ))
0 commit comments