Skip to content

Commit effcce1

Browse files
committed
Fix: Py_BuildValue should accept spaces in dict spec
1 parent 6284dc6 commit effcce1

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,14 @@ MUST_INLINE static PyObject* _PyTruffle_BuildValue(const char* format, va_list v
467467
break;
468468
case ':':
469469
case ',':
470+
case ' ':
470471
if (v->prev == NULL) {
471472
PyErr_SetString(PyExc_SystemError, "':' without '{' in Py_BuildValue");
472473
}
473474
break;
474475
default:
475-
fprintf(stderr, "error: unsupported format starting at %d : '%s'\n", format_idx, format);
476+
PyErr_SetString(PyExc_SystemError, "bad format char passed to Py_BuildValue");
477+
return NULL;
476478
}
477479
c = format[++format_idx];
478480
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,14 @@ def compile_module(self, name):
428428
cmpfunc=unhandled_error_compare
429429
)
430430

431+
test_Py_BuildValue = CPyExtFunction(
432+
lambda args: {args[1]: args[2], args[3]: args[4]},
433+
lambda: (
434+
('{O:O, O:O}', 'hello', 'world', 'foo', 'bar'),
435+
),
436+
resultspec="O",
437+
argspec="sOOOO",
438+
arguments=["char* fmt", "PyObject* a", "PyObject* b", "PyObject* c", "PyObject* d"],
439+
cmpfunc=unhandled_error_compare
440+
)
441+

0 commit comments

Comments
 (0)