[Python-checkins] r59696 - in python/trunk: Misc/NEWS Python/dynload_win.c

amaury.forgeotdarc python-checkins at python.org
Fri Jan 4 03:04:16 CET 2008


Author: amaury.forgeotdarc
Date: Fri Jan 4 03:04:15 2008
New Revision: 59696
Modified:
 python/trunk/Misc/NEWS
 python/trunk/Python/dynload_win.c
Log:
Partial port of r59682 from py3k.
On Windows, when import fails to load a dll module, the message says
"error code 193" instead of a more informative text.
It turns out that FormatMessage needs additional parameters for some error codes.
For example: 193 means "%1 is not a valid Win32 application".
Since it is impossible to know which parameter to pass, we use 
FORMAT_MESSAGE_IGNORE_INSERTS to get the raw message, which is still better
than the number.
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Fri Jan 4 03:04:15 2008
@@ -12,6 +12,10 @@
 Core and builtins
 -----------------
 
+- Improve some exception messages when Windows fails to load an extension
+ module. Now we get for example '%1 is not a valid Win32 application' instead
+ of 'error code 193'.
+
 - Bug #1481296: Fixed long(float('nan'))!=0L.
 
 - Issue #1640: Added math.isinf(x), math.isnan(x) and math.copysign(x, y)
Modified: python/trunk/Python/dynload_win.c
==============================================================================
--- python/trunk/Python/dynload_win.c	(original)
+++ python/trunk/Python/dynload_win.c	Fri Jan 4 03:04:15 2008
@@ -194,7 +194,8 @@
 			errorCode = GetLastError();
 
 			theLength = FormatMessage(
-				FORMAT_MESSAGE_FROM_SYSTEM, /* flags */
+				FORMAT_MESSAGE_FROM_SYSTEM |
+				FORMAT_MESSAGE_IGNORE_INSERTS, /* flags */
 				NULL, /* message source */
 				errorCode, /* the message (error) ID */
 				0, /* default language environment */


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /