Skip to content

Commit 19dfbcd

Browse files
timfelfangerer
authored andcommitted
refactor argument parsing, supports unpacking of tuples now
1 parent 7e3d390 commit 19dfbcd

File tree

3 files changed

+308
-172
lines changed

3 files changed

+308
-172
lines changed

graalpython/com.oracle.graal.python.cext/include/Python.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ extern int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, c
179179
#ifdef PyArg_ParseTuple
180180
#undef PyArg_ParseTuple
181181
#endif
182-
#define PyArg_ParseTuple(ARGV, FORMAT, ...) PyArg_ParseTupleAndKeywords(ARGV, PyDict_New(), FORMAT, (char*[]) { NULL }, ##__VA_ARGS__)
182+
#define PyArg_ParseTuple(ARGV, FORMAT, ...) PyArg_ParseTupleAndKeywords(ARGV, PyDict_New(), FORMAT, NULL, ##__VA_ARGS__)
183183

184184
#ifdef _PyArg_ParseTupleAndKeywordsFast
185185
#undef _PyArg_ParseTupleAndKeywordsFast
@@ -189,7 +189,7 @@ extern int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, c
189189
#ifdef PyArg_Parse
190190
#undef PyArg_Parse
191191
#endif
192-
#define PyArg_Parse(ARGV, FORMAT, ...) PyArg_ParseTupleAndKeywords(ARGV, PyDict_New(), FORMAT, (char*[]) { NULL }, __VA_ARGS__)
192+
#define PyArg_Parse(ARGV, FORMAT, ...) PyArg_ParseTupleAndKeywords(ARGV, PyDict_New(), FORMAT, NULL, __VA_ARGS__)
193193

194194
extern PyObject * PyTruffle_Unicode_FromFormat(const char *fmt, int s, void* v0, void* v1, void* v2, void* v3, void* v4, void* v5, void* v6, void* v7, void* v8, void* v9, void* v10, void* v11, void* v12, void* v13, void* v14, void* v15, void* v16, void* v17, void* v18, void* v19);
195195
#define PyTruffle_Unicode_FromFormat_0(F1) PyTruffle_Unicode_FromFormat(F1, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)

graalpython/com.oracle.graal.python.cext/src/capi.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
#ifndef CAPI_H
4040
#define CAPI_H
4141

42+
#define MUST_INLINE __attribute__((always_inline)) inline
43+
4244
#include "Python.h"
4345

4446
/* Private types are defined here because we need to declare the type cast. */
@@ -80,13 +82,13 @@ POLYGLOT_DECLARE_TYPE(PySetObject);
8082
extern void* to_java(PyObject* obj);
8183
extern void* to_java_type(PyTypeObject* cls);
8284
extern PyObject* to_sulong(void *o);
83-
#define as_char_pointer(obj) truffle_invoke(PY_TRUFFLE_CEXT, "to_char_pointer", to_java(obj))
84-
#define as_long(obj) truffle_invoke(PY_TRUFFLE_CEXT, "to_long", obj)
85+
#define as_char_pointer(obj) polyglot_invoke(PY_TRUFFLE_CEXT, "to_char_pointer", to_java(obj))
86+
#define as_long(obj) ((long)polyglot_as_i64(polyglot_invoke(PY_TRUFFLE_CEXT, "to_long", to_java(obj))))
8587
#define as_int(obj) ((int)as_long(obj))
8688
#define as_short(obj) ((short)as_long(obj))
8789
#define as_uchar(obj) ((unsigned char)as_long(obj))
8890
#define as_char(obj) ((char)as_long(obj))
89-
#define as_double(obj) truffle_invoke_d(PY_TRUFFLE_CEXT, "to_double", to_java(obj))
91+
#define as_double(obj) polyglot_as_double(polyglot_invoke(PY_TRUFFLE_CEXT, "to_double", to_java(obj)))
9092
#define as_float(obj) ((float)as_double(obj))
9193

9294
// defined in 'exceptions.c'

0 commit comments

Comments
 (0)