@@ -199,76 +199,65 @@ PyObject * PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwar
199
199
return _Py_CheckFunctionResult (callable , result , NULL );
200
200
}
201
201
202
+ typedef PyObject * (* call_fun_t )(PyObject * , PyObject * , PyObject * );
203
+ UPCALL_TYPED_ID (PyObject_Call , call_fun_t );
202
204
PyObject * 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 ));
204
206
}
205
207
206
208
PyObject * 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 );
208
210
}
209
211
210
- NO_INLINE
211
212
PyObject * PyObject_CallFunction (PyObject * callable , const char * fmt , ...) {
212
213
if (fmt == NULL || fmt [0 ] == '\0' ) {
213
- return PyObject_CallObject ( callable , NULL );
214
+ return _jls_PyObject_Call ( native_to_java ( callable ), NULL , NULL );
214
215
}
215
-
216
216
va_list va ;
217
217
va_start (va , fmt );
218
218
PyObject * args = Py_VaBuildValue (fmt , va );
219
219
va_end (va );
220
220
221
- if (strlen (fmt ) < 2 ) {
221
+ if (strlen (fmt ) == 1 ) {
222
222
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 );
228
226
}
229
- return PyObject_CallObject ( callable , args );
227
+ return _jls_PyObject_Call ( native_to_java ( callable ), native_to_java ( args ), NULL );
230
228
}
231
229
232
- NO_INLINE
233
230
PyObject * _PyObject_CallFunction_SizeT (PyObject * callable , const char * fmt , ...) {
234
231
if (fmt == NULL || fmt [0 ] == '\0' ) {
235
- return PyObject_CallObject ( callable , NULL );
232
+ return _jls_PyObject_Call ( native_to_java ( callable ), NULL , NULL );
236
233
}
237
234
238
235
va_list va ;
239
236
va_start (va , fmt );
240
237
PyObject * args = Py_VaBuildValue (fmt , va );
241
238
va_end (va );
242
239
243
- if (strlen (fmt ) < 2 ) {
240
+ if (strlen (fmt ) == 1 ) {
244
241
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 );
250
245
}
251
- return PyObject_CallObject ( callable , args );
246
+ return _jls_PyObject_Call ( native_to_java ( callable ), native_to_java ( args ), NULL );
252
247
}
253
248
254
- NO_INLINE
249
+ typedef PyObject * (* call_fun_obj_args_t )(PyObject * , void * );
250
+ UPCALL_TYPED_ID (PyObject_CallFunctionObjArgs , call_fun_obj_args_t );
255
251
PyObject * PyObject_CallFunctionObjArgs (PyObject * callable , ...) {
256
252
va_list vargs ;
257
253
va_start (vargs , callable );
258
254
// 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 );
266
256
va_end (vargs );
267
- return PyObject_CallObject ( callable , args ) ;
257
+ return result ;
268
258
}
269
259
270
260
UPCALL_ID (PyObject_CallMethod );
271
- NO_INLINE
272
261
PyObject * PyObject_CallMethod (PyObject * object , const char * method , const char * fmt , ...) {
273
262
PyObject * args ;
274
263
if (fmt == NULL || fmt [0 ] == '\0' ) {
@@ -282,7 +271,6 @@ PyObject* PyObject_CallMethod(PyObject* object, const char* method, const char*
282
271
return UPCALL_CEXT_O (_jls_PyObject_CallMethod , native_to_java (object ), polyglot_from_string (method , SRC_CS ), native_to_java (args ));
283
272
}
284
273
285
- NO_INLINE
286
274
PyObject * PyObject_CallMethodObjArgs (PyObject * callable , PyObject * name , ...) {
287
275
va_list vargs ;
288
276
va_start (vargs , name );
@@ -298,7 +286,6 @@ PyObject* PyObject_CallMethodObjArgs(PyObject *callable, PyObject *name, ...) {
298
286
return UPCALL_CEXT_O (_jls_PyObject_CallMethod , native_to_java (callable ), native_to_java (name ), native_to_java (args ));
299
287
}
300
288
301
- NO_INLINE
302
289
PyObject * _PyObject_CallMethod_SizeT (PyObject * object , const char * method , const char * fmt , ...) {
303
290
PyObject * args ;
304
291
if (fmt == NULL || fmt [0 ] == '\0' ) {
@@ -312,16 +299,10 @@ PyObject* _PyObject_CallMethod_SizeT(PyObject* object, const char* method, const
312
299
return UPCALL_CEXT_O (_jls_PyObject_CallMethod , native_to_java (object ), polyglot_from_string (method , SRC_CS ), native_to_java (args ));
313
300
}
314
301
302
+ typedef PyObject * (* fast_call_dict_fun_t )(PyObject * , void * , PyObject * );
303
+ UPCALL_TYPED_ID (PyObject_FastCallDict , fast_call_dict_fun_t );
315
304
PyObject * _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 ));
325
306
}
326
307
327
308
PyObject * PyObject_Type (PyObject * obj ) {
0 commit comments