[pypy-commit] cffi default: Issue #225: Ignore basic SAL annotations on Windows.

arigo noreply at buildbot.pypy.org
Tue Oct 20 04:01:23 EDT 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r2352:fbe55ed7e5e2
Date: 2015-10-20 10:02 +0200
http://bitbucket.org/cffi/cffi/changeset/fbe55ed7e5e2/

Log:	Issue #225: Ignore basic SAL annotations on Windows.

diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -29,6 +29,8 @@
 _r_stdcall1 = re.compile(r"\b(__stdcall|WINAPI)\b")
 _r_stdcall2 = re.compile(r"[(]\s*(__stdcall|WINAPI)\b")
 _r_cdecl = re.compile(r"\b__cdecl\b")
+_r_SAL = re.compile(r"([(,]\s*)(_In_|_Inout_|_Out_|_Outptr_|"
+                    r"_In_opt_|_Inout_opt_|_Out_opt_|_Outptr_opt_)\b")
 
 def _get_parser():
     global _parser_cache
@@ -55,6 +57,8 @@
     csource = _r_stdcall2.sub(' volatile volatile const(', csource)
     csource = _r_stdcall1.sub(' volatile volatile const ', csource)
     csource = _r_cdecl.sub(' ', csource)
+    if sys.platform == 'win32':
+        csource = _r_SAL.sub(r'\1 ', csource)
     # Replace "[...]" with "[__dotdotdotarray__]"
     csource = _r_partial_array.sub('[__dotdotdotarray__]', csource)
     # Replace "...}" with "__dotdotdotNUM__}".  This construction should
diff --git a/doc/source/whatsnew.rst b/doc/source/whatsnew.rst
--- a/doc/source/whatsnew.rst
+++ b/doc/source/whatsnew.rst
@@ -32,6 +32,12 @@
   which had unwanted side-effects.  Try saying ``import setuptools``
   first, which patches distutils...
 
+* Windows: basic SAL annotations can be given in the cdef() and are
+  ignored.  More precisely, ``_In_``, ``_Inout_``, ``_Out_``,
+  ``_Outptr_``, ``In_opt_``, ``_Inout_opt_``, ``_Out_opt_`` and
+  ``_Outptr_opt_`` are ignored if they are following a ``(`` or a
+  ``,`` (which is where function parameters are).
+
 .. _`ffi.memmove()`: using.html#memmove
 .. __: https://bugs.python.org/issue23246
 .. __: https://bitbucket.org/cffi/cffi/pull-requests/65/remove-_hack_at_distutils-which-imports/diff
diff --git a/testing/cffi0/test_parsing.py b/testing/cffi0/test_parsing.py
--- a/testing/cffi0/test_parsing.py
+++ b/testing/cffi0/test_parsing.py
@@ -384,3 +384,10 @@
         "<ctype 'int(*)(int(%s*)(int), "
                         "long(*)(), "
                         "short(%s*)(short))'>" % (stdcall, stdcall))
+
+def test_basic_SAL_annotations_on_windows():
+    if sys.platform != 'win32':
+        py.test.skip("Only for Windows")
+    ffi = FFI()
+    tp = ffi.typeof("int(*)(_In_ int *abc, _Out_opt_ int *bcd)")
+    assert str(tp) == "<ctype 'int(*)(int *, int *)'>"


More information about the pypy-commit mailing list