]> granicus.if.org Git - python/commitdiff
Partial port of r59682 from py3k.
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Fri, 4 Jan 2008 02:04:15 +0000 (02:04 +0000)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Fri, 4 Jan 2008 02:04:15 +0000 (02:04 +0000)
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.

Misc/NEWS
Python/dynload_win.c

index bd98e38fb2cf3a3ac861ce6b72ccb3a864c21cf9..fc1c810e3bb9cd1a79842a8f15573caed95b956a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,10 @@ What's New in Python 2.6 alpha 1?
 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)
index fc641b9ff9e2d034186cc5097ee74f7c4f60aecc..98ebccb2defd649a80af26570ef0d56209bbcf38 100644 (file)
@@ -194,7 +194,8 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
                        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 */