Skip to content

Commit 6697a90

Browse files
committed
Directly access va_list in WriteOutVarNode and GetVaArgsNode.
1 parent 6ee2a35 commit 6697a90

File tree

5 files changed

+190
-164
lines changed

5 files changed

+190
-164
lines changed

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

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -201,62 +201,6 @@ POLYGLOT_DECLARE_TYPE(PyThreadState);
201201
POLYGLOT_DECLARE_TYPE(newfunc);
202202

203203

204-
/* primitive and pointer type declarations */
205-
206-
#define REGISTER_BASIC_TYPE(typename) \
207-
POLYGLOT_DECLARE_TYPE(typename); \
208-
NO_INLINE static polyglot_typeid get_ ## typename ## _typeid(void) { \
209-
return polyglot_ ## typename ## _typeid(); \
210-
}
211-
212-
/* just a renaming to avoid name clash with Java types */
213-
typedef float float_t;
214-
typedef double double_t;
215-
216-
REGISTER_BASIC_TYPE(int64_t);
217-
REGISTER_BASIC_TYPE(int32_t);
218-
REGISTER_BASIC_TYPE(int16_t);
219-
REGISTER_BASIC_TYPE(int8_t);
220-
REGISTER_BASIC_TYPE(uint64_t);
221-
REGISTER_BASIC_TYPE(uint32_t);
222-
REGISTER_BASIC_TYPE(uint16_t);
223-
REGISTER_BASIC_TYPE(uint8_t);
224-
REGISTER_BASIC_TYPE(Py_complex);
225-
REGISTER_BASIC_TYPE(float_t);
226-
REGISTER_BASIC_TYPE(double_t);
227-
REGISTER_BASIC_TYPE(Py_ssize_t);
228-
229-
typedef int64_t* int64_ptr_t;
230-
typedef int32_t* int32_ptr_t;
231-
typedef int16_t* int16_ptr_t;
232-
typedef int8_t* int8_ptr_t;
233-
typedef char* char_ptr_t;
234-
typedef float* float_ptr_t;
235-
typedef double* double_ptr_t;
236-
typedef uint64_t* uint64_ptr_t;
237-
typedef uint32_t* uint32_ptr_t;
238-
typedef uint16_t* uint16_ptr_t;
239-
typedef uint8_t* uint8_ptr_t;
240-
typedef Py_complex* Py_complex_ptr_t;
241-
typedef void* void_ptr_t;
242-
typedef Py_ssize_t* Py_ssize_ptr_t;
243-
244-
REGISTER_BASIC_TYPE(int64_ptr_t);
245-
REGISTER_BASIC_TYPE(int32_ptr_t);
246-
REGISTER_BASIC_TYPE(int16_ptr_t);
247-
REGISTER_BASIC_TYPE(int8_ptr_t);
248-
REGISTER_BASIC_TYPE(char_ptr_t);
249-
REGISTER_BASIC_TYPE(uint64_ptr_t);
250-
REGISTER_BASIC_TYPE(uint32_ptr_t);
251-
REGISTER_BASIC_TYPE(uint16_ptr_t);
252-
REGISTER_BASIC_TYPE(uint8_ptr_t);
253-
REGISTER_BASIC_TYPE(Py_complex_ptr_t);
254-
REGISTER_BASIC_TYPE(void_ptr_t);
255-
REGISTER_BASIC_TYPE(float_ptr_t);
256-
REGISTER_BASIC_TYPE(double_ptr_t);
257-
REGISTER_BASIC_TYPE(Py_ssize_ptr_t);
258-
259-
260204
static void initialize_globals() {
261205
// register native NULL
262206
wrapped_null = polyglot_invoke(PY_TRUFFLE_CEXT, polyglot_from_string("PyTruffle_Register_NULL", SRC_CS), NULL);
@@ -405,6 +349,7 @@ polyglot_typeid get_byte_array_typeid(uint64_t len) {
405349
return polyglot_array_typeid(polyglot_i8_typeid(), len);
406350
}
407351

352+
POLYGLOT_DECLARE_TYPE(uint32_t);
408353
/** to be used from Java code only; returns the type ID for a uint32_t array */
409354
polyglot_typeid get_uint32_t_array_typeid(uint64_t len) {
410355
return polyglot_array_typeid(polyglot_uint32_t_typeid(), len);

graalpython/com.oracle.graal.python.cext/src/modsupport.c

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,59 @@ static void init_upcall_PyTruffle_Arg_ParseTupleAndKeyword(void) {
8787
PyTruffle_Arg_ParseTupleAndKeywords = polyglot_get_member(PY_TRUFFLE_CEXT, polyglot_from_string("PyTruffle_Arg_ParseTupleAndKeywords", SRC_CS));
8888
}
8989

90-
typedef char* char_ptr_t;
91-
POLYGLOT_DECLARE_TYPE(char_ptr_t);
90+
/* primitive and pointer type declarations */
91+
92+
#define REGISTER_BASIC_TYPE(typename) \
93+
POLYGLOT_DECLARE_TYPE(typename); \
94+
NO_INLINE polyglot_typeid get_ ## typename ## _typeid(void) { \
95+
return polyglot_ ## typename ## _typeid(); \
96+
}
97+
98+
/* just a renaming to avoid name clash with Java types */
99+
typedef char char_t;
100+
typedef float float_t;
101+
typedef double double_t;
102+
103+
REGISTER_BASIC_TYPE(int64_t);
104+
REGISTER_BASIC_TYPE(int32_t);
105+
REGISTER_BASIC_TYPE(int16_t);
106+
REGISTER_BASIC_TYPE(int8_t);
107+
REGISTER_BASIC_TYPE(uint64_t);
108+
REGISTER_BASIC_TYPE(uint32_t);
109+
REGISTER_BASIC_TYPE(uint16_t);
110+
REGISTER_BASIC_TYPE(uint8_t);
111+
REGISTER_BASIC_TYPE(Py_complex);
112+
REGISTER_BASIC_TYPE(char_t);
113+
REGISTER_BASIC_TYPE(PyObject);
114+
REGISTER_BASIC_TYPE(float_t);
115+
REGISTER_BASIC_TYPE(double_t);
116+
REGISTER_BASIC_TYPE(Py_ssize_t);
117+
118+
/* For pointers, make them look like an array of size 1 such that it is
119+
possible to dereference the pointer by accessing element 0. */
120+
#define REGISTER_POINTER_TYPE(basetype, ptrtype) \
121+
typedef basetype* ptrtype; \
122+
POLYGLOT_DECLARE_TYPE(ptrtype); \
123+
NO_INLINE polyglot_typeid get_ ## ptrtype ## _typeid(void) { \
124+
return polyglot_array_typeid(polyglot_ ## basetype ## _typeid(), 1); \
125+
}
126+
127+
REGISTER_POINTER_TYPE(int64_t, int64_ptr_t);
128+
REGISTER_POINTER_TYPE(int32_t, int32_ptr_t);
129+
REGISTER_POINTER_TYPE(int16_t, int16_ptr_t);
130+
REGISTER_POINTER_TYPE(int8_t, int8_ptr_t);
131+
REGISTER_POINTER_TYPE(char_t, char_ptr_t);
132+
REGISTER_POINTER_TYPE(uint64_t, uint64_ptr_t);
133+
REGISTER_POINTER_TYPE(uint32_t, uint32_ptr_t);
134+
REGISTER_POINTER_TYPE(uint16_t, uint16_ptr_t);
135+
REGISTER_POINTER_TYPE(uint8_t, uint8_ptr_t);
136+
REGISTER_POINTER_TYPE(Py_complex, Py_complex_ptr_t);
137+
REGISTER_POINTER_TYPE(PyObject, PyObject_ptr_t);
138+
REGISTER_POINTER_TYPE(PyObject_ptr_t, PyObject_ptr_ptr_t);
139+
REGISTER_POINTER_TYPE(float_t, float_ptr_t);
140+
REGISTER_POINTER_TYPE(double_t, double_ptr_t);
141+
REGISTER_POINTER_TYPE(Py_ssize_t, Py_ssize_ptr_t);
142+
92143

93144
#define CallParseTupleAndKeywordsWithPolyglotArgs(__res__, __offset__, __args__, __kwds__, __fmt__, __kwdnames__) \
94145
va_list __vl; \

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/NativeCAPISymbols.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ public abstract class NativeCAPISymbols {
114114
private static final String FUN_GET_FLOAT_T_TYPEID = "get_float_t_typeid";
115115
private static final String FUN_GET_DOUBLE_T_TYPEID = "get_double_t_typeid";
116116
private static final String FUN_GET_PY_SSIZE_T_TYPEID = "get_Py_ssize_t_typeid";
117-
private static final String FUN_GET_VOID_PTR_T_TYPEID = "get_void_ptr_t_typeid";
117+
private static final String FUN_GET_PYOBJECT_PTR_T_TYPEID = "get_PyObject_ptr_t_typeid";
118+
private static final String FUN_GET_PYOBJECT_PTR_PTR_T_TYPEID = "get_PyObject_ptr_ptr_t_typeid";
118119
private static final String FUN_GET_CHAR_PTR_T_TYPEID = "get_char_ptr_t_typeid";
119120
private static final String FUN_GET_INT8_PTR_T_TYPEID = "get_int8_ptr_t_typeid";
120121
private static final String FUN_GET_INT16_PTR_T_TYPEID = "get_int16_ptr_t_typeid";

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiContext.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ public enum LLVMType {
742742
double_t,
743743
Py_ssize_t,
744744
Py_complex,
745-
void_ptr_t,
745+
PyObject_ptr_t,
746746
char_ptr_t,
747747
int8_ptr_t,
748748
int16_ptr_t,
@@ -753,13 +753,36 @@ public enum LLVMType {
753753
uint32_ptr_t,
754754
uint64_ptr_t,
755755
Py_complex_ptr_t,
756+
PyObject_ptr_ptr_t,
756757
float_ptr_t,
757758
double_ptr_t,
758759
Py_ssize_ptr_t;
759760

760761
public static String getGetterFunctionName(LLVMType llvmType) {
761762
CompilerAsserts.neverPartOfCompilation();
762-
return "get_" + llvmType.name() + "_typeid()";
763+
return "get_" + llvmType.name() + "_typeid";
764+
}
765+
766+
public static boolean isPointer(LLVMType llvmType) {
767+
switch (llvmType) {
768+
case PyObject_ptr_t:
769+
case char_ptr_t:
770+
case int8_ptr_t:
771+
case int16_ptr_t:
772+
case int32_ptr_t:
773+
case int64_ptr_t:
774+
case uint8_ptr_t:
775+
case uint16_ptr_t:
776+
case uint32_ptr_t:
777+
case uint64_ptr_t:
778+
case Py_complex_ptr_t:
779+
case PyObject_ptr_ptr_t:
780+
case float_ptr_t:
781+
case double_ptr_t:
782+
case Py_ssize_ptr_t:
783+
return true;
784+
}
785+
return false;
763786
}
764787

765788
public static boolean isPointerToPrimitive(LLVMType llvmType) {

0 commit comments

Comments
 (0)