* [gentoo-commits] repo/gentoo:master commit in: dev-python/cffi/files/, dev-python/cffi/
@ 2020-05-28 8:20 Michał Górny
0 siblings, 0 replies; 4+ messages in thread
From: Michał Górny @ 2020-05-28 8:20 UTC (permalink / raw
To: gentoo-commits
commit: 4146461e033a5b02c0ff97b2238701f7731a92e8
Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Thu May 28 08:06:04 2020 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Thu May 28 08:06:04 2020 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=4146461e
dev-python/cffi: Fix handling #line created by 'cpp -g'
Closes: https://bugs.gentoo.org/723476
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
.../{cffi-1.14.0.ebuild => cffi-1.14.0-r1.ebuild} | 4 +
dev-python/cffi/files/cffi-0.14.0-g-line.patch | 144 +++++++++++++++++++++
2 files changed, 148 insertions(+)
diff --git a/dev-python/cffi/cffi-1.14.0.ebuild b/dev-python/cffi/cffi-1.14.0-r1.ebuild
similarity index 96%
rename from dev-python/cffi/cffi-1.14.0.ebuild
rename to dev-python/cffi/cffi-1.14.0-r1.ebuild
index 6e8b5153b7d..98bd94e809c 100644
--- a/dev-python/cffi/cffi-1.14.0.ebuild
+++ b/dev-python/cffi/cffi-1.14.0-r1.ebuild
@@ -29,6 +29,10 @@ BDEPEND="${RDEPEND}
distutils_enable_sphinx doc/source
+PATCHES=(
+ "${FILESDIR}"/cffi-0.14.0-g-line.patch
+)
+
src_configure() {
tc-export PKG_CONFIG
}
diff --git a/dev-python/cffi/files/cffi-0.14.0-g-line.patch b/dev-python/cffi/files/cffi-0.14.0-g-line.patch
new file mode 100644
index 00000000000..965f26db495
--- /dev/null
+++ b/dev-python/cffi/files/cffi-0.14.0-g-line.patch
@@ -0,0 +1,144 @@
+From 19ff1036043ae40ff3d8a2e1a6a793219e1ec378 Mon Sep 17 00:00:00 2001
+From: Armin Rigo <arigo@tunes.org>
+Date: Tue, 26 May 2020 15:51:56 +0200
+Subject: [PATCH] Issue #454
+
+Try harder to avoid #line directives confuse the rest of pre-parsing
+---
+ cffi/cparser.py | 37 ++++++++++++++++++++++++---
+ testing/cffi0/test_parsing.py | 48 ++++++++++++++++++++++++++++++++++-
+ 2 files changed, 81 insertions(+), 4 deletions(-)
+
+diff --git a/cffi/cparser.py b/cffi/cparser.py
+index d7069a73..d9784655 100644
+--- a/cffi/cparser.py
++++ b/cffi/cparser.py
+@@ -29,6 +29,7 @@ _r_comment = re.compile(r"/\*.*?\*/|//([^\n\\]|\\.)*?$",
+ _r_define = re.compile(r"^\s*#\s*define\s+([A-Za-z_][A-Za-z_0-9]*)"
+ r"\b((?:[^\n\\]|\\.)*?)$",
+ re.DOTALL | re.MULTILINE)
++_r_line_directive = re.compile(r"^[ \t]*#[ \t]*line\b.*$", re.MULTILINE)
+ _r_partial_enum = re.compile(r"=\s*\.\.\.\s*[,}]|\.\.\.\s*\}")
+ _r_enum_dotdotdot = re.compile(r"__dotdotdot\d+__$")
+ _r_partial_array = re.compile(r"\[\s*\.\.\.\s*\]")
+@@ -163,10 +164,37 @@ def _warn_for_non_extern_non_static_global_variable(decl):
+ "with C it should have a storage class specifier "
+ "(usually 'extern')" % (decl.name,))
+
++def _remove_line_directives(csource):
++ # _r_line_directive matches whole lines, without the final \n, if they
++ # start with '#line' with some spacing allowed. This function stores
++ # them away and replaces them with exactly the string '#line@N', where
++ # N is the index in the list 'line_directives'.
++ line_directives = []
++ def replace(m):
++ i = len(line_directives)
++ line_directives.append(m.group())
++ return '#line@%d' % i
++ csource = _r_line_directive.sub(replace, csource)
++ return csource, line_directives
++
++def _put_back_line_directives(csource, line_directives):
++ def replace(m):
++ s = m.group()
++ if not s.startswith('#line@'):
++ raise AssertionError("unexpected #line directive "
++ "(should have been processed and removed")
++ return line_directives[int(s[6:])]
++ return _r_line_directive.sub(replace, csource)
++
+ def _preprocess(csource):
++ # First, remove the lines of the form '#line N "filename"' because
++ # the "filename" part could confuse the rest
++ csource, line_directives = _remove_line_directives(csource)
+ # Remove comments. NOTE: this only work because the cdef() section
+- # should not contain any string literal!
+- csource = _r_comment.sub(' ', csource)
++ # should not contain any string literals (except in line directives)!
++ def replace_keeping_newlines(m):
++ return ' ' + m.group().count('\n') * '\n'
++ csource = _r_comment.sub(replace_keeping_newlines, csource)
+ # Remove the "#define FOO x" lines
+ macros = {}
+ for match in _r_define.finditer(csource):
+@@ -219,7 +247,10 @@ def _preprocess(csource):
+ csource = _r_float_dotdotdot.sub(' __dotdotdotfloat__ ', csource)
+ # Replace all remaining "..." with the same name, "__dotdotdot__",
+ # which is declared with a typedef for the purpose of C parsing.
+- return csource.replace('...', ' __dotdotdot__ '), macros
++ csource = csource.replace('...', ' __dotdotdot__ ')
++ # Finally, put back the line directives
++ csource = _put_back_line_directives(csource, line_directives)
++ return csource, macros
+
+ def _common_type_names(csource):
+ # Look in the source for what looks like usages of types from the
+diff --git a/testing/cffi0/test_parsing.py b/testing/cffi0/test_parsing.py
+index 3fc3783a..5f2d7ec4 100644
+--- a/testing/cffi0/test_parsing.py
++++ b/testing/cffi0/test_parsing.py
+@@ -174,7 +174,7 @@ def test_remove_line_continuation_comments():
+ double // blah \\
+ more comments
+ x(void);
+- double // blah\\\\
++ double // blah // blah\\\\
+ y(void);
+ double // blah\\ \
+ etc
+@@ -185,6 +185,52 @@ def test_remove_line_continuation_comments():
+ m.y
+ m.z
+
++def test_dont_remove_comment_in_line_directives():
++ ffi = FFI(backend=FakeBackend())
++ e = py.test.raises(CDefError, ffi.cdef, """
++ \t # \t line \t 8 \t "baz.c" \t
++
++ some syntax error here
++ """)
++ assert str(e.value) == "parse error\nbaz.c:9:14: before: syntax"
++ #
++ e = py.test.raises(CDefError, ffi.cdef, """
++ #line 7 "foo//bar.c"
++
++ some syntax error here
++ """)
++ assert str(e.value) == "parse error\nfoo//bar.c:8:14: before: syntax"
++
++def test_multiple_line_directives():
++ ffi = FFI(backend=FakeBackend())
++ e = py.test.raises(CDefError, ffi.cdef,
++ """ #line 5 "foo.c"
++ extern int xx;
++ #line 6 "bar.c"
++ extern int yy;
++ #line 7 "baz.c"
++ some syntax error here
++ #line 8 "yadda.c"
++ extern int zz;
++ """)
++ assert str(e.value) == "parse error\nbaz.c:7:14: before: syntax"
++
++def test_commented_line_directive():
++ ffi = FFI(backend=FakeBackend())
++ e = py.test.raises(CDefError, ffi.cdef, """
++ /*
++ #line 5 "foo.c"
++ */
++ void xx(void);
++
++ #line 6 "bar.c"
++ /*
++ #line 35 "foo.c"
++ */
++ some syntax error
++ """)
++ assert str(e.value) == "parse error\nbar.c:9:14: before: syntax"
++
+ def test_line_continuation_in_defines():
+ ffi = FFI(backend=FakeBackend())
+ ffi.cdef("""
+--
+2.26.2
+
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-commits] repo/gentoo:master commit in: dev-python/cffi/files/, dev-python/cffi/
@ 2020-05-29 8:46 Michał Górny
0 siblings, 0 replies; 4+ messages in thread
From: Michał Górny @ 2020-05-29 8:46 UTC (permalink / raw
To: gentoo-commits
commit: c847df4320352b36b0e164efcf67d0ef7b37b93b
Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Fri May 29 08:45:57 2020 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Fri May 29 08:45:57 2020 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c847df43
dev-python/cffi: Backport proper -g fix
Closes: https://bugs.gentoo.org/723476
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
...cffi-1.14.0-r1.ebuild => cffi-1.14.0-r2.ebuild} | 0
dev-python/cffi/files/cffi-0.14.0-g-line.patch | 106 +++++++++++++++++++++
2 files changed, 106 insertions(+)
diff --git a/dev-python/cffi/cffi-1.14.0-r1.ebuild b/dev-python/cffi/cffi-1.14.0-r2.ebuild
similarity index 100%
rename from dev-python/cffi/cffi-1.14.0-r1.ebuild
rename to dev-python/cffi/cffi-1.14.0-r2.ebuild
diff --git a/dev-python/cffi/files/cffi-0.14.0-g-line.patch b/dev-python/cffi/files/cffi-0.14.0-g-line.patch
index 965f26db495..45a1099dce2 100644
--- a/dev-python/cffi/files/cffi-0.14.0-g-line.patch
+++ b/dev-python/cffi/files/cffi-0.14.0-g-line.patch
@@ -142,3 +142,109 @@ index 3fc3783a..5f2d7ec4 100644
--
2.26.2
+From 31249d786c833d4960bbbf4e0d7f7bcaecf92d1f Mon Sep 17 00:00:00 2001
+From: Armin Rigo <arigo@tunes.org>
+Date: Fri, 29 May 2020 10:27:40 +0200
+Subject: [PATCH] #454
+
+Second try with '# NUMBER' instead of '#line NUMBER', as gcc seems to output
+---
+ cffi/cparser.py | 8 +++----
+ testing/cffi0/test_parsing.py | 41 +++++++++++++++++++++++++++++++++++
+ 2 files changed, 45 insertions(+), 4 deletions(-)
+
+diff --git a/cffi/cparser.py b/cffi/cparser.py
+index d9784655..74830e91 100644
+--- a/cffi/cparser.py
++++ b/cffi/cparser.py
+@@ -29,7 +29,7 @@ _r_comment = re.compile(r"/\*.*?\*/|//([^\n\\]|\\.)*?$",
+ _r_define = re.compile(r"^\s*#\s*define\s+([A-Za-z_][A-Za-z_0-9]*)"
+ r"\b((?:[^\n\\]|\\.)*?)$",
+ re.DOTALL | re.MULTILINE)
+-_r_line_directive = re.compile(r"^[ \t]*#[ \t]*line\b.*$", re.MULTILINE)
++_r_line_directive = re.compile(r"^[ \t]*#[ \t]*(?:line|\d+)\b.*$", re.MULTILINE)
+ _r_partial_enum = re.compile(r"=\s*\.\.\.\s*[,}]|\.\.\.\s*\}")
+ _r_enum_dotdotdot = re.compile(r"__dotdotdot\d+__$")
+ _r_partial_array = re.compile(r"\[\s*\.\.\.\s*\]")
+@@ -166,9 +166,9 @@ def _warn_for_non_extern_non_static_global_variable(decl):
+
+ def _remove_line_directives(csource):
+ # _r_line_directive matches whole lines, without the final \n, if they
+- # start with '#line' with some spacing allowed. This function stores
+- # them away and replaces them with exactly the string '#line@N', where
+- # N is the index in the list 'line_directives'.
++ # start with '#line' with some spacing allowed, or '#NUMBER'. This
++ # function stores them away and replaces them with exactly the string
++ # '#line@N', where N is the index in the list 'line_directives'.
+ line_directives = []
+ def replace(m):
+ i = len(line_directives)
+diff --git a/testing/cffi0/test_parsing.py b/testing/cffi0/test_parsing.py
+index 5f2d7ec4..a5e45874 100644
+--- a/testing/cffi0/test_parsing.py
++++ b/testing/cffi0/test_parsing.py
+@@ -199,6 +199,21 @@ def test_dont_remove_comment_in_line_directives():
+
+ some syntax error here
+ """)
++ #
++ assert str(e.value) == "parse error\nfoo//bar.c:8:14: before: syntax"
++ ffi = FFI(backend=FakeBackend())
++ e = py.test.raises(CDefError, ffi.cdef, """
++ \t # \t 8 \t "baz.c" \t
++
++ some syntax error here
++ """)
++ assert str(e.value) == "parse error\nbaz.c:9:14: before: syntax"
++ #
++ e = py.test.raises(CDefError, ffi.cdef, """
++ # 7 "foo//bar.c"
++
++ some syntax error here
++ """)
+ assert str(e.value) == "parse error\nfoo//bar.c:8:14: before: syntax"
+
+ def test_multiple_line_directives():
+@@ -214,6 +229,18 @@ def test_multiple_line_directives():
+ extern int zz;
+ """)
+ assert str(e.value) == "parse error\nbaz.c:7:14: before: syntax"
++ #
++ e = py.test.raises(CDefError, ffi.cdef,
++ """ # 5 "foo.c"
++ extern int xx;
++ # 6 "bar.c"
++ extern int yy;
++ # 7 "baz.c"
++ some syntax error here
++ # 8 "yadda.c"
++ extern int zz;
++ """)
++ assert str(e.value) == "parse error\nbaz.c:7:14: before: syntax"
+
+ def test_commented_line_directive():
+ ffi = FFI(backend=FakeBackend())
+@@ -229,6 +256,20 @@ def test_commented_line_directive():
+ */
+ some syntax error
+ """)
++ #
++ assert str(e.value) == "parse error\nbar.c:9:14: before: syntax"
++ e = py.test.raises(CDefError, ffi.cdef, """
++ /*
++ # 5 "foo.c"
++ */
++ void xx(void);
++
++ # 6 "bar.c"
++ /*
++ # 35 "foo.c"
++ */
++ some syntax error
++ """)
+ assert str(e.value) == "parse error\nbar.c:9:14: before: syntax"
+
+ def test_line_continuation_in_defines():
+--
+2.26.2
+
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-commits] repo/gentoo:master commit in: dev-python/cffi/files/, dev-python/cffi/
@ 2020-11-28 7:27 Sam James
0 siblings, 0 replies; 4+ messages in thread
From: Sam James @ 2020-11-28 7:27 UTC (permalink / raw
To: gentoo-commits
commit: 130c6887fd5bddceb491335ab95c5fea690d2f64
Author: Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sat Nov 28 07:27:25 2020 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Nov 28 07:27:25 2020 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=130c6887
dev-python/cffi: don't call Homebrew on Darwin
Package-Manager: Portage-3.0.9, Repoman-3.0.2
Signed-off-by: Sam James <sam <AT> gentoo.org>
dev-python/cffi/cffi-1.14.0-r3.ebuild | 1 +
dev-python/cffi/files/cffi-1.14.0-darwin-no-brew.patch | 14 ++++++++++++++
2 files changed, 15 insertions(+)
diff --git a/dev-python/cffi/cffi-1.14.0-r3.ebuild b/dev-python/cffi/cffi-1.14.0-r3.ebuild
index 4a459635cd1..78f80a7e2b3 100644
--- a/dev-python/cffi/cffi-1.14.0-r3.ebuild
+++ b/dev-python/cffi/cffi-1.14.0-r3.ebuild
@@ -31,6 +31,7 @@ distutils_enable_sphinx doc/source
PATCHES=(
"${FILESDIR}"/cffi-0.14.0-g-line.patch
+ "${FILESDIR}"/cffi-1.14.0-darwin-no-brew.patch
)
src_configure() {
diff --git a/dev-python/cffi/files/cffi-1.14.0-darwin-no-brew.patch b/dev-python/cffi/files/cffi-1.14.0-darwin-no-brew.patch
new file mode 100644
index 00000000000..c92b6112b85
--- /dev/null
+++ b/dev-python/cffi/files/cffi-1.14.0-darwin-no-brew.patch
@@ -0,0 +1,14 @@
+diff --git a/setup.py b/setup.py
+index e1dd39d..3e88f74 100644
+--- a/setup.py
++++ b/setup.py
+@@ -105,9 +105,6 @@ def uses_msvc():
+ return config.try_compile('#ifndef _MSC_VER\n#error "not MSVC"\n#endif')
+
+ def use_pkg_config():
+- if sys.platform == 'darwin' and os.path.exists('/usr/local/bin/brew'):
+- use_homebrew_for_libffi()
+-
+ _ask_pkg_config(include_dirs, '--cflags-only-I', '-I', sysroot=True)
+ _ask_pkg_config(extra_compile_args, '--cflags-only-other')
+ _ask_pkg_config(library_dirs, '--libs-only-L', '-L', sysroot=True)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-commits] repo/gentoo:master commit in: dev-python/cffi/files/, dev-python/cffi/
@ 2021-01-31 21:36 Michał Górny
0 siblings, 0 replies; 4+ messages in thread
From: Michał Górny @ 2021-01-31 21:36 UTC (permalink / raw
To: gentoo-commits
commit: b7ad8360eb6423abd14f9677a884c58a5c4c5706
Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 31 21:34:01 2021 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Sun Jan 31 21:36:48 2021 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=b7ad8360
dev-python/cffi: Remove old
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
dev-python/cffi/Manifest | 1 -
dev-python/cffi/cffi-1.14.0-r3.ebuild | 48 -----
dev-python/cffi/files/cffi-0.14.0-g-line.patch | 250 -------------------------
3 files changed, 299 deletions(-)
diff --git a/dev-python/cffi/Manifest b/dev-python/cffi/Manifest
index 64ab58ed51a..068a1f07b8b 100644
--- a/dev-python/cffi/Manifest
+++ b/dev-python/cffi/Manifest
@@ -1,2 +1 @@
-DIST cffi-1.14.0.tar.gz 463065 BLAKE2B 4d1e8a92241db801848ef8bd05ea15a31c7f61ea426ce4da184aff00df786348d2c76de9dc48898c814478aed9750b665868df24ad39435062cd7e1c84163e52 SHA512 4c5451eeede1d48a8f4b40e25b845ad1863b8bf3bd39624e6c693c2800d89a13efedc4c43b37e317a035613bffc2e3fd5f7e583c46cb283cb5cb930356f86253
DIST cffi-1.14.4.tar.gz 471302 BLAKE2B 9722e517c99b6df239f59235baea76957900dc8566ff04c8d1fd367d20ad5f5437212bdb5e4e98aca303121e79411634fcb5e4e72179ecb3007d4f0eee68c9f2 SHA512 b2c54a805ead93c5dd8531d7f0f7e4b44be8f07bfcb1af2f19eb6d325b4e846cae23f16a5bcc777ba019d1213f013611614ade798e195f5b4f6b7904c9cb6e3a
diff --git a/dev-python/cffi/cffi-1.14.0-r3.ebuild b/dev-python/cffi/cffi-1.14.0-r3.ebuild
deleted file mode 100644
index fe9cf1decfa..00000000000
--- a/dev-python/cffi/cffi-1.14.0-r3.ebuild
+++ /dev/null
@@ -1,48 +0,0 @@
-# Copyright 1999-2021 Gentoo Authors
-# Distributed under the terms of the GNU General Public License v2
-
-EAPI=7
-
-# DO NOT ADD pypy to PYTHON_COMPAT
-# pypy bundles a modified version of cffi. Use python_gen_cond_dep instead.
-DISTUTILS_USE_SETUPTOOLS=rdepend
-PYTHON_COMPAT=( python3_{7,8,9} )
-
-inherit distutils-r1 toolchain-funcs
-
-DESCRIPTION="Foreign Function Interface for Python calling C code"
-HOMEPAGE="https://cffi.readthedocs.io/ https://pypi.org/project/cffi/"
-SRC_URI="mirror://pypi/${PN:0:1}/${PN}/${P}.tar.gz"
-
-LICENSE="MIT"
-SLOT="0/${PV}"
-KEYWORDS="~alpha amd64 arm arm64 hppa ~ia64 ~m68k ~mips ppc ppc64 ~riscv s390 sparc x86 ~x64-cygwin ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
-IUSE="test"
-RESTRICT="!test? ( test )"
-
-DEPEND="dev-libs/libffi:="
-RDEPEND="${DEPEND}
- dev-python/pycparser[${PYTHON_USEDEP}]"
-BDEPEND="${RDEPEND}
- virtual/pkgconfig
- test? ( dev-python/pytest[${PYTHON_USEDEP}] )"
-
-distutils_enable_sphinx doc/source
-
-PATCHES=(
- "${FILESDIR}"/cffi-0.14.0-g-line.patch
- "${FILESDIR}"/cffi-1.14.0-darwin-no-brew.patch
-)
-
-src_configure() {
- tc-export PKG_CONFIG
-}
-
-python_test() {
- "${EPYTHON}" -c "import _cffi_backend as backend" || die
- pytest -x -vv \
- --ignore testing/test_zintegration.py \
- --ignore testing/embedding \
- c/ testing/ \
- || die "Testing failed with ${EPYTHON}"
-}
diff --git a/dev-python/cffi/files/cffi-0.14.0-g-line.patch b/dev-python/cffi/files/cffi-0.14.0-g-line.patch
deleted file mode 100644
index 45a1099dce2..00000000000
--- a/dev-python/cffi/files/cffi-0.14.0-g-line.patch
+++ /dev/null
@@ -1,250 +0,0 @@
-From 19ff1036043ae40ff3d8a2e1a6a793219e1ec378 Mon Sep 17 00:00:00 2001
-From: Armin Rigo <arigo@tunes.org>
-Date: Tue, 26 May 2020 15:51:56 +0200
-Subject: [PATCH] Issue #454
-
-Try harder to avoid #line directives confuse the rest of pre-parsing
----
- cffi/cparser.py | 37 ++++++++++++++++++++++++---
- testing/cffi0/test_parsing.py | 48 ++++++++++++++++++++++++++++++++++-
- 2 files changed, 81 insertions(+), 4 deletions(-)
-
-diff --git a/cffi/cparser.py b/cffi/cparser.py
-index d7069a73..d9784655 100644
---- a/cffi/cparser.py
-+++ b/cffi/cparser.py
-@@ -29,6 +29,7 @@ _r_comment = re.compile(r"/\*.*?\*/|//([^\n\\]|\\.)*?$",
- _r_define = re.compile(r"^\s*#\s*define\s+([A-Za-z_][A-Za-z_0-9]*)"
- r"\b((?:[^\n\\]|\\.)*?)$",
- re.DOTALL | re.MULTILINE)
-+_r_line_directive = re.compile(r"^[ \t]*#[ \t]*line\b.*$", re.MULTILINE)
- _r_partial_enum = re.compile(r"=\s*\.\.\.\s*[,}]|\.\.\.\s*\}")
- _r_enum_dotdotdot = re.compile(r"__dotdotdot\d+__$")
- _r_partial_array = re.compile(r"\[\s*\.\.\.\s*\]")
-@@ -163,10 +164,37 @@ def _warn_for_non_extern_non_static_global_variable(decl):
- "with C it should have a storage class specifier "
- "(usually 'extern')" % (decl.name,))
-
-+def _remove_line_directives(csource):
-+ # _r_line_directive matches whole lines, without the final \n, if they
-+ # start with '#line' with some spacing allowed. This function stores
-+ # them away and replaces them with exactly the string '#line@N', where
-+ # N is the index in the list 'line_directives'.
-+ line_directives = []
-+ def replace(m):
-+ i = len(line_directives)
-+ line_directives.append(m.group())
-+ return '#line@%d' % i
-+ csource = _r_line_directive.sub(replace, csource)
-+ return csource, line_directives
-+
-+def _put_back_line_directives(csource, line_directives):
-+ def replace(m):
-+ s = m.group()
-+ if not s.startswith('#line@'):
-+ raise AssertionError("unexpected #line directive "
-+ "(should have been processed and removed")
-+ return line_directives[int(s[6:])]
-+ return _r_line_directive.sub(replace, csource)
-+
- def _preprocess(csource):
-+ # First, remove the lines of the form '#line N "filename"' because
-+ # the "filename" part could confuse the rest
-+ csource, line_directives = _remove_line_directives(csource)
- # Remove comments. NOTE: this only work because the cdef() section
-- # should not contain any string literal!
-- csource = _r_comment.sub(' ', csource)
-+ # should not contain any string literals (except in line directives)!
-+ def replace_keeping_newlines(m):
-+ return ' ' + m.group().count('\n') * '\n'
-+ csource = _r_comment.sub(replace_keeping_newlines, csource)
- # Remove the "#define FOO x" lines
- macros = {}
- for match in _r_define.finditer(csource):
-@@ -219,7 +247,10 @@ def _preprocess(csource):
- csource = _r_float_dotdotdot.sub(' __dotdotdotfloat__ ', csource)
- # Replace all remaining "..." with the same name, "__dotdotdot__",
- # which is declared with a typedef for the purpose of C parsing.
-- return csource.replace('...', ' __dotdotdot__ '), macros
-+ csource = csource.replace('...', ' __dotdotdot__ ')
-+ # Finally, put back the line directives
-+ csource = _put_back_line_directives(csource, line_directives)
-+ return csource, macros
-
- def _common_type_names(csource):
- # Look in the source for what looks like usages of types from the
-diff --git a/testing/cffi0/test_parsing.py b/testing/cffi0/test_parsing.py
-index 3fc3783a..5f2d7ec4 100644
---- a/testing/cffi0/test_parsing.py
-+++ b/testing/cffi0/test_parsing.py
-@@ -174,7 +174,7 @@ def test_remove_line_continuation_comments():
- double // blah \\
- more comments
- x(void);
-- double // blah\\\\
-+ double // blah // blah\\\\
- y(void);
- double // blah\\ \
- etc
-@@ -185,6 +185,52 @@ def test_remove_line_continuation_comments():
- m.y
- m.z
-
-+def test_dont_remove_comment_in_line_directives():
-+ ffi = FFI(backend=FakeBackend())
-+ e = py.test.raises(CDefError, ffi.cdef, """
-+ \t # \t line \t 8 \t "baz.c" \t
-+
-+ some syntax error here
-+ """)
-+ assert str(e.value) == "parse error\nbaz.c:9:14: before: syntax"
-+ #
-+ e = py.test.raises(CDefError, ffi.cdef, """
-+ #line 7 "foo//bar.c"
-+
-+ some syntax error here
-+ """)
-+ assert str(e.value) == "parse error\nfoo//bar.c:8:14: before: syntax"
-+
-+def test_multiple_line_directives():
-+ ffi = FFI(backend=FakeBackend())
-+ e = py.test.raises(CDefError, ffi.cdef,
-+ """ #line 5 "foo.c"
-+ extern int xx;
-+ #line 6 "bar.c"
-+ extern int yy;
-+ #line 7 "baz.c"
-+ some syntax error here
-+ #line 8 "yadda.c"
-+ extern int zz;
-+ """)
-+ assert str(e.value) == "parse error\nbaz.c:7:14: before: syntax"
-+
-+def test_commented_line_directive():
-+ ffi = FFI(backend=FakeBackend())
-+ e = py.test.raises(CDefError, ffi.cdef, """
-+ /*
-+ #line 5 "foo.c"
-+ */
-+ void xx(void);
-+
-+ #line 6 "bar.c"
-+ /*
-+ #line 35 "foo.c"
-+ */
-+ some syntax error
-+ """)
-+ assert str(e.value) == "parse error\nbar.c:9:14: before: syntax"
-+
- def test_line_continuation_in_defines():
- ffi = FFI(backend=FakeBackend())
- ffi.cdef("""
---
-2.26.2
-
-From 31249d786c833d4960bbbf4e0d7f7bcaecf92d1f Mon Sep 17 00:00:00 2001
-From: Armin Rigo <arigo@tunes.org>
-Date: Fri, 29 May 2020 10:27:40 +0200
-Subject: [PATCH] #454
-
-Second try with '# NUMBER' instead of '#line NUMBER', as gcc seems to output
----
- cffi/cparser.py | 8 +++----
- testing/cffi0/test_parsing.py | 41 +++++++++++++++++++++++++++++++++++
- 2 files changed, 45 insertions(+), 4 deletions(-)
-
-diff --git a/cffi/cparser.py b/cffi/cparser.py
-index d9784655..74830e91 100644
---- a/cffi/cparser.py
-+++ b/cffi/cparser.py
-@@ -29,7 +29,7 @@ _r_comment = re.compile(r"/\*.*?\*/|//([^\n\\]|\\.)*?$",
- _r_define = re.compile(r"^\s*#\s*define\s+([A-Za-z_][A-Za-z_0-9]*)"
- r"\b((?:[^\n\\]|\\.)*?)$",
- re.DOTALL | re.MULTILINE)
--_r_line_directive = re.compile(r"^[ \t]*#[ \t]*line\b.*$", re.MULTILINE)
-+_r_line_directive = re.compile(r"^[ \t]*#[ \t]*(?:line|\d+)\b.*$", re.MULTILINE)
- _r_partial_enum = re.compile(r"=\s*\.\.\.\s*[,}]|\.\.\.\s*\}")
- _r_enum_dotdotdot = re.compile(r"__dotdotdot\d+__$")
- _r_partial_array = re.compile(r"\[\s*\.\.\.\s*\]")
-@@ -166,9 +166,9 @@ def _warn_for_non_extern_non_static_global_variable(decl):
-
- def _remove_line_directives(csource):
- # _r_line_directive matches whole lines, without the final \n, if they
-- # start with '#line' with some spacing allowed. This function stores
-- # them away and replaces them with exactly the string '#line@N', where
-- # N is the index in the list 'line_directives'.
-+ # start with '#line' with some spacing allowed, or '#NUMBER'. This
-+ # function stores them away and replaces them with exactly the string
-+ # '#line@N', where N is the index in the list 'line_directives'.
- line_directives = []
- def replace(m):
- i = len(line_directives)
-diff --git a/testing/cffi0/test_parsing.py b/testing/cffi0/test_parsing.py
-index 5f2d7ec4..a5e45874 100644
---- a/testing/cffi0/test_parsing.py
-+++ b/testing/cffi0/test_parsing.py
-@@ -199,6 +199,21 @@ def test_dont_remove_comment_in_line_directives():
-
- some syntax error here
- """)
-+ #
-+ assert str(e.value) == "parse error\nfoo//bar.c:8:14: before: syntax"
-+ ffi = FFI(backend=FakeBackend())
-+ e = py.test.raises(CDefError, ffi.cdef, """
-+ \t # \t 8 \t "baz.c" \t
-+
-+ some syntax error here
-+ """)
-+ assert str(e.value) == "parse error\nbaz.c:9:14: before: syntax"
-+ #
-+ e = py.test.raises(CDefError, ffi.cdef, """
-+ # 7 "foo//bar.c"
-+
-+ some syntax error here
-+ """)
- assert str(e.value) == "parse error\nfoo//bar.c:8:14: before: syntax"
-
- def test_multiple_line_directives():
-@@ -214,6 +229,18 @@ def test_multiple_line_directives():
- extern int zz;
- """)
- assert str(e.value) == "parse error\nbaz.c:7:14: before: syntax"
-+ #
-+ e = py.test.raises(CDefError, ffi.cdef,
-+ """ # 5 "foo.c"
-+ extern int xx;
-+ # 6 "bar.c"
-+ extern int yy;
-+ # 7 "baz.c"
-+ some syntax error here
-+ # 8 "yadda.c"
-+ extern int zz;
-+ """)
-+ assert str(e.value) == "parse error\nbaz.c:7:14: before: syntax"
-
- def test_commented_line_directive():
- ffi = FFI(backend=FakeBackend())
-@@ -229,6 +256,20 @@ def test_commented_line_directive():
- */
- some syntax error
- """)
-+ #
-+ assert str(e.value) == "parse error\nbar.c:9:14: before: syntax"
-+ e = py.test.raises(CDefError, ffi.cdef, """
-+ /*
-+ # 5 "foo.c"
-+ */
-+ void xx(void);
-+
-+ # 6 "bar.c"
-+ /*
-+ # 35 "foo.c"
-+ */
-+ some syntax error
-+ """)
- assert str(e.value) == "parse error\nbar.c:9:14: before: syntax"
-
- def test_line_continuation_in_defines():
---
-2.26.2
-
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-01-31 21:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-29 8:46 [gentoo-commits] repo/gentoo:master commit in: dev-python/cffi/files/, dev-python/cffi/ Michał Górny
-- strict thread matches above, loose matches on Subject: below --
2021-01-31 21:36 Michał Górny
2020-11-28 7:27 Sam James
2020-05-28 8:20 Michał Górny
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox