This instance will be upgraded to Heptapod 0.21.0rc3 on 2021-04-23 at 10:30 UTC+2 (a few minutes of down time)

Commit 8e095afd authored by Matti Picus's avatar Matti Picus

sync Py_.*Flags with sys.flags, issue 3409

parent 8fc65bf4bf6a
Pipeline #18666 failed with stage
in 47 seconds
......@@ -381,6 +381,8 @@ def set_io_encoding(io_encoding, io_encoding_output, errors, overridden):
set_file_encoding(f, encoding, errors)
# Order is significant!
# Keep synchronized with pypy.module.sys.app.sysflags and
# pypy.module.cpyext._flags
sys_flags = (
"debug",
"py3k_warning",
......
......@@ -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
......
......@@ -16,8 +16,8 @@ PyAPI_DATA(int) Py_InspectFlag;
PyAPI_DATA(int) Py_OptimizeFlag;
PyAPI_DATA(int) Py_NoSiteFlag;
PyAPI_DATA(int) Py_BytesWarningFlag;
PyAPI_DATA(int) Py_UseClassExceptionsFlag;
PyAPI_DATA(int) Py_FrozenFlag;
PyAPI_DATA(int) Py_UseClassExceptionsFlag; /* Unused, removed in 3.7 */
PyAPI_DATA(int) Py_FrozenFlag; /* set when the python is "frozen" */
PyAPI_DATA(int) Py_TabcheckFlag;
PyAPI_DATA(int) Py_UnicodeFlag;
PyAPI_DATA(int) Py_IgnoreEnvironmentFlag;
......
......@@ -12,7 +12,8 @@ int Py_DebugFlag = 1;
int Py_VerboseFlag = 0;
int Py_InteractiveFlag = 0;
int Py_InspectFlag = 0;
int Py_OptimizeFlag = 0;
/* intentionally set to -1 for test, should be reset at startup */
int Py_OptimizeFlag = -1;
int Py_NoSiteFlag = 0;
int Py_BytesWarningFlag = 0;
int Py_UseClassExceptionsFlag = 0;
......
......@@ -939,3 +939,15 @@ class AppTestCpythonExtension(AppTestCpythonExtensionBase):
'''
),
])
def test_consistent_flags(self):
import sys
mod = self.import_extension('foo', [
('test_optimize', 'METH_NOARGS',
'''
return PyLong_FromLong(Py_OptimizeFlag);
'''),
])
# This is intentionally set to -1 by default from missing.c
# and should be set to sys.flags.optimize at startup
assert mod.test_optimize() == sys.flags.optimize
......@@ -75,11 +75,11 @@ def callstats():
return None
copyright_str = """
Copyright 2003-2016 PyPy development team.
Copyright 2003-2021 PyPy development team.
All Rights Reserved.
For further information, see <http://pypy.org>
Portions Copyright (c) 2001-2016 Python Software Foundation.
Portions Copyright (c) 2001-2021 Python Software Foundation.
All Rights Reserved.
Portions Copyright (c) 2000 BeOpen.com.
......@@ -92,6 +92,8 @@ Portions Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
All Rights Reserved.
"""
# Keep synchronized with pypy.interpreter.app_main.sys_flags and
# pypy.module.cpyext._flags
# This is tested in test_app_main.py
class sysflags:
......
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