Commit 37b4ce75 authored by Stefan Behnel's avatar Stefan Behnel

explicitly reject unknown compiler options to make cythonize() less unfriendly to use

parent 1165671b
...@@ -479,7 +479,7 @@ class CompilationOptions(object): ...@@ -479,7 +479,7 @@ class CompilationOptions(object):
cplus boolean Compile as c++ code cplus boolean Compile as c++ code
""" """
def __init__(self, defaults = None, **kw): def __init__(self, defaults=None, **kw):
self.include_path = [] self.include_path = []
if defaults: if defaults:
if isinstance(defaults, CompilationOptions): if isinstance(defaults, CompilationOptions):
...@@ -490,6 +490,16 @@ class CompilationOptions(object): ...@@ -490,6 +490,16 @@ class CompilationOptions(object):
options = dict(defaults) options = dict(defaults)
options.update(kw) options.update(kw)
# let's assume 'default_options' contains a value for most known compiler options
# and validate against them
unknown_options = set(options) - set(default_options)
# ignore valid options that are not in the defaults
unknown_options.difference_update(['include_path'])
if unknown_options:
raise ValueError("got unexpected compilation option%s: %s" % (
's' if len(unknown_options) > 1 else '',
', '.join(unknown_options)))
directives = dict(options['compiler_directives']) # copy mutable field directives = dict(options['compiler_directives']) # copy mutable field
options['compiler_directives'] = directives options['compiler_directives'] = directives
if 'language_level' in directives and 'language_level' not in kw: if 'language_level' in directives and 'language_level' not in kw:
...@@ -675,4 +685,6 @@ default_options = dict( ...@@ -675,4 +685,6 @@ default_options = dict(
gdb_debug = False, gdb_debug = False,
compile_time_env = None, compile_time_env = None,
common_utility_include_dir = None, common_utility_include_dir = None,
output_dir=None,
build_dir=None,
) )
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment