@@ -199,76 +199,65 @@ PyObject * PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwar
199199 return _Py_CheckFunctionResult (callable , result , NULL );
200200}
201201
202+ typedef PyObject * (* call_fun_t )(PyObject * , PyObject * , PyObject * );
203+ UPCALL_TYPED_ID (PyObject_Call , call_fun_t );
202204PyObject * PyObject_Call (PyObject * callable , PyObject * args , PyObject * kwargs ) {
203- return polyglot_invoke ( PY_TRUFFLE_CEXT , "PyObject_Call" , native_to_java (callable ), native_to_java (args ), native_to_java (kwargs ));
205+ return _jls_PyObject_Call ( native_to_java (callable ), native_to_java (args ), native_to_java (kwargs ));
204206}
205207
206208PyObject * PyObject_CallObject (PyObject * callable , PyObject * args ) {
207- return PyObject_Call ( callable , args , PyDict_New () );
209+ return _jls_PyObject_Call ( native_to_java ( callable ), native_to_java ( args ), NULL );
208210}
209211
210- NO_INLINE
211212PyObject * PyObject_CallFunction (PyObject * callable , const char * fmt , ...) {
212213 if (fmt == NULL || fmt [0 ] == '\0' ) {
213- return PyObject_CallObject ( callable , NULL );
214+ return _jls_PyObject_Call ( native_to_java ( callable ), NULL , NULL );
214215 }
215-
216216 va_list va ;
217217 va_start (va , fmt );
218218 PyObject * args = Py_VaBuildValue (fmt , va );
219219 va_end (va );
220220
221- if (strlen (fmt ) < 2 ) {
221+ if (strlen (fmt ) == 1 ) {
222222 PyObject * singleArg = args ;
223- args = PyTuple_New (strlen (fmt ));
224- if (strlen (fmt ) == 1 ) {
225- Py_XINCREF (singleArg );
226- PyTuple_SetItem (args , 0 , singleArg );
227- }
223+ args = PyTuple_New (1 );
224+ Py_XINCREF (singleArg );
225+ PyTuple_SetItem (args , 0 , singleArg );
228226 }
229- return PyObject_CallObject ( callable , args );
227+ return _jls_PyObject_Call ( native_to_java ( callable ), native_to_java ( args ), NULL );
230228}
231229
232- NO_INLINE
233230PyObject * _PyObject_CallFunction_SizeT (PyObject * callable , const char * fmt , ...) {
234231 if (fmt == NULL || fmt [0 ] == '\0' ) {
235- return PyObject_CallObject ( callable , NULL );
232+ return _jls_PyObject_Call ( native_to_java ( callable ), NULL , NULL );
236233 }
237234
238235 va_list va ;
239236 va_start (va , fmt );
240237 PyObject * args = Py_VaBuildValue (fmt , va );
241238 va_end (va );
242239
243- if (strlen (fmt ) < 2 ) {
240+ if (strlen (fmt ) == 1 ) {
244241 PyObject * singleArg = args ;
245- args = PyTuple_New (strlen (fmt ));
246- if (strlen (fmt ) == 1 ) {
247- Py_XINCREF (singleArg );
248- PyTuple_SetItem (args , 0 , singleArg );
249- }
242+ args = PyTuple_New (1 );
243+ Py_XINCREF (singleArg );
244+ PyTuple_SetItem (args , 0 , singleArg );
250245 }
251- return PyObject_CallObject ( callable , args );
246+ return _jls_PyObject_Call ( native_to_java ( callable ), native_to_java ( args ), NULL );
252247}
253248
254- NO_INLINE
249+ typedef PyObject * (* call_fun_obj_args_t )(PyObject * , void * );
250+ UPCALL_TYPED_ID (PyObject_CallFunctionObjArgs , call_fun_obj_args_t );
255251PyObject * PyObject_CallFunctionObjArgs (PyObject * callable , ...) {
256252 va_list vargs ;
257253 va_start (vargs , callable );
258254 // the arguments are given as a variable list followed by NULL
259- int nargs = polyglot_get_array_size (vargs ) - 1 ;
260- PyObject * args = PyTuple_New (nargs );
261- for (int i = 0 ; i < nargs ; i ++ ) {
262- PyObject * arg = (PyObject * ) va_arg (vargs , PyObject * );
263- Py_INCREF (arg );
264- PyTuple_SetItem (args , i , arg );
265- }
255+ PyObject * result = _jls_PyObject_CallFunctionObjArgs (native_to_java (callable ), & vargs );
266256 va_end (vargs );
267- return PyObject_CallObject ( callable , args ) ;
257+ return result ;
268258}
269259
270260UPCALL_ID (PyObject_CallMethod );
271- NO_INLINE
272261PyObject * PyObject_CallMethod (PyObject * object , const char * method , const char * fmt , ...) {
273262 PyObject * args ;
274263 if (fmt == NULL || fmt [0 ] == '\0' ) {
@@ -282,7 +271,6 @@ PyObject* PyObject_CallMethod(PyObject* object, const char* method, const char*
282271 return UPCALL_CEXT_O (_jls_PyObject_CallMethod , native_to_java (object ), polyglot_from_string (method , SRC_CS ), native_to_java (args ));
283272}
284273
285- NO_INLINE
286274PyObject * PyObject_CallMethodObjArgs (PyObject * callable , PyObject * name , ...) {
287275 va_list vargs ;
288276 va_start (vargs , name );
@@ -298,7 +286,6 @@ PyObject* PyObject_CallMethodObjArgs(PyObject *callable, PyObject *name, ...) {
298286 return UPCALL_CEXT_O (_jls_PyObject_CallMethod , native_to_java (callable ), native_to_java (name ), native_to_java (args ));
299287}
300288
301- NO_INLINE
302289PyObject * _PyObject_CallMethod_SizeT (PyObject * object , const char * method , const char * fmt , ...) {
303290 PyObject * args ;
304291 if (fmt == NULL || fmt [0 ] == '\0' ) {
@@ -312,16 +299,10 @@ PyObject* _PyObject_CallMethod_SizeT(PyObject* object, const char* method, const
312299 return UPCALL_CEXT_O (_jls_PyObject_CallMethod , native_to_java (object ), polyglot_from_string (method , SRC_CS ), native_to_java (args ));
313300}
314301
302+ typedef PyObject * (* fast_call_dict_fun_t )(PyObject * , void * , PyObject * );
303+ UPCALL_TYPED_ID (PyObject_FastCallDict , fast_call_dict_fun_t );
315304PyObject * _PyObject_FastCallDict (PyObject * func , PyObject * const * args , size_t nargs , PyObject * kwargs ) {
316- PyObject * targs = PyTuple_New (nargs );
317- Py_ssize_t i ;
318- PyObject * arg ;
319- for (i = 0 ; i < nargs ; i ++ ) {
320- arg = args [i ];
321- Py_XINCREF (arg );
322- PyTuple_SetItem (targs , i , arg );
323- }
324- return polyglot_invoke (PY_TRUFFLE_CEXT , "PyObject_Call" , native_to_java (func ), native_to_java (targs ), native_to_java (kwargs ));
305+ return _jls_PyObject_FastCallDict (native_to_java (func ), polyglot_from_PyObjectPtr_array (args , nargs ), native_to_java (kwargs ));
325306}
326307
327308PyObject * PyObject_Type (PyObject * obj ) {
0 commit comments