pythonの実行方法色々あります(-m をつけたり、pipelineで実行したりREPL(interactive prompt)を使ってり)
実行するうえで3要素が必要となる:
input → (config, state, modules) → runtime → output
Py_
がついてればpublic function_Py
が最初についてれば、loaderからアクセス可能な内部関数実行する前にconfigを確立するよ
configuration of the runtimeは大きく3つ (詳細は https://www.python.org/dev/peps/pep-0587/ )
Include/cpython/initconfig.h
Preinitialization Configutration
Include/cpython/initconfig.h
, Python/initconfig.c
Runtime Configuration Data Structure
Setting Runtime Conguration with the Command Line
verbose mode: 開発者がcpythonデバッグするためのモード、 -v
flagで指定できる。
./python.exe -v -c "print('hello')"
みたいに実行すると、cpythonの実行ログがすごい出てくるconfig->verbose
は -1
が代入されているPYTHONVERBOSE
を使って、 config->verbose
に値を代入する
-1
にするconfig_parse_cmdline
で、command line optionの値をsetする_Py_GetGlobalVariablesAsDict
でglobal変数 Py_VerboseFlag
にsetされるverbose modeに限らず大体こんな感じ
Viewing Runtime Flags
runtime flags : advanced feature CPython-specific behaviors
sys.flags
でアクセスできる-X
flagで指定したattributeは sys._xoptions
でdict形式で見ることができる$ ./python.exe -X dev -q
>>> import sys
>>> sys.flags
sys.flags(debug=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, verbose=0, bytes_warning=0, quiet=1,
hash_randomization=1, isolated=0, dev_mode=True, utf8_mode=0)
>>> sys._xoptions
{'dev': True}
pyconfig.h
にあるよ./configure
すると設定される