From: Mark Florisson Date: Mon, 8 Nov 2010 13:35:06 +0000 (+0100) Subject: disable C/C++ compiler optimization when compiling with the "debug" flag X-Git-Tag: 0.14.beta0~1^2~29 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2aadadd01635affa3991dd193f36ae1a3d5abefa;p=cython.git disable C/C++ compiler optimization when compiling with the "debug" flag --- diff --git a/Cython/Debugger/libcython.py b/Cython/Debugger/libcython.py index b0fa9313..6208777c 100644 --- a/Cython/Debugger/libcython.py +++ b/Cython/Debugger/libcython.py @@ -244,8 +244,14 @@ class CythonBase(object): if not pyframeobject: raise gdb.GdbError('Unable to read information on python frame') - filename = pyframeobject.filename() - lineno = pyframeobject.current_line_num() + try: + filename = pyframeobject.filename() + except RuntimeError: + filename = None + lineno = None + else: + lineno = pyframeobject.current_line_num() + if pygments: lexer = pygments.lexers.PythonLexer(stripall=False) else: @@ -307,7 +313,10 @@ class CythonBase(object): # print this python function as a C function return self.print_stackframe(frame, index, is_c=True) - func_name = pyframe.co_name + try: + func_name = str(pyframe.co_name) + except RuntimeError: + func_name = 'Unknown Function Name' func_cname = 'PyEval_EvalFrameEx' func_args = [] elif self.is_cython_function(frame): diff --git a/Cython/Distutils/build_ext.py b/Cython/Distutils/build_ext.py index c08b8849..604290c5 100644 --- a/Cython/Distutils/build_ext.py +++ b/Cython/Distutils/build_ext.py @@ -17,11 +17,45 @@ from distutils.dep_util import newer, newer_group from distutils import log from distutils.dir_util import mkpath from distutils.command import build_ext as _build_ext +from distutils import sysconfig extension_name_re = _build_ext.extension_name_re show_compilers = _build_ext.show_compilers +class Optimization(object): + def __init__(self): + self.flags = ( + 'OPT', + 'CFLAGS', + 'CPPFLAGS', + 'EXTRA_CFLAGS', + 'BASECFLAGS', + 'PY_CFLAGS', + ) + self.state = sysconfig.get_config_vars(*self.flags) + self.config_vars = sysconfig.get_config_vars() + + + def disable_optimization(self): + "disable optimization for the C or C++ compiler" + badoptions = ('-O1', '-O2', '-O3') + + for flag, option in zip(self.flags, self.state): + if option is not None: + g = (opt for opt in option.split() if opt not in badoptions) + self.config_vars[flag] = ' '.join(g) + + def restore_state(self): + "restore the original state" + for flag, option in zip(self.flags, self.state): + if option is not None: + self.config_vars[flag] = option + + +optimization = Optimization() + + class build_ext(_build_ext.build_ext): description = "build C/C++ and Cython extensions (compile/link to build directory)" @@ -77,10 +111,22 @@ class build_ext(_build_ext.build_ext): if self.pyrex_directives is None: self.pyrex_directives = {} # finalize_options () - + + def run(self): + # We have one shot at this before build_ext initializes the compiler. + # If --pyrex-debug is in effect as a command line option or as option + # of any Extension module, disable optimization for the C or C++ + # compiler. + if (self.pyrex_debug or any(getattr(ext, 'pyrex_debug', False) + for ext in self.extensions)): + optimization.disable_optimization() + + _build_ext.build_ext.run(self) + def build_extensions(self): # First, sanity-check the 'extensions' list self.check_extensions_list(self.extensions) + for ext in self.extensions: ext.sources = self.cython_sources(ext.sources, ext) self.build_extension(ext)