Skip to content

Commit 6850d6a

Browse files
committed
[GR-23568] [GR-26784] [GR-27479] Support running Pandas tests.
PullRequest: graalpython/1374
2 parents 86182b4 + 4671fe8 commit 6850d6a

File tree

26 files changed

+697
-172
lines changed

26 files changed

+697
-172
lines changed

graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/ArgumentClinic.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,10 @@ enum ClinicConversion {
135135
* Corresponds to CPython's {@code Py_buffer} converter.
136136
*/
137137
Buffer,
138+
/**
139+
* Corresponds to CPython's {@code double} converter. Supports {@link #defaultValue()}, and
140+
* {@link #useDefaultForNone()}.
141+
*/
142+
Double,
138143
}
139144
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ int PyErr_WarnEx(PyObject *category, const char *text, Py_ssize_t stack_level) {
7272
NO_INLINE int PyErr_WarnFormat(PyObject *category, Py_ssize_t stack_level, const char *format, ...) {
7373
va_list args;
7474
va_start(args, format);
75-
PyObject* result = PyTruffle_Unicode_FromFormat(format, args);
75+
PyObject* result = PyUnicode_FromFormatV(format, args);
7676
va_end(args);
7777
return warn_unicode(category, result, stack_level, Py_None);
7878
}
7979

8080
int PyErr_ResourceWarning(PyObject *source, Py_ssize_t stack_level, const char *format, ...) {
8181
va_list args;
8282
va_start(args, format);
83-
PyObject* result = PyTruffle_Unicode_FromFormat(format, args);
83+
PyObject* result = PyUnicode_FromFormatV(format, args);
8484
va_end(args);
8585
return warn_unicode(PyExc_ResourceWarning, result, stack_level, source);
8686
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,6 @@ extern PyObject* wrapped_null;
382382

383383
/* internal functions to avoid unnecessary managed <-> native conversions */
384384

385-
/* STR */
386-
__attribute__((always_inline)) PyObject* PyTruffle_Unicode_FromFormat(const char *fmt, va_list va);
387-
388385
/* BYTES, BYTEARRAY */
389386
int bytes_buffer_getbuffer(PyBytesObject *self, Py_buffer *view, int flags);
390387
int bytearray_getbuffer(PyByteArrayObject *obj, Py_buffer *view, int flags);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ NO_INLINE
163163
PyObject* PyErr_Format(PyObject* exception, const char* fmt, ...) {
164164
va_list args;
165165
va_start(args, fmt);
166-
PyObject* formatted_msg = PyTruffle_Unicode_FromFormat(fmt, args);
166+
PyObject* formatted_msg = PyUnicode_FromFormatV(fmt, args);
167167
va_end(args);
168168
UPCALL_CEXT_VOID(_jls_PyErr_CreateAndSetException, native_to_java(exception), native_to_java(formatted_msg));
169169
return NULL;

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,24 @@ static void init_upcall_PyTruffle_Arg_ParseTupleAndKeyword(void) {
9696
}
9797

9898
/* 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-
99+
typedef void* void_ptr_t;
100+
typedef char char_t;
101+
typedef float float_t;
102+
typedef double double_t;
103+
typedef int int_t;
104+
typedef unsigned int uint_t;
105+
typedef long long_t;
106+
typedef unsigned long ulong_t;
107+
typedef long long longlong_t;
108+
typedef unsigned long long ulonglong_t;
109+
110+
REGISTER_BASIC_TYPE(void_ptr_t);
111+
REGISTER_BASIC_TYPE(int_t);
112+
REGISTER_BASIC_TYPE(uint_t);
113+
REGISTER_BASIC_TYPE(long_t);
114+
REGISTER_BASIC_TYPE(ulong_t);
115+
REGISTER_BASIC_TYPE(longlong_t);
116+
REGISTER_BASIC_TYPE(ulonglong_t);
103117
REGISTER_BASIC_TYPE(int64_t);
104118
REGISTER_BASIC_TYPE(int32_t);
105119
REGISTER_BASIC_TYPE(int16_t);
@@ -114,6 +128,7 @@ REGISTER_BASIC_TYPE(PyObject);
114128
REGISTER_BASIC_TYPE(float_t);
115129
REGISTER_BASIC_TYPE(double_t);
116130
REGISTER_BASIC_TYPE(Py_ssize_t);
131+
REGISTER_BASIC_TYPE(size_t);
117132

118133
/* For pointers, make them look like an array of size 1 such that it is
119134
possible to dereference the pointer by accessing element 0. */

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

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -230,97 +230,17 @@ PyObject * PyUnicode_FromStringAndSize(const char *u, Py_ssize_t size) {
230230
return to_sulong(polyglot_from_string_n(u, size, SRC_CS));
231231
}
232232

233-
#define AS_I64(__arg__) (polyglot_fits_in_i64((__arg__)) ? polyglot_as_i64((__arg__)) : (int64_t)(__arg__))
234-
235-
MUST_INLINE PyObject* PyTruffle_Unicode_FromFormat(const char *fmt, va_list va) {
236-
size_t fmt_size = strlen(fmt) + 1;
237-
char* fmtcpy = strdup(fmt);
238-
char* c = fmtcpy;
239-
240-
int remaining_space = 2047;
241-
char* buffer = (char*)calloc(sizeof(char), remaining_space + 1);
242-
char* full_buffer = buffer;
243-
244-
void *variable = NULL;
245-
char *allocated = NULL; // points to the same as variable, if it has to be free'd
246-
247-
while (c[0]) {
248-
if (c[0] == '%') {
249-
// we've reached the next directive, write until here
250-
c[0] = '\0';
251-
int bytes_written;
252-
if (variable != NULL) {
253-
bytes_written = snprintf(buffer, remaining_space, fmtcpy, AS_I64(variable));
254-
if (allocated != NULL) {
255-
free(allocated);
256-
allocated = NULL;
257-
}
258-
variable = NULL;
259-
} else {
260-
bytes_written = vsnprintf(buffer, remaining_space, fmtcpy, va);
261-
}
262-
remaining_space -= bytes_written;
263-
buffer += bytes_written;
264-
fmtcpy = c;
265-
c[0] = '%';
266-
267-
// now decide if we need to do something special with this directive
268-
PyObject* (*converter)(PyObject*) = NULL;
269-
switch (c[1]) {
270-
case 'A':
271-
// The conversion cases, these all use a function to convert the
272-
// PyObject* to a char* and they fall through
273-
converter = PyObject_ASCII;
274-
case 'U':
275-
if (converter == NULL) converter = PyObject_Str;
276-
case 'S':
277-
if (converter == NULL) converter = PyObject_Str;
278-
case 'R':
279-
if (converter == NULL) converter = PyObject_Repr;
280-
c[1] = 's';
281-
allocated = variable = as_char_pointer(converter(va_arg(va, PyObject*)));
282-
break;
283-
case 'd':
284-
break;
285-
case '%':
286-
// literal %
287-
break;
288-
case 'c':
289-
// This case should just treat it's argument as an integer
290-
c[1] = 'd';
291-
default:
292-
variable = va_arg(va, PyObject*);
293-
}
294-
// skip over next char, we checked it
295-
c += 1;
296-
}
297-
c += 1;
298-
}
299-
300-
// write the remaining buffer
301-
if (variable != NULL) {
302-
snprintf(buffer, remaining_space, fmtcpy, AS_I64(variable));
303-
if (allocated) {
304-
free(allocated);
305-
}
306-
} else {
307-
vsnprintf(buffer, remaining_space, fmtcpy, va);
308-
}
309-
310-
PyObject* result = PyUnicode_FromString(full_buffer);
311-
free(full_buffer);
312-
return result;
313-
}
314-
233+
typedef PyObject* (*unicode_fromformat_fun_t)(void* jstr, va_list va);
234+
UPCALL_TYPED_ID(PyTruffle_Unicode_FromFormat, unicode_fromformat_fun_t);
315235
PyObject* PyUnicode_FromFormatV(const char* format, va_list va) {
316-
return PyTruffle_Unicode_FromFormat(format, va);
236+
return _jls_PyTruffle_Unicode_FromFormat(polyglot_from_string(format, "ascii"), va);
317237
}
318238

319239
NO_INLINE
320240
PyObject* PyUnicode_FromFormat(const char* format, ...) {
321241
va_list args;
322242
va_start(args, format);
323-
PyObject* result = PyTruffle_Unicode_FromFormat(format, args);
243+
PyObject* result = _jls_PyTruffle_Unicode_FromFormat(polyglot_from_string(format, "ascii"), args);
324244
va_end(args);
325245
return result;
326246
}

graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/ConverterFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public enum Param {
9696
private static ConverterFactory BuiltinIndex;
9797
private static ConverterFactory BuiltinSliceIndex;
9898
private static ConverterFactory BuiltinNone;
99+
private static ConverterFactory BuiltinDouble;
99100

100101
public final String fullClassName;
101102
public final String className;
@@ -121,6 +122,8 @@ public static ConverterFactory getBuiltin(ArgumentClinic annotation) {
121122
return annotation.defaultValue().isEmpty() ? BuiltinString : BuiltinStringWithDefaultValue;
122123
case Int:
123124
return BuiltinInt;
125+
case Double:
126+
return BuiltinDouble;
124127
case CodePoint:
125128
return BuiltinCodePoint;
126129
case Buffer:
@@ -197,6 +200,7 @@ public static void initBuiltins(Elements elementUtils) throws ProcessingError {
197200
BuiltinString = forBuiltin(elementUtils, "JavaStringConverterNode");
198201
BuiltinStringWithDefaultValue = forBuiltin(elementUtils, "JavaStringConverterWithDefaultValueNode");
199202
BuiltinInt = forBuiltin(elementUtils, "JavaIntConversionNode");
203+
BuiltinDouble = forBuiltin(elementUtils, "JavaDoubleConversionNode");
200204
BuiltinCodePoint = forBuiltin(elementUtils, "CodePointConversionNode");
201205
BuiltinBuffer = forBuiltin(elementUtils, "BufferConversionNode");
202206
BuiltinIndex = forBuiltin(elementUtils, "IndexConversionNode");

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_err.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,20 @@ def compile_module(self, name):
198198
cmpfunc=unhandled_error_compare
199199
)
200200

201+
test_PyErr_Format_dS = CPyExtFunctionVoid(
202+
_reference_format,
203+
lambda: (
204+
(ValueError, "hello %d times %S", 10, "world"),
205+
(ValueError, "hello %c times %R", 95, "world"),
206+
),
207+
resultspec="O",
208+
argspec='OsiO',
209+
arguments=["PyObject* v", "char* msg", "int arg0", "PyObject* arg1"],
210+
resultval="NULL",
211+
callfunction="PyErr_Format",
212+
cmpfunc=unhandled_error_compare
213+
)
214+
201215
test_PyErr_PrintEx = CPyExtFunction(
202216
lambda args: None,
203217
lambda: (

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_unicode.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ def _reference_unicode_escape(args):
7575
return _codecs.unicode_escape_encode(args[0])[0]
7676

7777

78+
def _reference_fromformat(args):
79+
fmt = args[0]
80+
fmt_args = args[1:]
81+
# replace specifiers
82+
for s in ["%ld", "%li", "%lu", "%lld", "%lli", "%llu"]:
83+
fmt = fmt.replace(s, "%d")
84+
return fmt % fmt_args
85+
86+
7887
class CustomString(str):
7988
pass
8089

@@ -128,7 +137,7 @@ def compile_module(self, name):
128137
)
129138

130139
test_PyUnicode_FromFormat0 = CPyExtFunction(
131-
lambda args: args[0] % tuple(args[1:]),
140+
_reference_fromformat,
132141
lambda: (
133142
("hello, world!",),
134143
),
@@ -143,19 +152,17 @@ def compile_module(self, name):
143152
cmpfunc=unhandled_error_compare
144153
)
145154

146-
test_PyUnicode_FromFormat3 = CPyExtFunction(
147-
lambda args: args[0] % tuple(args[1:]),
155+
test_PyUnicode_FromFormat4 = CPyExtFunction(
156+
_reference_fromformat,
148157
lambda: (
149-
("word0: %s; word1: %s; int: %d", "hello", "world", 1234),
158+
("word0: %s; word1: %s; int: %d; long long: %lld", "hello", "world", 1234, 1234),
159+
("word0: %s; word1: %s; int: %d; long long: %lld", "hello", "world", 1234, (1<<44)+123),
150160
),
151-
code="""PyObject* wrap_PyUnicode_FromFormat3(char* fmt, char* arg0, char* arg1, int n) {
152-
return PyUnicode_FromFormat(fmt, arg0, arg1, n);
153-
}
154-
""",
161+
code="typedef long long longlong_t;",
155162
resultspec="O",
156-
argspec='sssi',
157-
arguments=["char* fmt", "char* arg0", "char* arg1", "int n"],
158-
callfunction="wrap_PyUnicode_FromFormat3",
163+
argspec='sssiL',
164+
arguments=["char* fmt", "char* arg0", "char* arg1", "int n", "longlong_t l"],
165+
callfunction="PyUnicode_FromFormat",
159166
cmpfunc=unhandled_error_compare
160167
)
161168

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_webbrowser.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*graalpython.lib-python.3.test.test_webbrowser.ImportTest.test_environment_preferred
2020
*graalpython.lib-python.3.test.test_webbrowser.ImportTest.test_get
2121
*graalpython.lib-python.3.test.test_webbrowser.ImportTest.test_register
22-
*graalpython.lib-python.3.test.test_webbrowser.ImportTest.test_synthesize
2322
*graalpython.lib-python.3.test.test_webbrowser.MozillaCommandTest.test_open
2423
*graalpython.lib-python.3.test.test_webbrowser.MozillaCommandTest.test_open_new
2524
*graalpython.lib-python.3.test.test_webbrowser.MozillaCommandTest.test_open_new_tab

0 commit comments

Comments
 (0)