[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyQt] sipdistutils.py - broken exceptions flags in VC++
From: Matteo Italia <matteo () mitalia ! net>
Date: 2014-10-27 22:27:47
Message-ID: 544EC6E3.4000200 () mitalia ! net
[Download RAW message or body]
Hello,
when building a Python 2.7 extension on Windows (with VC++ 2008) through
sipdistutils.py, I spotted several warning about wrong exception flags.
The issue seems to be that distutils only bothers to provide a compiler
with build options adequate for C extensions
(http://bugs.python.org/issue1222585), while we need C++ settings. For
this reason, no /EH flag is provided, and we end up building extensions
with broken exception semantic (in particular, RAII seems to be
completely broken when no /EH is provided, and catch(...) catches also
SEH exceptions, which is _extremely_ bad).
To fix this issue, I patched sipdistutils.py to add the adequate
exception specification option (/EHsc) if not present (and complain if
some /EH which is not /EHsc is already present); attached you can find
the diff against the sipdistutils.py in the current repository (since it
already goes on checking command line arguments, there's also a check to
remove -Wstrict-prototypes on Unix, which just generates noise in the
build).
Could someone check if it looks ok and if it can be eventually merged
back in SIP? I already had several bizarre crashes that could be traced
back to this problem, so I think that this may be useful to others.
Regards,
Matteo
["sipdistutils-winexceptions.patch" (text/x-patch)]
diff -r 2a310fa9719a sipdistutils.py
--- a/sipdistutils.py Mon May 26 11:36:04 2014 +0100
+++ b/sipdistutils.py Mon Oct 27 23:26:05 2014 +0100
@@ -108,6 +108,35 @@
if old_sig != new_sig:
self.force = True
+ # The compiler by default starts with the arguments used when compiling \
Python itself + # This means that we may get a configuration thought for C, \
that we have to patch + # (actually, the fact that we get a C++ compiler and \
not a C one is accidental; see + # http://bugs.python.org/issue1222585 )
+ try:
+ c=self.compiler
+ if c.compiler_type=='unix':
+ # On gcc, we kill -Wstrict-prototypes, that does not apply to C++
+ # and generates spurious warnings at each processed file
+ try:
+ c.compiler_so.remove('-Wstrict-prototypes')
+ except:
+ pass
+ elif c.compiler_type=='msvc':
+ if not c.initialized:
+ c.initialize()
+ # On VC++, if we do not specify /EHsc the C++ exception semantics is \
broken + # (destruction on stack unwinding is not performed correctly, \
and catch(...) + # eats also Win32 SEH exceptions)
+ ehOptions=[opt for opt in c.compile_options if \
opt.startswith('/EH')] + if '/EHsc' not in c.compile_options:
+ if len(ehOptions):
+ # We already have some unexpected /EH... option around
+ print 'WARNING: strange exception semantics specified in \
compile_options:', ehOptions + else:
+ c.compile_options.append('/EHsc')
+ except Exception as ex:
+ print "Couldn't patch compiler arguments, got exception: ", repr(ex)
+
build_ext_base.build_extension(self, ext)
self.force = oldforce
[Attachment #4 (text/plain)]
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic