summaryrefslogtreecommitdiff
path: root/giscanner/giscannermodule.c
diff options
context:
space:
mode:
authorTor Lillqvist <tml@novell.com>2008-08-27 13:33:21 +0000
committerTor Lillqvist <tml@src.gnome.org>2008-08-27 13:33:21 +0000
commitdf824ba7d2710621aff9dfa46be7d87addd73500 (patch)
tree37a0b9678ba5b774644bbab633040f18ee990095 /giscanner/giscannermodule.c
parent1ea33b3637536ab6b9c5ae6373fa5e6b12422304 (diff)
downloadgobject-introspection-df824ba7d2710621aff9dfa46be7d87addd73500.tar.gz
Make g-ir-scanner work on Windows. Still problems with the typelib code.
2008-08-27 Tor Lillqvist <tml@novell.com> Make g-ir-scanner work on Windows. Still problems with the typelib code. Changes okayed by jdahlin. * configure.ac: Check for Windows, set Automake conditional OS_WIN32. Change backslashes to forward slashes in pyexecdir to avoid shell quoting issues * girepository/Makefile.am: Use -no-undefined so that libtool agrees to build a shared library on Windows. * girepository/girparser.c (backtrace_stderr): No backtrace() on Windows. Empty implementation on Windows so far. * girepository/gtypelib.c (g_typelib_check_sanity): Give more informative error message for the assertion failures. Tell also what the expected size of the struct is. Check all sizes first and fail afterwards if at least one size was different from expected. * tools/Makefile.am: Reorder libraries into proper logical dependency order. * tools/generate.c: Don't include <dlfcn.h>, not used. * giscanner/Makefile.am: On Windows, link with the Python library, and install the module DLL as _giscanner.pyd. Remove the unnecessary import library and libtool library that libtool has installed. * giscanner/scannerlexer.l: Recognize the gcc __attribute__ syntax and just skip it. Recognize also two "l" suffixes for long long constants. Recognize also __inline__. * giscanner/grealpath.h (g_realpath): Implement on Windows, using GetFullPathName(). As such, GetFullPathName() does more than the UNIX realpath(). It also changes relative paths into absolute paths. But for our purposes that shouldn't matter. * giscanner/giscannermodule.c (pygi_source_scanner_parse_file): On Windows the file descriptor passed to us is from Python. Python Python2.5 uses the msvcr71.dll C library, while mingw-built code uses msvcrt.dll. On Windows, file descriptors are specific to which C library is used. So we must find out what underlying OS handle corresponds to the file descriptor Python passes us, and then make that into a file descriptor valid for the C library this code uses. * giscanner/sourcescanner.py (_parse): Don't need to bypass __attribute__ as the lexer now handles it. The definition as empty was ineffective for mingw anyway, as mingw's _mingw.h undefines __attribute__. Close the temp file before unlinking it. * giscanner/cgobject.py: Use correct library name for the gobject DLL on Windows. * gir/Makefile.am: Must pass the full basename of the DLLs on Windows to g-ir-scanner. It's a bit ugly that we have to "know" that the names of the GLib DLLs are like libglib-2.0-0.dll, but in reality they won't change, until there is a GLib 3, and then also the Unix code here needs changing. Must pass CPPFLAGS to g-ir-scanner when building GLib.gir so that libintl.h is found. svn path=/trunk/; revision=503
Diffstat (limited to 'giscanner/giscannermodule.c')
-rw-r--r--giscanner/giscannermodule.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/giscanner/giscannermodule.c b/giscanner/giscannermodule.c
index 3d3e7d95..8159c599 100644
--- a/giscanner/giscannermodule.c
+++ b/giscanner/giscannermodule.c
@@ -25,6 +25,14 @@
#include "sourcescanner.h"
#include <Python.h>
+#ifdef _WIN32
+#include <fcntl.h>
+#include <io.h>
+#define WIN32_LEAN_AND_MEAN
+#define STRICT
+#include <windows.h>
+#endif
+
#define NEW_CLASS(ctype, name, cname) \
static const PyMethodDef _Py##cname##_methods[]; \
PyTypeObject Py##cname##_Type = { \
@@ -393,6 +401,47 @@ pygi_source_scanner_parse_file (PyGISourceScanner *self,
if (!PyArg_ParseTuple (args, "i:SourceScanner.parse_file", &fd))
return NULL;
+#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.
+ */
+ {
+ HMODULE msvcr71;
+ int (*p__get_osfhandle) (int);
+ HANDLE handle;
+
+ msvcr71 = GetModuleHandle ("msvcr71.dll");
+ if (!msvcr71)
+ {
+ g_print ("No msvcr71.dll loaded.\n");
+ return NULL;
+ }
+
+ p__get_osfhandle = GetProcAddress (msvcr71, "_get_osfhandle");
+ if (!p__get_osfhandle)
+ {
+ g_print ("No _get_osfhandle found in msvcr71.dll.\n");
+ return NULL;
+ }
+
+ handle = p__get_osfhandle (fd);
+ if (!p__get_osfhandle)
+ {
+ g_print ("Could not get OS handle from msvcr71 fd.\n");
+ return NULL;
+ }
+
+ fd = _open_osfhandle (handle, _O_RDONLY);
+ if (fd == -1)
+ {
+ g_print ("Could not open C fd from OS handle.\n");
+ return NULL;
+ }
+ }
+#endif
+
fp = fdopen (fd, "r");
if (!fp)
{