[Patches] [ python-Patches-505846 ] pyport.h, Wince and errno getter/setter

noreply@sourceforge.net noreply@sourceforge.net
Sat, 19 Jan 2002 12:52:11 -0800


Patches item #505846, was opened at 2002-01-19 12:13
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=505846&group_id=5470

Category: Core (C code)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Brad Clements (bkc)
Assigned to: Nobody/Anonymous (nobody)
Summary: pyport.h, Wince and errno getter/setter

Initial Comment:
Most of the remaining Windows CE diffs are due to the 
lack of errno on Windows CE. There are other OS's that 
do not have errno (but they have a workalike method).

At first I had simply commented out all references in 
the code to errno, but that quickly became unworkable. 

Wince and NetWare use a function to set the per-
thread "errno" value. Although errno #defines  (like 
ERANGE) are not defined for Wince, they are defined 
for NetWare. Removing references to errno would 
artificially hobble the NetWare port.

These platforms also use a function to retrieve the 
current errno value.

The attached diff for pyport.h attempts to standardize 
the access method for errno (or it's work-alike) by 
providing SetErrno(), ClearErrno() and GetErrno() 
macros.

ClearErrno() is SetErrno(0)

I've found and changed all direct references to errno 
to use these macros. This patch must be submitted 
before the patches for other modules.

--

I see two negatives with this approach:

1. It will be a pain to think GetErrno() instead 
of "errno" when modifying/writing new code.

2. Extension modules will need access to pyport.h for 
the target platform.

In the worst case, directly referencing errno instead 
of using the macros will break only those platforms 
for which the macros do something different. That is, 
Wince and NetWare.

--

An alternative spelling/capitalization of these macros 
might make them more appealing. Feel free to make a 
suggestion.


--

It's probably incorrect for me to use SetErrno() as a 
function, such as

   SetErrno(1);

I think the semi-colon is not needed, but wasn't 
entirely certain. On better advice, I will fix these 
statements in the remaining source files if this patch 
is accepted.



----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2002-01-19 12:52

Message:
Logged In: YES 
user_id=31435

All identifiers defined in pyport.h must begin with "Py_".  
pyport.h is (and must be) #include'd by extension modules, 
and we need the prefix to avoid stomping on their 
namespace, and to make clear (to them and to us) that the 
gimmicks are part of Python's portability layer.  A name 
like "SetErrno" is certain to conflict with some other 
package's attempt to worm around errno problems; Py_SetErrno
() is not.  Agree with Neal's final suggestion about 
dealing with  semicolons.

----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2002-01-19 12:28

Message:
Logged In: YES 
user_id=33168

Typically, the semi-colon problem is dealt with as in
Py_SET_ERANGE_IF_OVERFLOW.

So, 

#define SetErrno(X) do { SetLastError(X); } while (0)

I don't think (but can't remember if) there is any problem
for single statements like you have.  You could probably do:

#ifndef MS_WINCE
#define SetErrno(X) errno = (X)     /* note no ; */
#else
#define SetErrno(X) SetLastError(X) /* note no ; */
#endif


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=505846&group_id=5470