[Python-checkins] r45925 - in python/trunk: Lib/tempfile.py Lib/test/test_os.py Misc/NEWS Modules/posixmodule.c

"Martin v. Löwis" martin at v.loewis.de
Sun May 7 20:58:04 CEST 2006


M.-A. Lemburg wrote:
> Right. The idea used in errno is to let the Windows
> error code override the value possibly defined in the
> C lib (that's why the order of the inscode() in errno
> matters). This is based on:
> 
> http://msdn.microsoft.com/library/en-us/winsock/winsock/error_codes_errno_h_errno_and_wsagetlasterror_2.asp?frame=true

You mean, "The idea used in WSA"?

If I understand this correctly, the idea is to define

#define errno WSAGetLastError()

(the article actually defines that as "WSAGetLastError",
 but that is wrong, as WSAGetLastError is a function, and
 errno is not)

I can't see how it would help to define such a macro.
We are talking about Python code here, not C code.

Can you please provide a specific patch implementing
your proposal? I don't get the idea.

> Perhaps we should have hybrid error code objects that compare
> equal to more than one integer code, but otherwise behave like
> integers ?!

That would be very hacky. One thing I could imagine implementing
is to put two values into WindowsError:
- errno, with possible values from errno.h (which Microsoft
  calls "DOS error codes")
- winerror, with possible values from winerror.h.

That way, on creating a directory that already exists, you
would get a WindowsError with errno==EEXIST (17) and
winerror==ERROR_ALREADY_EXISTS (183).

That would make my recent library changes unnecessary, and also
not require changes to applications that currently check
OSError.errno. It would have two problems:
- somebody would have to provide the mapping table from
  Win32 error codes to "DOS error codes". Microsoft has
  that in the function _dosmaperr, however, that function
  is not exported from the CRT.
- code that currently catches WindowsError and looks into
  the errno value would break, as that would not contain
  Win32 error codes anymore.

Regards,
Martin


More information about the Python-checkins mailing list