This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients eric.snow, htgoebel, ncoghlan, vstinner
Date 2018-03-12.13:33:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1520861603.18.0.467229070634.issue33042@psf.upfronthosting.co.za>
In-reply-to
Content
Python documentation was enhanced in Python 3.7 to explicitly list all functions safe to call *before* Py_Initialize():

https://docs.python.org/dev/c-api/init.html#before-python-initialization

PySys_AddWarnOption() is not part of the list. While it's not in the list, I'm kind of unhappy that we broke your use case: it wasn't my intent. Because I broken your use case with this change part of the big bpo-32030 refactoring:

commit f7e5b56c37eb859e225e886c79c5d742c567ee95
Author: Victor Stinner <victor.stinner@gmail.com>
Date:   Wed Nov 15 15:48:08 2017 -0800

    bpo-32030: Split Py_Main() into subfunctions (#4399)

IHMO the regression is that PySys_AddWarnOption() now calls _PySys_GetObjectId(): in Python 3.6, it wasn't the case.

Python 3.6 code:
---
void
PySys_AddWarnOptionUnicode(PyObject *unicode)
{
    if (warnoptions == NULL || !PyList_Check(warnoptions)) {
        Py_XDECREF(warnoptions);
        warnoptions = PyList_New(0);
        if (warnoptions == NULL)
            return;
    }
    PyList_Append(warnoptions, unicode);
}
---

Again, it's a bad idea to use the Python API before Py_Initialize(): you likely have to build a Unicode string and you use a list, whereas these two object types are not properly initialized...

The PEP 432 and bpo-32030 prepared Python to have a much better API in Python 3.8 for embedding Python. You will be able to use a wchar_t* string to pass warning options.
History
Date User Action Args
2018-03-12 13:33:23vstinnersetrecipients: + vstinner, htgoebel, ncoghlan, eric.snow
2018-03-12 13:33:23vstinnersetmessageid: <1520861603.18.0.467229070634.issue33042@psf.upfronthosting.co.za>
2018-03-12 13:33:23vstinnerlinkissue33042 messages
2018-03-12 13:33:23vstinnercreate