@@ -67,26 +67,6 @@ PyObject* PyTruffle_GetArg(positional_argstack* p, PyObject* kwds, char** kwdnam
67
67
return out ;
68
68
}
69
69
70
- /*
71
- * (tfel): On native Sulong, using va_list will force all arguments to native
72
- * memory, which hinders escape analysis and PE in a big way. To avoid this,
73
- * when we have function called with var args (rather than already with a
74
- * va_list), we allocate a managed array of void*, fill it with the arguments,
75
- * and pass that one on. In the target functions, we use the macros below to
76
- * access the variable arguments part depending on whether it is a va_list or a
77
- * managed void* array. The assumption is that once everything is compiled
78
- * together, the managed array with arguments will be escape analyzed away.
79
- */
80
-
81
- #define CallAndReturnWithPolyglotArgs (off , function , ...) \
82
- int __poly_argc = polyglot_get_arg_count(); \
83
- int __poly_args_s = sizeof(void*) * (__poly_argc - off); \
84
- void **__poly_args = truffle_managed_malloc(__poly_args_s); \
85
- for (int i = off; i < __poly_argc; i++) { \
86
- __poly_args[i - off] = polyglot_get_arg(i); \
87
- } \
88
- return function(__VA_ARGS__, NULL, __poly_args, 0)
89
-
90
70
#define PyTruffleVaArg (poly_args , offset , va , T ) (poly_args == NULL ? va_arg(va, T) : (T)(poly_args[offset++]))
91
71
92
72
#define PyTruffle_WriteOut (poly_args , offset , va , T , arg ) { \
@@ -379,11 +359,13 @@ int _PyArg_VaParseTupleAndKeywords_SizeT(PyObject *argv, PyObject *kwds, const c
379
359
380
360
381
361
int PyArg_ParseTupleAndKeywords (PyObject * argv , PyObject * kwds , const char * format , char * * kwdnames , ...) {
382
- CallAndReturnWithPolyglotArgs (4 , _PyTruffleArg_ParseTupleAndKeywords , argv , kwds , format , kwdnames );
362
+ CallWithPolyglotArgs (int result , kwdnames , 4 , _PyTruffleArg_ParseTupleAndKeywords , argv , kwds , format , kwdnames );
363
+ return result ;
383
364
}
384
365
385
366
int _PyArg_ParseTupleAndKeywords_SizeT (PyObject * argv , PyObject * kwds , const char * format , char * * kwdnames , ...) {
386
- CallAndReturnWithPolyglotArgs (4 , _PyTruffleArg_ParseTupleAndKeywords , argv , kwds , format , kwdnames );
367
+ CallWithPolyglotArgs (int result , kwdnames , 4 , _PyTruffleArg_ParseTupleAndKeywords , argv , kwds , format , kwdnames );
368
+ return result ;
387
369
}
388
370
389
371
int PyArg_ParseStack (PyObject * * args , Py_ssize_t nargs , PyObject * kwds , struct _PyArg_Parser * parser , ...) {
@@ -392,7 +374,8 @@ int PyArg_ParseStack(PyObject **args, Py_ssize_t nargs, PyObject *kwds, struct _
392
374
for (i = 0 ; i < nargs ; i ++ ) {
393
375
PyTuple_SetItem (argv , i , args [i ]);
394
376
}
395
- CallAndReturnWithPolyglotArgs (4 , _PyTruffleArg_ParseTupleAndKeywords , argv , kwds , parser -> format , parser -> keywords );
377
+ CallWithPolyglotArgs (int result , parser , 4 , _PyTruffleArg_ParseTupleAndKeywords , argv , kwds , parser -> format , parser -> keywords );
378
+ return result ;
396
379
}
397
380
398
381
int _PyArg_ParseStack_SizeT (PyObject * * args , Py_ssize_t nargs , PyObject * kwds , struct _PyArg_Parser * parser , ...) {
@@ -402,7 +385,8 @@ int _PyArg_ParseStack_SizeT(PyObject **args, Py_ssize_t nargs, PyObject *kwds, s
402
385
PyTuple_SetItem (argv , i , args [i ]);
403
386
}
404
387
405
- CallAndReturnWithPolyglotArgs (4 , _PyTruffleArg_ParseTupleAndKeywords , argv , kwds , parser -> format , parser -> keywords );
388
+ CallWithPolyglotArgs (int result , parser , 4 , _PyTruffleArg_ParseTupleAndKeywords , argv , kwds , parser -> format , parser -> keywords );
389
+ return result ;
406
390
}
407
391
408
392
int _PyArg_VaParseTupleAndKeywordsFast (PyObject * args , PyObject * kwargs , struct _PyArg_Parser * parser , va_list va ) {
@@ -414,19 +398,23 @@ int _PyArg_VaParseTupleAndKeywordsFast_SizeT(PyObject *args, PyObject *kwargs, s
414
398
}
415
399
416
400
int _PyArg_ParseTupleAndKeywordsFast (PyObject * args , PyObject * kwargs , struct _PyArg_Parser * parser , ...) {
417
- CallAndReturnWithPolyglotArgs (3 , _PyTruffleArg_ParseTupleAndKeywords , args , kwargs , parser -> format , parser -> keywords );
401
+ CallWithPolyglotArgs (int result , parser , 3 , _PyTruffleArg_ParseTupleAndKeywords , args , kwargs , parser -> format , parser -> keywords );
402
+ return result ;
418
403
}
419
404
420
405
int _PyArg_ParseTupleAndKeywordsFast_SizeT (PyObject * args , PyObject * kwargs , struct _PyArg_Parser * parser , ...) {
421
- CallAndReturnWithPolyglotArgs (3 , _PyTruffleArg_ParseTupleAndKeywords , args , kwargs , parser -> format , parser -> keywords );
406
+ CallWithPolyglotArgs (int result , parser , 3 , _PyTruffleArg_ParseTupleAndKeywords , args , kwargs , parser -> format , parser -> keywords );
407
+ return result ;
422
408
}
423
409
424
410
int PyArg_ParseTuple (PyObject * args , const char * format , ...) {
425
- CallAndReturnWithPolyglotArgs (2 , _PyTruffleArg_ParseTupleAndKeywords , args , NULL , format , NULL );
411
+ CallWithPolyglotArgs (int result , format , 2 , _PyTruffleArg_ParseTupleAndKeywords , args , NULL , format , NULL );
412
+ return result ;
426
413
}
427
414
428
415
int _PyArg_ParseTuple_SizeT (PyObject * args , const char * format , ...) {
429
- CallAndReturnWithPolyglotArgs (2 , _PyTruffleArg_ParseTupleAndKeywords , args , NULL , format , NULL );
416
+ CallWithPolyglotArgs (int result , format , 2 , _PyTruffleArg_ParseTupleAndKeywords , args , NULL , format , NULL );
417
+ return result ;
430
418
}
431
419
432
420
int PyArg_VaParse (PyObject * args , const char * format , va_list va ) {
@@ -438,11 +426,13 @@ int _PyArg_VaParse_SizeT(PyObject *args, const char *format, va_list va) {
438
426
}
439
427
440
428
int PyArg_Parse (PyObject * args , const char * format , ...) {
441
- CallAndReturnWithPolyglotArgs (2 , _PyTruffleArg_ParseTupleAndKeywords , PyTuple_Pack (1 , args ), NULL , format , NULL );
429
+ CallWithPolyglotArgs (int result , format , 2 , _PyTruffleArg_ParseTupleAndKeywords , PyTuple_Pack (1 , args ), NULL , format , NULL );
430
+ return result ;
442
431
}
443
432
444
433
int _PyArg_Parse_SizeT (PyObject * args , const char * format , ...) {
445
- CallAndReturnWithPolyglotArgs (2 , _PyTruffleArg_ParseTupleAndKeywords , PyTuple_Pack (1 , args ), NULL , format , NULL );
434
+ CallWithPolyglotArgs (int result , format , 2 , _PyTruffleArg_ParseTupleAndKeywords , PyTuple_Pack (1 , args ), NULL , format , NULL );
435
+ return result ;
446
436
}
447
437
448
438
typedef struct _build_stack {
@@ -659,11 +649,13 @@ PyObject* _Py_VaBuildValue_SizeT(const char *format, va_list va) {
659
649
}
660
650
661
651
PyObject * Py_BuildValue (const char * format , ...) {
662
- CallAndReturnWithPolyglotArgs (1 , _PyTruffle_BuildValue , format );
652
+ CallWithPolyglotArgs (PyObject * result , format , 1 , _PyTruffle_BuildValue , format );
653
+ return result ;
663
654
}
664
655
665
656
PyObject * _Py_BuildValue_SizeT (const char * format , ...) {
666
- CallAndReturnWithPolyglotArgs (1 , _PyTruffle_BuildValue , format );
657
+ CallWithPolyglotArgs (PyObject * result , format , 1 , _PyTruffle_BuildValue , format );
658
+ return result ;
667
659
}
668
660
669
661
// taken from CPython "Python/modsupport.c"
0 commit comments