diff options
Diffstat (limited to 'pypy/module/cpyext/api.py')
-rw-r--r-- | pypy/module/cpyext/api.py | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py index 84ec9ed150..237285be5c 100644 --- a/pypy/module/cpyext/api.py +++ b/pypy/module/cpyext/api.py @@ -622,12 +622,8 @@ SYMBOLS_C = [ 'PyFunction_Type', 'PyMethod_Type', 'PyRange_Type', 'PyTraceBack_Type', - 'Py_DebugFlag', 'Py_VerboseFlag', 'Py_InteractiveFlag', 'Py_InspectFlag', - 'Py_OptimizeFlag', 'Py_NoSiteFlag', 'Py_BytesWarningFlag', 'Py_UseClassExceptionsFlag', - 'Py_FrozenFlag', 'Py_TabcheckFlag', 'Py_UnicodeFlag', 'Py_IgnoreEnvironmentFlag', - 'Py_DivisionWarningFlag', 'Py_DontWriteBytecodeFlag', 'Py_NoUserSiteDirectory', - '_Py_QnewFlag', 'Py_Py3kWarningFlag', 'Py_HashRandomizationFlag', '_Py_PackageContext', - 'PyOS_InputHook', + 'Py_UseClassExceptionsFlag', 'Py_FrozenFlag', # not part of sys.flags + '_Py_PackageContext', 'PyOS_InputHook', '_PyTraceMalloc_Track', '_PyTraceMalloc_Untrack', 'PyMem_Malloc', 'PyObject_Free', 'PyObject_GC_Del', 'PyType_GenericAlloc', '_PyObject_New', '_PyObject_NewVar', @@ -640,6 +636,30 @@ FORWARD_DECLS = [] INIT_FUNCTIONS = [] BOOTSTRAP_FUNCTIONS = [] +# Keep synchronized with pypy.interpreter.app_main.sys_flags and +# module.sys.app.sysflags. Synchronized in an init_function +_flags = ( + # c name, sys.flags name + ('Py_DebugFlag', 'debug'), + ('Py_Py3kWarningFlag', 'py3k_warning'), + ('Py_DivisionWarningFlag', 'division_warning'), + ('_Py_QnewFlag', 'division_new'), + ('Py_InspectFlag', 'inspect'), + ('Py_InteractiveFlag', 'interactive'), + ('Py_OptimizeFlag', 'optimize'), + ('Py_DontWriteBytecodeFlag', 'dont_write_bytecode'), + ('Py_NoUserSiteDirectory', 'no_user_site'), + ('Py_NoSiteFlag', 'no_site'), + ('Py_IgnoreEnvironmentFlag', 'ignore_environment'), + ('Py_TabcheckFlag', 'tabcheck'), + ('Py_VerboseFlag', 'verbose'), + ('Py_UnicodeFlag', 'unicode'), + ('Py_BytesWarningFlag', 'bytes_warning'), + ('Py_HashRandomizationFlag', 'hash_randomization'), +) + +SYMBOLS_C += [c_name for c_name, _ in _flags] + # this needs to include all prebuilt pto, otherwise segfaults occur register_global('_Py_NoneStruct', 'PyObject*', 'space.w_None', header=pypy_decl) @@ -1168,6 +1188,22 @@ def attach_c_functions(space, eci, prefix): state.C.tuple_new = rffi.llexternal( '_PyPy_tuple_new', [PyTypeObjectPtr, PyObject, PyObject], PyObject, compilation_info=eci, _nowrapper=True) + if we_are_translated(): + eci_flags = eci + else: + # To get this to work in tests, we need a new eci + libs = eci.get_module_files()[1].libraries + eci_flags = ExternalCompilationInfo( + include_dirs=include_dirs, + includes=['Python.h'], + link_extra = libs, + ) + for c_name, attr in _flags: + _, setter = rffi.CExternVariable(rffi.SIGNED, c_name, eci_flags, + _nowrapper=True, c_type='int') + setattr(state.C, 'set_' + attr, setter) + + def init_function(func): INIT_FUNCTIONS.append(func) @@ -1181,6 +1217,13 @@ def run_bootstrap_functions(space): for func in BOOTSTRAP_FUNCTIONS: func(space) +@bootstrap_function +def init_flags(space): + state = space.fromcache(State) + for _, attr in _flags: + f = getattr(state.C, 'set_' + attr) + f(space.sys.get_flag(attr)) + #_____________________________________________________ # Build the bridge DLL, Allow extension DLLs to call # back into Pypy space functions |