Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

WINNT/9X patch for errors.c

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


tismer at appliedbiometrics

Apr 21, 1999, 3:51 AM

Post #1 of 2 (137 views)
Permalink
WINNT/9X patch for errors.c

This is a multi-part message in MIME format.
--------------4F9C6C08BFFF7FF3DC1C3963
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

This is a patch to errors.c which gives the correct POSIX
error messages for WinNT/9X.

Reason: os.listdir("nonexistent") gave
OSError: [Errno 3] No such process

Problem caused by:
The standard function strerror is supposed to give an error message for
a system error. Under Windows, these are DOS messages, not POSIX.
They don't match completely.

Solution:
Instead of strerror, FormatMessage is used. This function
has an option to return standard system messages.

This will now give the correct message.
The messages are those which appear to be natural under
Windows: kernel32.dll defines them all in the default
language of your operating system

Guido van Rossum wrote:
>
> Christian,
>
> I just tried your code on Windows, and I noticed a missing feature.
> Python now adds the filename (when it is known) to the error message;
> your code doesn't do this.

Solved this, too. My code was ok, but the filename moved into
the next line. The returned message contains a CR/LF sequence
and also a dot. I'm removing this now, and it looks good.

ciao - chris

--
Christian Tismer :^) <mailto:tismer [at] appliedbiometrics>
Applied Biometrics GmbH : Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101 : *Starship* http://starship.python.net
10553 Berlin : PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF
we're tired of banana software - shipped green, ripens at home
--------------4F9C6C08BFFF7FF3DC1C3963
Content-Type: text/plain; charset=us-ascii;
name="errors.c.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="errors.c.diff"

*** /w/orion/install/cvsroot/python/dist/src/python/errors.c Mon Dec 21 19:33:30 1998
--- /w/orion/install/python1.5/errors.c Wed Apr 21 12:13:40 1999
***************
*** 49,54 ****
--- 49,59 ----
#endif
#endif

+ #ifdef _WIN32
+ #include "windows.h"
+ #include "winbase.h"
+ #endif
+
void
PyErr_Restore(type, value, traceback)
PyObject *type;
***************
*** 291,297 ****
--- 296,319 ----
if (i == 0)
s = "Error"; /* Sometimes errno didn't get set */
else
+ #ifndef _WIN32
s = strerror(i);
+ #else
+ {
+ int len = FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, // no message source
+ i,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ (LPTSTR) &s,
+ 0, // size not used
+ NULL ); // no args
+ // remove trailing cr/lf and dots
+ while(len && s[len-1] <= '.') s[--len] = '\0' ;
+ }
+ #endif
if (filename != NULL && Py_UseClassExceptionsFlag)
v = Py_BuildValue("(iss)", i, s, filename);
else
***************
*** 300,305 ****
--- 322,330 ----
PyErr_SetObject(exc, v);
Py_DECREF(v);
}
+ #ifdef _WIN32
+ LocalFree(s);
+ #endif
return NULL;
}


--------------4F9C6C08BFFF7FF3DC1C3963--


tismer at appliedbiometrics

Apr 21, 1999, 3:58 AM

Post #2 of 2 (138 views)
Permalink
WINNT/9X patch for errors.c [In reply to]

Sorry, I forgot to change this:

Instead of _WIN32, one should use MS_WIN32 which has the
same meaning, but is the correct convention for Python.
Please adjust the 3 places in the diff from

> + #ifndef _WIN32

to

> + #ifndef MS_WIN32

(it has no other effect, just a matter of style)

ciao - chris

--
Christian Tismer :^) <mailto:tismer [at] appliedbiometrics>
Applied Biometrics GmbH : Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101 : *Starship* http://starship.python.net
10553 Berlin : PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF
we're tired of banana software - shipped green, ripens at home

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.