summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2018-03-25 10:44:30 (GMT)
committerGitHub <noreply@github.com>2018-03-25 10:44:30 (GMT)
commitbc77eff8b96be4f035e665ab35c1d06e22f46491 (patch)
tree68ca923578c2ac466dace4ce07b1571c77bae519 /Doc
parentd02ac25ab0879f1a6de6937573bf00a16b7bd22e (diff)
downloadcpython-bc77eff8b96be4f035e665ab35c1d06e22f46491.zip
cpython-bc77eff8b96be4f035e665ab35c1d06e22f46491.tar.gz
cpython-bc77eff8b96be4f035e665ab35c1d06e22f46491.tar.bz2
bpo-33042: Fix pre-initialization sys module configuration (GH-6157)
- new test case for pre-initialization of sys.warnoptions and sys._xoptions - restored ability to call these APIs prior to Py_Initialize - updated the docs for the affected APIs to make it clear they can be called before Py_Initialize - also enhanced the existing embedding test cases to check for expected settings in the sys module
Diffstat (limited to 'Doc')
-rw-r--r--Doc/c-api/init.rst3
-rw-r--r--Doc/c-api/sys.rst15
-rw-r--r--Doc/whatsnew/3.7.rst23
3 files changed, 36 insertions, 5 deletions
diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst
index f2564c4..694b466 100644
--- a/Doc/c-api/init.rst
+++ b/Doc/c-api/init.rst
@@ -31,6 +31,9 @@ The following functions can be safely called before Python is initialized:
* :c:func:`Py_SetProgramName`
* :c:func:`Py_SetPythonHome`
* :c:func:`Py_SetStandardStreamEncoding`
+ * :c:func:`PySys_AddWarnOption`
+ * :c:func:`PySys_AddXOption`
+ * :c:func:`PySys_ResetWarnOptions`
* Informative functions:
diff --git a/Doc/c-api/sys.rst b/Doc/c-api/sys.rst
index e4da96c..994509a 100644
--- a/Doc/c-api/sys.rst
+++ b/Doc/c-api/sys.rst
@@ -205,16 +205,24 @@ accessible to C code. They all work with the current interpreter thread's
.. c:function:: void PySys_ResetWarnOptions()
- Reset :data:`sys.warnoptions` to an empty list.
+ Reset :data:`sys.warnoptions` to an empty list. This function may be
+ called prior to :c:func:`Py_Initialize`.
.. c:function:: void PySys_AddWarnOption(const wchar_t *s)
- Append *s* to :data:`sys.warnoptions`.
+ Append *s* to :data:`sys.warnoptions`. This function must be called prior
+ to :c:func:`Py_Initialize` in order to affect the warnings filter list.
.. c:function:: void PySys_AddWarnOptionUnicode(PyObject *unicode)
Append *unicode* to :data:`sys.warnoptions`.
+ Note: this function is not currently usable from outside the CPython
+ implementation, as it must be called prior to the implicit import of
+ :mod:`warnings` in :c:func:`Py_Initialize` to be effective, but can't be
+ called until enough of the runtime has been initialized to permit the
+ creation of Unicode objects.
+
.. c:function:: void PySys_SetPath(const wchar_t *path)
Set :data:`sys.path` to a list object of paths found in *path* which should
@@ -260,7 +268,8 @@ accessible to C code. They all work with the current interpreter thread's
.. c:function:: void PySys_AddXOption(const wchar_t *s)
Parse *s* as a set of :option:`-X` options and add them to the current
- options mapping as returned by :c:func:`PySys_GetXOptions`.
+ options mapping as returned by :c:func:`PySys_GetXOptions`. This function
+ may be called prior to :c:func:`Py_Initialize`.
.. versionadded:: 3.2
diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst
index 7eb19f0..0b5ad00 100644
--- a/Doc/whatsnew/3.7.rst
+++ b/Doc/whatsnew/3.7.rst
@@ -951,6 +951,14 @@ Build and C API Changes
second argument is *NULL* and the :c:type:`wchar_t*` string contains null
characters. (Contributed by Serhiy Storchaka in :issue:`30708`.)
+- Changes to the startup sequence and the management of dynamic memory
+ allocators mean that the long documented requirement to call
+ :c:func:`Py_Initialize` before calling most C API functions is now
+ relied on more heavily, and failing to abide by it may lead to segfaults in
+ embedding applications. See the :ref:`porting-to-python-37` section in this
+ document and the :ref:`pre-init-safe` section in the C API documentation
+ for more details.
+
Other CPython Implementation Changes
====================================
@@ -1098,6 +1106,7 @@ API and Feature Removals
``asyncio._overlapped``. Replace ``from asyncio import selectors`` with
``import selectors`` for example.
+.. _porting-to-python-37:
Porting to Python 3.7
=====================
@@ -1282,14 +1291,24 @@ Other CPython implementation changes
------------------------------------
* In preparation for potential future changes to the public CPython runtime
- initialization API (see :pep:`432` for details), CPython's internal startup
+ initialization API (see :pep:`432` for an initial, but somewhat outdated,
+ draft), CPython's internal startup
and configuration management logic has been significantly refactored. While
these updates are intended to be entirely transparent to both embedding
applications and users of the regular CPython CLI, they're being mentioned
here as the refactoring changes the internal order of various operations
during interpreter startup, and hence may uncover previously latent defects,
either in embedding applications, or in CPython itself.
- (Contributed by Nick Coghlan and Eric Snow as part of :issue:`22257`.)
+ (Initially contributed by Nick Coghlan and Eric Snow as part of
+ :issue:`22257`, and further updated by Nick, Eric, and Victor Stinner in a
+ number of other issues). Some known details affected:
+
+ * :c:func:`PySys_AddWarnOptionUnicode` is not currently usable by embedding
+ applications due to the requirement to create a Unicode object prior to
+ calling `Py_Initialize`. Use :c:func:`PySys_AddWarnOption` instead.
+ * warnings filters added by an embedding application with
+ :c:func:`PySys_AddWarnOption` should now more consistently take precedence
+ over the default filters set by the interpreter
* Due to changes in the way the default warnings filters are configured,
setting :c:data:`Py_BytesWarningFlag` to a value greater than one is no longer