summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2017-01-26 11:14:28 +0100
committerArmin Rigo <arigo@tunes.org>2017-01-26 11:14:28 +0100
commitd55000271fc0f0356e99be9523d45e5d3c90afef (patch)
tree8b5c4beffd37fbe34c7de1598e2073eeb370e2f8
parentf0a21999115b31814835e8a8e55c916a49c4ee89 (diff)
downloadcffi-d55000271fc0f0356e99be9523d45e5d3c90afef.tar.gz
complain clearly if set_source() is given a /-separated name
-rw-r--r--cffi/api.py4
-rw-r--r--testing/cffi1/test_recompiler.py5
2 files changed, 9 insertions, 0 deletions
diff --git a/cffi/api.py b/cffi/api.py
index d3ec791..43b78f8 100644
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -593,11 +593,15 @@ class FFI(object):
ensure('extra_link_args', '/MANIFEST')
def set_source(self, module_name, source, source_extension='.c', **kwds):
+ import os
if hasattr(self, '_assigned_source'):
raise ValueError("set_source() cannot be called several times "
"per ffi object")
if not isinstance(module_name, basestring):
raise TypeError("'module_name' must be a string")
+ if os.sep in module_name or (os.altsep and os.altsep in module_name):
+ raise ValueError("'module_name' must not contain '/': use a dotted "
+ "name to make a 'package.module' location")
self._assigned_source = (str(module_name), source,
source_extension, kwds)
diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py
index 747e9aa..e48820b 100644
--- a/testing/cffi1/test_recompiler.py
+++ b/testing/cffi1/test_recompiler.py
@@ -36,6 +36,11 @@ def verify(ffi, module_name, source, *args, **kwds):
['-Werror'])
return recompiler._verify(ffi, module_name, source, *args, **kwds)
+def test_set_source_no_slashes():
+ ffi = FFI()
+ py.test.raises(ValueError, ffi.set_source, "abc/def", None)
+ py.test.raises(ValueError, ffi.set_source, "abc/def", "C code")
+
def test_type_table_func():
check_type_table("double sin(double);",