[Python-checkins] r45925 - in python/trunk: Lib/tempfile.py Lib/test/test_os.py Misc/NEWS Modules/posixmodule.c
M.-A. Lemburg
mal at egenix.com
Sun May 7 20:01:57 CEST 2006
Martin v. Löwis wrote:
> M.-A. Lemburg wrote:
>> That's not what I meant: in errno, many WSA windows error codes
>> are aliased to their corresponding Unix error codes to
>> enhance portability across platforms.
>
> Can you please explain how such aliasing could work? errno can
> only have one value: either 183, or 17, but not both.
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
>> I don't know where ERROR_ALREADY_EXISTS is defined and
>> how it relates to the WSA codes, but since EEXIST doesn't
>> have a corresponding, it's probably a good idea to alias
>> EEXIST to ERROR_ALREADY_EXISTS and use that in tempfile.py
>> for both Windows and Unix instead of adding another except
>> clause.
>
> ERROR_ALREADY_EXISTS is defined in winerror.h, and it is possible
> result of the GetLastError system call.
>
> I don't understand the fragment "but since EEXIST doesn't have a
> corresponding": A corresponding what?
Sorry, it should read "corresponding WSA alias", ie. there's
no WSAEEXIST, probably because Windows sockets don't support
domain sockets.
> You mean, I should define EEXIST to have the value of 183, instead
> of having the value 17? That's certainly not a good idea. First,
> EEXIST should map to either ERROR_FILE_EXISTS (80) or
> ERROR_ALREADY_EXISTS (183), depending on context. Furthermore,
> the C library will still put its own value (17) into errno.
Ah, ok. I didn't know that they use different error values.
That makes things complicated.
>>> In what sense would the backwards compatibility be improved ?!
>> I suppose that the code used to raise an OSError with
>> EEXIST error code before the change to use Win32 APIs
>> on Windows.
>
> Correct. It now raises WindowsError instead.
>
>> With the alias, existing code looking for EEXIST on Windows
>> will continue to work without change.
>
> I still cannot see how this could work, at least not in a way
> that wouldn't break something else.
Indeed.
Perhaps we should have hybrid error code objects that compare
equal to more than one integer code, but otherwise behave like
integers ?!
E.g.
# Error code objects
class ErrorCode(int):
values = ()
def __new__(cls, basevalue, *aliasvalues):
return int.__new__(cls, basevalue)
def __init__(self, basevalue, *aliasvalues):
self.values = (basevalue,) + aliasvalues
def __cmp__(self, other):
if other in self.values:
return 0
if other < self.values:
return 1
else:
return -1
EEXISTS = ErrorCode(17, 183, 80)
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, May 07 2006)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::
More information about the Python-checkins
mailing list