summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);",