]> granicus.if.org Git - python/commitdiff
Add a new function uses_seh() to the _ctypes extension module. This
authorThomas Heller <theller@ctypes.org>
Mon, 3 Jul 2006 08:08:14 +0000 (08:08 +0000)
committerThomas Heller <theller@ctypes.org>
Mon, 3 Jul 2006 08:08:14 +0000 (08:08 +0000)
will return True if Windows Structured Exception handling (SEH) is
used when calling functions, False otherwise.

Currently, only MSVC supports SEH.

Fix the test so that it doesn't crash when run with MingW compiled
_ctypes.  Note that two tests are still failing when mingw is used, I
suspect structure layout differences and function calling conventions
between MSVC and MingW.

Lib/ctypes/test/test_win32.py
Modules/_ctypes/callproc.c

index 8247d370d39b2198a3a47aa59b5dff39dc0cbaac..eb016ffbc7d0e82421e4fa70b9abbca1612592b8 100644 (file)
@@ -30,15 +30,11 @@ if sys.platform == "win32":
             # or wrong calling convention
             self.assertRaises(ValueError, IsWindow, None)
 
-        def test_SEH(self):
-            # Call functions with invalid arguments, and make sure that access violations
-            # are trapped and raise an exception.
-            #
-            # Normally, in a debug build of the _ctypes extension
-            # module, exceptions are not trapped, so we can only run
-            # this test in a release build.
-            import sys
-            if not hasattr(sys, "getobjects"):
+        import _ctypes
+        if _ctypes.uses_seh():
+            def test_SEH(self):
+                # Call functions with invalid arguments, and make sure that access violations
+                # are trapped and raise an exception.
                 self.assertRaises(WindowsError, windll.kernel32.GetModuleHandleA, 32)
 
 class Structures(unittest.TestCase):
index 16e10dedad2e6635b7064e462dc7927fffb2f985..4ec1f13d80988d6958618da754f9b21a1e3a9a5a 100644 (file)
@@ -1526,7 +1526,21 @@ resize(PyObject *self, PyObject *args)
        return Py_None;
 }
 
+static PyObject *
+uses_seh(PyObject *self, PyObject *args)
+{
+#if defined(DONT_USE_SEH) || !defined(MS_WIN32)
+       Py_INCREF(Py_False);
+       return Py_False;
+#else
+       Py_INCREF(Py_True);
+       return Py_True;
+#endif
+}
+
 PyMethodDef module_methods[] = {
+       {"uses_seh", uses_seh, METH_NOARGS,
+        "Return whether ctypes uses Windows structured exception handling"},
        {"resize", resize, METH_VARARGS, "Resize the memory buffer of a ctypes instance"},
 #ifdef CTYPES_UNICODE
        {"set_conversion_mode", set_conversion_mode, METH_VARARGS, set_conversion_mode_doc},