Because C and OCaml use different implementations of stdio, and
because C stdout is not line-buffered, we can get mixed up debugging
messages.
Partially fix this by using fflush (stdout) after printing C debugging
messages (this doesn't completely fix it because we'd have to do the
same in OCaml code too).
This slows down debugging output, but it's only used when debugging so
we don't care about that.
---
src/librpm-c.c | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/src/librpm-c.c b/src/librpm-c.c
index fc847d6..3bd25a2 100644
--- a/src/librpm-c.c
+++ b/src/librpm-c.c
@@ -202,8 +202,11 @@ supermin_rpm_installed (value rpmv, value pkgv)
caml_raise_not_found ();
count = rpmdbGetIteratorCount (iter);
- if (data.debug >= 2)
- printf ("supermin: rpm: installed: %d occurrences for '%s'\n",
count, String_val (pkgv));
+ if (data.debug >= 2) {
+ printf ("supermin: rpm: installed: %d occurrences for '%s'\n",
+ count, String_val (pkgv));
+ fflush (stdout);
+ }
rv = caml_alloc (count, 0);
i = 0;
@@ -287,8 +290,11 @@ supermin_rpm_pkg_requires (value rpmv, value pkgv)
caml_raise_not_found ();
count = rpmdbGetIteratorCount (iter);
- if (data.debug >= 2)
- printf ("supermin: rpm: pkg_requires: %d occurrences for '%s'\n",
count, String_val (pkgv));
+ if (data.debug >= 2) {
+ printf ("supermin: rpm: pkg_requires: %d occurrences for '%s'\n",
+ count, String_val (pkgv));
+ fflush (stdout);
+ }
if (count != 1)
librpm_raise_multiple_matches (count);
@@ -351,8 +357,11 @@ supermin_rpm_pkg_whatprovides (value rpmv, value pkgv)
caml_raise_not_found ();
count = rpmdbGetIteratorCount (iter);
- if (data.debug >= 2)
- printf ("supermin: rpm: pkg_whatprovides: %d occurrences for
'%s'\n", count, String_val (pkgv));
+ if (data.debug >= 2) {
+ printf ("supermin: rpm: pkg_whatprovides: %d occurrences for
'%s'\n",
+ count, String_val (pkgv));
+ fflush (stdout);
+ }
rv = caml_alloc (count, 0);
i = 0;
@@ -398,8 +407,11 @@ supermin_rpm_pkg_filelist (value rpmv, value pkgv)
caml_raise_not_found ();
count = rpmdbGetIteratorCount (iter);
- if (data.debug >= 2)
- printf ("supermin: rpm: pkg_filelist: %d occurrences for '%s'\n",
count, String_val (pkgv));
+ if (data.debug >= 2) {
+ printf ("supermin: rpm: pkg_filelist: %d occurrences for '%s'\n",
+ count, String_val (pkgv));
+ fflush (stdout);
+ }
if (count != 1)
librpm_raise_multiple_matches (count);
--
2.5.0