Skip to content

Commit 49fa1f9

Browse files
committed
Fix: allow NULL or empty arg format.
1 parent 9798d3d commit 49fa1f9

File tree

1 file changed

+20
-2
lines changed
  • graalpython/com.oracle.graal.python.cext/src

1 file changed

+20
-2
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ PyObject* PyObject_CallObject(PyObject* callable, PyObject* args) {
227227

228228
PyObject* PyObject_CallFunction(PyObject* callable, const char* fmt, ...) {
229229
PyObject* args;
230+
231+
if (fmt == NULL || fmt[0] == '\0') {
232+
return _PyObject_CallNoArg(callable);
233+
}
234+
230235
CALL_WITH_VARARGS(args, Py_BuildValue, 2, fmt);
231236
if (strlen(fmt) < 2) {
232237
PyObject* singleArg = args;
@@ -240,6 +245,11 @@ PyObject* PyObject_CallFunction(PyObject* callable, const char* fmt, ...) {
240245

241246
PyObject* _PyObject_CallFunction_SizeT(PyObject* callable, const char* fmt, ...) {
242247
PyObject* args;
248+
249+
if (fmt == NULL || fmt[0] == '\0') {
250+
return _PyObject_CallNoArg(callable);
251+
}
252+
243253
CALL_WITH_VARARGS(args, Py_BuildValue, 2, fmt);
244254
if (strlen(fmt) < 2) {
245255
PyObject* singleArg = args;
@@ -263,13 +273,21 @@ PyObject* PyObject_CallFunctionObjArgs(PyObject *callable, ...) {
263273
UPCALL_ID(PyObject_CallMethod);
264274
PyObject* PyObject_CallMethod(PyObject* object, const char* method, const char* fmt, ...) {
265275
PyObject* args;
266-
CALL_WITH_VARARGS(args, Py_BuildValue, 3, fmt);
276+
if (fmt == NULL || fmt[0] == '\0') {
277+
args = Py_None;
278+
} else {
279+
CALL_WITH_VARARGS(args, Py_BuildValue, 3, fmt);
280+
}
267281
return UPCALL_CEXT_O(_jls_PyObject_CallMethod, native_to_java(object), polyglot_from_string(method, SRC_CS), native_to_java(args));
268282
}
269283

270284
PyObject* _PyObject_CallMethod_SizeT(PyObject* object, const char* method, const char* fmt, ...) {
271285
PyObject* args;
272-
CALL_WITH_VARARGS(args, Py_BuildValue, 3, fmt);
286+
if (fmt == NULL || fmt[0] == '\0') {
287+
args = Py_None;
288+
} else {
289+
CALL_WITH_VARARGS(args, Py_BuildValue, 3, fmt);
290+
}
273291
return UPCALL_CEXT_O(_jls_PyObject_CallMethod, native_to_java(object), polyglot_from_string(method, SRC_CS), native_to_java(args));
274292
}
275293

0 commit comments

Comments
 (0)