From 6f0dfe6d2d6334a8a5e5d7ac245bc363dc8e87be Mon Sep 17 00:00:00 2001 From: Jason Erickson Date: Wed, 23 Feb 2011 14:29:44 -0700 Subject: [PATCH 1/5] Windows MSVC: Remove /Wp64 compiler flag Remove the /Wp64 flag since it is deprecated starting in Visual Studio 2008. --- setup.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 66c2fed6..f371abe9 100644 --- a/setup.py +++ b/setup.py @@ -181,13 +181,7 @@ class psycopg_build_ext(build_ext): compiler_name = self.get_compiler().lower() compiler_is_msvc = compiler_name.startswith('msvc') compiler_is_mingw = compiler_name.startswith('mingw') - if compiler_is_msvc: - # If we're using MSVC 7.1 or later on a 32-bit platform, add the - # /Wp64 option to generate warnings about Win64 portability - # problems. - if sysVer >= (2,4) and struct.calcsize('P') == 4: - extra_compiler_args.append('/Wp64') - elif compiler_is_mingw: + if compiler_is_mingw: # Default MinGW compilation of Python extensions on Windows uses # only -O: extra_compiler_args.append('-O3') From 631883f62fb3303671bce9e7e6c26c25cfe25f82 Mon Sep 17 00:00:00 2001 From: Jason Erickson Date: Wed, 23 Feb 2011 15:11:27 -0700 Subject: [PATCH 2/5] Windows MSVC: Fix data loss compiler warnings Fixed MSVC compiler warnings where it was indicating a conversion from a larger data type to smaller data type might have data loss. --- psycopg/lobject_type.c | 5 +++-- psycopg/xid_type.c | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/psycopg/lobject_type.c b/psycopg/lobject_type.c index 51c41d35..ba45de2d 100644 --- a/psycopg/lobject_type.c +++ b/psycopg/lobject_type.c @@ -124,10 +124,11 @@ static PyObject * psyco_lobj_read(lobjectObject *self, PyObject *args) { PyObject *res; - int where, end, size = -1; + int where, end; + Py_ssize_t size = -1; char *buffer; - if (!PyArg_ParseTuple(args, "|i", &size)) return NULL; + if (!PyArg_ParseTuple(args, "|" CONV_CODE_PY_SSIZE_T, &size)) return NULL; EXC_IF_LOBJ_CLOSED(self); EXC_IF_LOBJ_LEVEL0(self); diff --git a/psycopg/xid_type.c b/psycopg/xid_type.c index 82d6d899..9e95fd1b 100644 --- a/psycopg/xid_type.c +++ b/psycopg/xid_type.c @@ -100,7 +100,8 @@ static int xid_init(XidObject *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"format_id", "gtrid", "bqual", NULL}; - int format_id, i, gtrid_len, bqual_len; + int format_id; + size_t i, gtrid_len, bqual_len; const char *gtrid, *bqual; PyObject *tmp; From 961e855bbd099e02cb3898c69464de616ee11320 Mon Sep 17 00:00:00 2001 From: Jason Erickson Date: Wed, 23 Feb 2011 15:16:35 -0700 Subject: [PATCH 3/5] Windows MSVC: Fix Compiler Warning: getpid Fix a compiler warning when using PSYCOPG_DEBUG on MSVC where getpid is undefined. --- psycopg/config.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/psycopg/config.h b/psycopg/config.h index 708f0a89..551cfe48 100644 --- a/psycopg/config.h +++ b/psycopg/config.h @@ -51,6 +51,10 @@ extern HIDDEN int psycopg_debug_enabled; #else /* !__GNUC__ or __APPLE__ */ #ifdef PSYCOPG_DEBUG #include +#ifdef _WIN32 +#include +#define getpid _getpid +#endif static void Dprintf(const char *fmt, ...) { va_list ap; From 7c2fa77c4b68203bd22d1599c1a8a92901756772 Mon Sep 17 00:00:00 2001 From: Jason Erickson Date: Wed, 23 Feb 2011 17:32:45 -0700 Subject: [PATCH 4/5] Windows MSVC: Fixed warning of incompatible types Fixed incompatible type warning from XidObject * to PyObject * by casting. --- psycopg/connection_type.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index 7af6a62a..b0c9ddcc 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -939,7 +939,7 @@ connection_repr(connectionObject *self) static int connection_traverse(connectionObject *self, visitproc visit, void *arg) { - Py_VISIT(self->tpc_xid); + Py_VISIT((PyObject *)(self->tpc_xid)); Py_VISIT(self->async_cursor); Py_VISIT(self->notice_list); Py_VISIT(self->notice_filter); From 2997c0eb6cc32a5ea111c30abc2029413fb7b387 Mon Sep 17 00:00:00 2001 From: Jason Erickson Date: Thu, 24 Feb 2011 14:12:40 -0700 Subject: [PATCH 5/5] Windows MSVC: 64bit compiler sees 2 export symbols The MSVC compiler sees a request for the main symbol (init__pyscopg) to be exported twice during the build process and issues a warning in 64bit mode. One symbol is from distutils exporting the library with the build_ext.get_export_symbols() function, the other is from the #define PyMODINIT_FUNC (define in pyport.h) that begins the main _psycopg module. This patch overrides the get_export_symbols function and returns an empty array of symbols to export if the compiler is MSVC. --- setup.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/setup.py b/setup.py index f371abe9..e87c78dd 100644 --- a/setup.py +++ b/setup.py @@ -155,6 +155,13 @@ class psycopg_build_ext(build_ext): def get_pg_config(self, kind): return get_pg_config(kind, self.pg_config) + def get_export_symbols(self, ext): + # Fix MSVC seeing two of the same export symbols. + if self.get_compiler().lower().startswith('msvc'): + return [] + else: + return build_ext.get_export_symbols(self, ext) + def build_extension(self, ext): build_ext.build_extension(self, ext)