Skip to content

Commit ba6b9bd

Browse files
Copilotgerlero
andcommitted
Fix error handling in C extension for unclosed comments
Co-authored-by: gerlero <[email protected]>
1 parent 4a9bbd8 commit ba6b9bd

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/foamlib/_files/_parsing/_skip_ext.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,22 @@ skip(PyObject *self, PyObject *args, PyObject *kwargs)
8585
if (contents_obj == NULL) {
8686
return NULL;
8787
}
88-
PyObject *error = PyObject_CallFunction(FoamFileDecodeError, "Ons",
89-
contents_obj, len, "*/");
88+
/* Call FoamFileDecodeError with keyword argument expected */
89+
PyObject *kwargs = Py_BuildValue("{s:s}", "expected", "*/");
90+
if (kwargs == NULL) {
91+
Py_DECREF(contents_obj);
92+
return NULL;
93+
}
94+
PyObject *args = Py_BuildValue("(On)", contents_obj, len);
95+
if (args == NULL) {
96+
Py_DECREF(contents_obj);
97+
Py_DECREF(kwargs);
98+
return NULL;
99+
}
100+
PyObject *error = PyObject_Call(FoamFileDecodeError, args, kwargs);
90101
Py_DECREF(contents_obj);
102+
Py_DECREF(args);
103+
Py_DECREF(kwargs);
91104
if (error != NULL) {
92105
PyErr_SetObject(FoamFileDecodeError, error);
93106
Py_DECREF(error);

0 commit comments

Comments
 (0)