[sword-devel] Transport status reporting

Jaak Ristioja jaak at ristioja.ee
Wed Jul 31 03:09:53 MST 2013


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi!

Yesterday, I again found myself writing safety workarounds around
Sword status reporting, i.e. for the
sword::StatusReporter::statusUpdate() callback, which for some reason
uses floating point doubles instead of integers. Digging my way into
the depths of Sword I noticed that this was implemented this way
probably due to libcurl providing similar callbacks with doubles.
Looking at the libcurl source code, I noticed that for their upcoming
version 7.32.0 they have implemented a better callback for progress.
For reference, see

  https://github.com/bagder/curl/commit/12d01cb6

It should be possible to use some

  #include <curl/curlver.h>
  #if LIBCURL_VERSION_NUM >= 0x072000

magic in Sword to provide similar callback alternatives for Sword
programs. I suggest that the sword::StatusReporter class be extended
with this method:

  virtual void update(size_t dlTotal, size_t dlNow);

keeping the older statusUpdate(double, double) as well. When progress
is reported by the new curl callback, both update() and statusUpdate()
should be called for backwards compatibility.

If using curl 7.32.0 or later, for the update() call, curl_off_t
arguments (signed integers of some width) are converted to size_t, and
for statusUpdate() call they are converted to double().

If using earlier versions of curl, for the update() call, double
arguments are converted to size_t, and for statusUpdate() call they
are passed as-is.

As you can easily see, both old and new approaches in curl have its
deficiencies, since both double and curl_off_t are both signed. An
additional caveats come from conversions to or/and from doubles and
operations on them, which might involve using the FPU (integer
operations are much faster on CPU cores), might yield imprecise
values, invalid values or floating point exceptions. The latter might
just crash the program in some circumstances. I haven't time to
formally analyze whether some or all of these issues affect BibleTime,
but our code for statusUpdate() has workarounds in case the passed
doubles are negative, if (dlTotal == 0.0), if (dlNow > dlTotal), etc.
I guess we could also call fpclassify() etc to work around other
corner cases, but in principle, this is not what frontend developers
should be dealing with, so I suggest a proper update(size_t done,
size_t total) interface be defined, where total > 0u and done <= total
always hold.

The old statusUpdate(double, double) interface should be deprecated.

Blessings,
Jaak

PS: I'm not sure whether we should to delay the 1.7.0 release for
this, although this issue might involve an API change.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.20 (GNU/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