summaryrefslogtreecommitdiff
path: root/Python/pystate.c
AgeCommit message (Collapse)AuthorLines
2018-12-04bpo-35414: Add a missing Py_INCREF(Py_None) in PyState_RemoveModule(). ↵Miss Islington (bot)-0/+1
(GH-10914) (cherry picked from commit 2a893430c9c8378cbdfac95895a64fa07aaff9ed) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
2018-05-23bpo-33612: Remove PyThreadState_Clear() assertion (GH-7069) (GH-7074)Miss Islington (bot)-1/+0
bpo-25612, bpo-33612: Remove an assertion from PyThreadState_Clear() which failed at Python shutdown or on fork if a thread was running a generator. (cherry picked from commit b6dccf54fd3bac9c87348d96f9d6b571608c15bc) Co-authored-by: Victor Stinner <vstinner@redhat.com>
2018-05-15bpo-32604: Remove xid registry. (#6813)Eric Snow-258/+0
Remove the interpreters testing helper (and xid registry).
2018-03-06bpo-33005: Fix _PyGILState_Reinit() (GH-6001)Miss Islington (bot)-4/+23
Fix a crash on fork when using a custom memory allocator (ex: using PYTHONMALLOC env var). _PyGILState_Reinit() and _PyInterpreterState_Enable() now use the default RAW memory allocator to allocate a new interpreters mutex on fork. (cherry picked from commit 5d92647102fac9e116b98ab8bbc632eeed501c34) Co-authored-by: Victor Stinner <victor.stinner@gmail.com>
2018-02-20bpo-32604: Swap threads only if the interpreter is different. (gh-5783)Miss Islington (bot)-6/+14
The CPython runtime assumes that there is a one-to-one relationship (for a given interpreter) between PyThreadState and OS threads. Sending and receiving on a channel in the same interpreter was causing crashes because of this (specifically due to a check in PyThreadState_Swap()). The solution is to not switch threads if the interpreter is the same. (cherry picked from commit f53d9f2778a87bdd48eb9030f782a4ebf9e7622f) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2018-02-16bpo-32604: Clean up created subinterpreters before runtime finalization. ↵Miss Islington (bot)-1/+57
(gh-5710) (cherry picked from commit 4c6955e2b0ccf88c705f8d1fac685a8e65f9699e) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2018-02-02bpo-32604: Fix memory leaks in the new _xxsubinterpreters module. (GH-5507)Miss Islington (bot)-0/+1
(cherry picked from commit 4e9da0d163731caa79811c723c703ee416c31826) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2018-01-29bpo-32604: Expose the subinterpreters C-API in a "private" stdlib module. ↵Eric Snow-1/+274
(gh-1748) The module is primarily intended for internal use in the test suite. Building the module under Windows will come in a follow-up PR.
2018-01-22bpo-32436: Implement PEP 567 (#5027)Yury Selivanov-0/+9
2018-01-21bpo-32591: Add native coroutine origin tracking (#5250)Nathaniel J. Smith-0/+2
* Add coro.cr_origin and sys.set_coroutine_origin_tracking_depth * Use coroutine origin information in the unawaited coroutine warning * Stop using set_coroutine_wrapper in asyncio debug mode * In BaseEventLoop.set_debug, enable debugging in the correct thread
2017-12-20bpo-31901: atexit callbacks should be run at subinterpreter shutdown (#4611)Marcel Plch-0/+2
Change atexit behavior and PEP-489 multiphase init support.
2017-12-15bpo-32030: Add _PyCoreConfig_Copy() (#4874)Victor Stinner-0/+2
Each interpreter now has its core_config and main_config copy: * Add _PyCoreConfig_Copy() and _PyMainInterpreterConfig_Copy() * Move _PyCoreConfig_Read(), _PyCoreConfig_Clear() and _PyMainInterpreterConfig_Clear() from Python/pylifecycle.c to Modules/main.c * Fix _Py_InitializeEx_Private(): call _PyCoreConfig_ReadEnv() before _Py_InitializeCore()
2017-11-30bpo-20891: Fix PyGILState_Ensure() (#4650)Victor Stinner-6/+18
When PyGILState_Ensure() is called in a non-Python thread before PyEval_InitThreads(), only call PyEval_InitThreads() after calling PyThreadState_New() to fix a crash. Add an unit test in test_embed.
2017-11-29bpo-32030: Rework memory allocators (#4625)Victor Stinner-7/+19
* Fix _PyMem_SetupAllocators("debug"): always restore allocators to the defaults, rather than only caling _PyMem_SetupDebugHooks(). * Add _PyMem_SetDefaultAllocator() helper to set the "default" allocator. * Add _PyMem_GetAllocatorsName(): get the name of the allocators * main() now uses debug hooks on memory allocators if Py_DEBUG is defined, rather than calling directly malloc() * Document default memory allocators in C API documentation * _Py_InitializeCore() now fails with a fatal user error if PYTHONMALLOC value is an unknown memory allocator, instead of failing with a fatal internal error. * Add new tests on the PYTHONMALLOC environment variable * Add support.with_pymalloc() * Add the _testcapi.WITH_PYMALLOC constant and expose it as support.with_pymalloc(). * sysconfig.get_config_var('WITH_PYMALLOC') doesn't work on Windows, so replace it with support.with_pymalloc(). * pythoninfo: add _testcapi collector for pymem
2017-11-24bpo-32096: Remove obj and mem from _PyRuntime (#4532)Victor Stinner-2/+0
bpo-32096, bpo-30860: Partially revert the commit 2ebc5ce42a8a9e047e790aefbf9a94811569b2b6: * Move structures back from Include/internal/mem.h to Objects/obmalloc.c * Remove _PyObject_Initialize() and _PyMem_Initialize() * Remove Include/internal/pymalloc.h * Add test_capi.test_pre_initialization_api(): Make sure that it's possible to call Py_DecodeLocale(), and then call Py_SetProgramName() with the decoded string, before Py_Initialize(). PyMem_RawMalloc() and Py_DecodeLocale() can be called again before _PyRuntimeState_Init(). Co-Authored-By: Eric Snow <ericsnowcurrently@gmail.com>
2017-11-23bpo-32030: Add _PyCoreConfig.module_search_path_env (#4504)Victor Stinner-40/+45
Changes: * Py_Main() initializes _PyCoreConfig.module_search_path_env from the PYTHONPATH environment variable. * PyInterpreterState_New() now initializes core_config and config fields * Compute sys.path a little bit ealier in _Py_InitializeMainInterpreter() and new_interpreter() * Add _Py_GetPathWithConfig() private function.
2017-11-16bpo-32043: New "developer mode": "-X dev" option (#4413)Victor Stinner-0/+8
Add a new "developer mode": new "-X dev" command line option to enable debug checks at runtime. Changes: * Add unit tests for -X dev * test_cmd_line: replace test.support with support. * Fix _PyRuntimeState_Fini(): Use the same memory allocator than _PyRuntimeState_Init(). * Fix _PyMem_GetDefaultRawAllocator()
2017-11-15bpo-32030: Enhance Py_Main() (#4412)Victor Stinner-3/+5
Parse more env vars in Py_Main(): * Add more options to _PyCoreConfig: * faulthandler * tracemalloc * importtime * Move code to parse environment variables from _Py_InitializeCore() to Py_Main(). This change fixes a regression from Python 3.6: PYTHONUNBUFFERED is now read before calling pymain_init_stdio(). * _PyFaulthandler_Init() and _PyTraceMalloc_Init() now take an argument to decide if the module has to be enabled at startup. * tracemalloc_start() is now responsible to check the maximum number of frames. Other changes: * Cleanup Py_Main(): * Rename some pymain_xxx() subfunctions * Add pymain_run_python() subfunction * Cleanup Py_NewInterpreter() * _PyInterpreterState_Enable() now reports failure * init_hash_secret() now considers pyurandom() failure as an "user error": don't fail with abort(). * pymain_optlist_append() and pymain_strdup() now sets err on memory allocation failure.
2017-11-15bpo-32030: Split Py_Main() into subfunctions (#4399)Victor Stinner-7/+9
* Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
2017-10-26Fix trailing whitespaces in C files. (#4130)Serhiy Storchaka-1/+1
2017-10-25bpo-31857: Make the behavior of USE_STACKCHECK deterministic (#4098)pdox-0/+1
2017-10-22Move exc state to generator. Fixes bpo-25612 (#1773)Mark Shannon-6/+15
Move exception state information from frame objects to coroutine (generator/thread) object where it belongs.
2017-10-06bpo-25658: Implement PEP 539 for Thread Specific Storage (TSS) API (GH-1362)Masayuki Yamamoto-33/+38
See PEP 539 for details. Highlights of changes: - Add Thread Specific Storage (TSS) API - Document the Thread Local Storage (TLS) API as deprecated - Update code that used TLS API to use TSS API
2017-09-14bpo-30860: Fix a refleak. (#3567)Eric Snow-2/+0
Resolves bpo-31420. (This was accidentally reverted when in #3565.)
2017-09-13bpo-31404: Revert "remove modules from Py_InterpreterState (#1638)" (#3565)Eric Snow-0/+4
PR #1638, for bpo-28411, causes problems in some (very) edge cases. Until that gets sorted out, we're reverting the merge. PR #3506, a fix on top of #1638, is also getting reverted.
2017-09-11bpo-30860: Fix a refleak. (#3506)Eric Snow-2/+0
* Drop warnoptions from PyInterpreterState. * Drop xoptions from PyInterpreterState. * Don't set warnoptions and _xoptions again. * Decref after adding to sys.__dict__. * Drop an unused macro. * Check sys.xoptions *before* we delete it.
2017-09-07bpo-30860: Consolidate stateful runtime globals. (#3397)Eric Snow-80/+99
* group the (stateful) runtime globals into various topical structs * consolidate the topical structs under a single top-level _PyRuntimeState struct * add a check-c-globals.py script that helps identify runtime globals Other globals are excluded (see globals.txt and check-c-globals.py).
2017-09-07bpo-31370: Remove support for threads-less builds (#3385)Antoine Pitrou-29/+1
* Remove Setup.config * Always define WITH_THREAD for compatibility.
2017-09-05Revert "bpo-30860: Consolidate stateful runtime globals." (#3379)Eric Snow-106/+87
Windows buildbots started failing due to include-related errors.
2017-09-05correct initialization code (#3376)Benjamin Peterson-2/+1
Explicitly initialize struct members rather than relying on compiler extensions.
2017-09-05bpo-30860: Consolidate stateful runtime globals. (#2594)Eric Snow-87/+107
* group the (stateful) runtime globals into various topical structs * consolidate the topical structs under a single top-level _PyRuntimeState struct * add a check-c-globals.py script that helps identify runtime globals Other globals are excluded (see globals.txt and check-c-globals.py).
2017-09-04bpo-28411: Remove "modules" field from Py_InterpreterState. (#1638)Eric Snow-2/+0
sys.modules is the one true source.
2017-06-21bpo-30604: clean up co_extra support (#2144)Dino Viehland-1/+1
bpo-30604: port fix from 3.6 dropping binary compatibility tweaks
2017-05-28Doc nits for bpo-16500 (#1841)Antoine Pitrou-1/+1
* Doc nits for bpo-16500 * Fix more references
2017-05-27bpo-16500: Allow registering at-fork handlers (#1715)Antoine Pitrou-0/+10
* bpo-16500: Allow registering at-fork handlers * Address Serhiy's comments * Add doc for new C API * Add doc for new Python-facing function * Add NEWS entry + doc nit
2017-05-22bpo-22257: Small changes for PEP 432. (#1728)Eric Snow-0/+16
PEP 432 specifies a number of large changes to interpreter startup code, including exposing a cleaner C-API. The major changes depend on a number of smaller changes. This patch includes all those smaller changes.
2017-05-22bpo-29102: Add a unique ID to PyInterpreterState. (#1639)Eric Snow-0/+37
2017-05-22bpo-30395 _PyGILState_Reinit deadlock fix (#1734)Jason Fried-0/+4
head_lock could be held by another thread when fork happened. We should reset it to avoid deadlock.
2017-03-23bpo-6532: Make the thread id an unsigned integer. (#781)Serhiy Storchaka-2/+3
* bpo-6532: Make the thread id an unsigned integer. From C API side the type of results of PyThread_start_new_thread() and PyThread_get_thread_ident(), the id parameter of PyThreadState_SetAsyncExc(), and the thread_id field of PyThreadState changed from "long" to "unsigned long". * Restore a check in thread_get_ident().
2016-09-09remove ceval timestamp supportBenjamin Peterson-3/+0
2016-09-08Issue #28003: Implement PEP 525 -- Asynchronous Generators.Yury Selivanov-0/+5
2016-09-07Add the co_extra field and accompanying APIs to code objects.Brett Cannon-0/+1
This completes PEP 523.
2016-09-06replace Py_(u)intptr_t with the c99 standard typesBenjamin Peterson-1/+1
2016-09-05Implement the frame evaluation API aspect of PEP 523.Brett Cannon-0/+1
2016-08-22Issue #27587: Merge from 3.5Berker Peksag-2/+4
2016-08-22Issue #27587: Move null pointer check earlier in _PyState_AddModule()Berker Peksag-2/+4
This was found by PVS-Studio: V595 The 'def' pointer was utilized before it was verified against nullptr. Check lines: 286, 292. pystate.c 286 Initial patch by Christian Heimes.
2016-08-02Issue #22557: Now importing already imported modules is up to 2.5 times faster.Serhiy Storchaka-0/+2
2016-05-04Issue #26932: Fixed support of RTLD_* constants defined as enum values,Serhiy Storchaka-2/+2
not via macros (in particular on Android). Patch by Chi Hsuan Yen.
2016-03-16faulthandler now works in non-Python threadsVictor Stinner-0/+6
Issue #26563: * Add _PyGILState_GetInterpreterStateUnsafe() function: the single PyInterpreterState used by this process' GILState implementation. * Enhance _Py_DumpTracebackThreads() to retrieve the interpreter state from autoInterpreterState in last resort. The function now accepts NULL for interp and current_tstate parameters. * test_faulthandler: fix a ResourceWarning when test is interrupted by CTRL+c
2016-03-14Add more checks on the GILVictor Stinner-5/+19
Issue #10915, #15751, #26558: * PyGILState_Check() now returns 1 (success) before the creation of the GIL and after the destruction of the GIL. It allows to use the function early in Python initialization and late in Python finalization. * Add a flag to disable PyGILState_Check(). Disable PyGILState_Check() when Py_NewInterpreter() is called * Add assert(PyGILState_Check()) to: _Py_dup(), _Py_fstat(), _Py_read() and _Py_write()