Permalink
Browse files

[WIP] Windows port: use the correct crt for Python 2.5, 2.6, 2.7 and 3.2

A more appropriate solution would be to decuce this in python.m4,
but let's work around this limitation for now.

https://bugzilla.gnome.org/show_bug.cgi?id=620566
  • Loading branch information...
1 parent cc3655e commit 4ba16dca73c8efaec2bb3b47cd10dd90a2ab9d4d @dieterv committed Sep 5, 2011
Showing with 26 additions and 13 deletions.
  1. +26 −13 giscanner/giscannermodule.c
@@ -31,6 +31,7 @@
#include "grealpath.h"
#ifdef _WIN32
+#include <stdint.h>
#include <fcntl.h>
#include <io.h>
#define WIN32_LEAN_AND_MEAN
@@ -411,37 +412,49 @@ pygi_source_scanner_parse_file (PyGISourceScanner *self,
#ifdef _WIN32
/* The file descriptor passed to us is from the C library Python
- * uses. That is msvcr71.dll at least for Python 2.5. This code, at
- * least if compiled with mingw, uses msvcrt.dll, so we cannot use
- * the file descriptor directly. So perform appropriate magic.
+ * uses. That is msvcr71.dll for Python 2.5 and msvcr90.dll for
+ * Python 2.6, 2.7, etc. This code, at least if compiled with mingw, uses
+ * msvcrt.dll, so we cannot use the file descriptor directly. So
+ * perform appropriate magic.
*/
{
- HMODULE msvcr71;
- int (*p__get_osfhandle) (int);
+#if defined(PY_MAJOR_VERSION) && PY_MAJOR_VERSION==2 && PY_MINOR_VERSION==5
+#define PYTHON_MSVCRXX_DLL "msvcr71.dll"
+#elif defined(PY_MAJOR_VERSION) && PY_MAJOR_VERSION==2 && PY_MINOR_VERSION==6
+#define PYTHON_MSVCRXX_DLL "msvcr90.dll"
+#elif defined(PY_MAJOR_VERSION) && PY_MAJOR_VERSION==2 && PY_MINOR_VERSION==7
+#define PYTHON_MSVCRXX_DLL "msvcr90.dll"
+#elif defined(PY_MAJOR_VERSION) && PY_MAJOR_VERSION==3 && PY_MINOR_VERSION==2
+#define PYTHON_MSVCRXX_DLL "msvcr90.dll"
+#else
+#error This Python version not handled
+#endif
+ HMODULE msvcrxx;
+ intptr_t (*p__get_osfhandle) (int);
HANDLE handle;
- msvcr71 = GetModuleHandle ("msvcr71.dll");
- if (!msvcr71)
+ msvcrxx = GetModuleHandle (PYTHON_MSVCRXX_DLL);
+ if (!msvcrxx)
{
- g_print ("No msvcr71.dll loaded.\n");
+ g_print ("No " PYTHON_MSVCRXX_DLL " loaded.\n");
return NULL;
}
- p__get_osfhandle = GetProcAddress (msvcr71, "_get_osfhandle");
+ p__get_osfhandle = (intptr_t (*) (int)) GetProcAddress (msvcrxx, "_get_osfhandle");
if (!p__get_osfhandle)
{
- g_print ("No _get_osfhandle found in msvcr71.dll.\n");
+ g_print ("No _get_osfhandle found in " PYTHON_MSVCRXX_DLL ".\n");
return NULL;
}
- handle = p__get_osfhandle (fd);
+ handle = (HANDLE) p__get_osfhandle (fd);
if (!p__get_osfhandle)
{
- g_print ("Could not get OS handle from msvcr71 fd.\n");
+ g_print ("Could not get OS handle from " PYTHON_MSVCRXX_DLL " fd.\n");
return NULL;
}
- fd = _open_osfhandle (handle, _O_RDONLY);
+ fd = _open_osfhandle ((intptr_t) handle, _O_RDONLY);
if (fd == -1)
{
g_print ("Could not open C fd from OS handle.\n");

0 comments on commit 4ba16dc

Please sign in to comment.