[Xapian-devel] Re: [Xapian-commits] 7990: trunk/xapian-core/trunk/xapian-core/bin/ trunk/xapian-core/tests/harness/

Olly Betts olly at survex.com
Fri Mar 30 05:34:21 BST 2007


On Fri, Mar 30, 2007 at 01:53:42PM +1000, Mark Hammond wrote:
> It is a little painful :(  FormatMessage() works for win32 defined error
> codes.  errno values are frustratingly similar, but not exactly the same
> (and obviously the win32 set is much larger).  This means that in general,
> you can't use FormatMessage with a value obtained from errno (or the crt in
> general) - only with a value from the API.  Similarly, using strerror() on
> an API error code might not give the correct results, even for low error
> values.
>
> Then we have sockets.  Although some of the winsock API tries to look like
> posix, it does not use the crt errno at all.

Looking at the winsock.h header in mingw, the "WSA" error codes are all
at least 10000.  So it would be easy enough to decode real errno values
with strerror() while handling the other values with something else.

If you're talking about sticking error codes which collide with errno
values in the "errno" field of Xapian::Error objects, that way madness
surely lies!  Catchers of Xapian::Error (not unreasonably) expect to be
able to decode the errno field with strerror().  And strerror() would
give an entirely irrelevant message if we start sticking other integer
error codes there with overlapping ranges.

It would be better to just ignore the errno field in such cases, and
instead convert any non-errno error code to a string and append it to
the message field at the time the Error object is built and thrown.
Or convert the error code to a suitable errno value if one exists
(for example, I strongly suspect WSAEINTR has the same meaning as
EINTR - they even have the same value modulo 10000!)

> All error results come from WSAGetLastError() - and as a result
> FormatMessage() must always be used.  I've no idea what mingw does
> with this.

The same as MSVC I imagine - mingw generally just wraps the functions in
MSVCRT.DLL directly.

Cheers,
    Olly



More information about the Xapian-devel mailing list