mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
python: Call PyErr_Clear() on non-error paths out of the Python bindings.
We also need to be more careful about PyString_FromString and similar functions returning NULL on failure. Currently we don't check this every time. This commit adds more checks, but is still not complete.
This commit is contained in:
6
TODO
6
TODO
@@ -563,12 +563,6 @@ Write an extension for mc that would let people browse into
|
||||
filesystems. See
|
||||
http://repo.or.cz/w/midnight-commander.git/tree/HEAD:/misc/ext.d
|
||||
|
||||
Python
|
||||
------
|
||||
|
||||
It seems as if we should call PyErr_Clear() somewhere in every
|
||||
Python binding.
|
||||
|
||||
Improvements in virt-log
|
||||
------------------------
|
||||
|
||||
|
||||
@@ -455,7 +455,8 @@ put_table (char * const * const argv)
|
||||
pr " py_r = PyString_FromString (r);\n";
|
||||
pr "#else\n";
|
||||
pr " py_r = PyUnicode_FromString (r);\n";
|
||||
pr "#endif\n"
|
||||
pr "#endif\n";
|
||||
pr " if (py_r == NULL) goto out;\n";
|
||||
| RConstOptString _ ->
|
||||
pr " if (r) {\n";
|
||||
pr "#ifdef HAVE_PYSTRING_ASSTRING\n";
|
||||
@@ -466,14 +467,16 @@ put_table (char * const * const argv)
|
||||
pr " } else {\n";
|
||||
pr " Py_INCREF (Py_None);\n";
|
||||
pr " py_r = Py_None;\n";
|
||||
pr " }\n"
|
||||
pr " }\n";
|
||||
pr " if (py_r == NULL) goto out;\n";
|
||||
| RString _ ->
|
||||
pr "#ifdef HAVE_PYSTRING_ASSTRING\n";
|
||||
pr " py_r = PyString_FromString (r);\n";
|
||||
pr "#else\n";
|
||||
pr " py_r = PyUnicode_FromString (r);\n";
|
||||
pr "#endif\n";
|
||||
pr " free (r);\n"
|
||||
pr " free (r);\n";
|
||||
pr " if (py_r == NULL) goto out;\n";
|
||||
| RStringList _ ->
|
||||
pr " py_r = put_string_list (r);\n";
|
||||
pr " guestfs_int_free_string_list (r);\n"
|
||||
@@ -492,10 +495,18 @@ put_table (char * const * const argv)
|
||||
pr "#else\n";
|
||||
pr " py_r = PyBytes_FromStringAndSize (r, size);\n";
|
||||
pr "#endif\n";
|
||||
pr " free (r);\n"
|
||||
pr " free (r);\n";
|
||||
pr " if (py_r == NULL) goto out;\n";
|
||||
);
|
||||
|
||||
(* As this is the non-error path, clear the Python error
|
||||
* indicator flag in case it was set accidentally somewhere in
|
||||
* the function. Since we are not returning an error indication
|
||||
* to the caller, having it set would risk the error popping up
|
||||
* at random later in the interpreter.
|
||||
*)
|
||||
pr "\n";
|
||||
pr " PyErr_Clear ();\n";
|
||||
pr " out:\n";
|
||||
|
||||
List.iter (
|
||||
|
||||
Reference in New Issue
Block a user