Skip to content

bpo-35373: Fix PyInit_time() error handling #10865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2018
Merged

bpo-35373: Fix PyInit_time() error handling #10865

merged 1 commit into from
Dec 3, 2018

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Dec 3, 2018

  • PyInit_time() now returns NULL if an exception is raised.
  • Rename PyInit_timezone() to pytime_init_timezone(). "PyInit_"
    prefix is a special prefix for function initializing a module.
    pytime_init_timezone() doesn't initialize a module and the function
    is not exported.

https://bugs.python.org/issue35373

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't fix all problems with errors handling and PyModule_AddObject(), but makes the code a tiny bit better.

* PyInit_time() now returns NULL if an exception is raised.
* Rename PyInit_timezone() to init_timezone(). "PyInit_" prefix is
  a special prefix for function initializing a module.
  init_timezone() doesn't initialize a module and the function is not
  exported.
@vstinner
Copy link
Member Author

vstinner commented Dec 3, 2018

This doesn't fix all problems with errors handling and PyModule_AddObject(), but makes the code a tiny bit better.

If PyInit_time() returns non-NULL value, _PyImport_LoadDynamicModuleWithSpec() should go into this code path:

    } else if (PyErr_Occurred()) {
        PyErr_Clear();
        PyErr_Format(
            PyExc_SystemError,
            "initialization of %s raised unreported exception",
            name_buf);
        m = NULL;
        goto error;
    }

It clears the raised exception and raise a new one :-( This PR should make the code a little bit better, but I know that it's not perfect :-)

@vstinner vstinner merged commit 3bb150d into python:master Dec 3, 2018
@vstinner vstinner deleted the pyinit_time branch December 3, 2018 12:45
vstinner added a commit that referenced this pull request Dec 3, 2018
* bpo-35373: Fix PyInit_timezone() error handling

PyInit_timezone() now returns -1 at exit if an exception is raised.
Check also explicitly PyUnicode_DecodeLocale() and Py_BuildValue()
errors.

* bpo-35373: Fix PyInit_time() error handling (GH-10865)

* PyInit_time() now returns NULL if an exception is raised.
* Rename PyInit_timezone() to init_timezone(). "PyInit_" prefix is
  a special prefix for function initializing a module.
  init_timezone() doesn't initialize a module and the function is not
  exported.

(cherry picked from commit 3bb150d)
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 3, 2018
* bpo-35373: Fix PyInit_timezone() error handling

PyInit_timezone() now returns -1 at exit if an exception is raised.
Check also explicitly PyUnicode_DecodeLocale() and Py_BuildValue()
errors.

* bpo-35373: Fix PyInit_time() error handling (pythonGH-10865)

* PyInit_time() now returns NULL if an exception is raised.
* Rename PyInit_timezone() to init_timezone(). "PyInit_" prefix is
  a special prefix for function initializing a module.
  init_timezone() doesn't initialize a module and the function is not
  exported.

(cherry picked from commit 3bb150d)
(cherry picked from commit 5eb78c7)

Co-authored-by: Victor Stinner <vstinner@redhat.com>
miss-islington added a commit that referenced this pull request Dec 3, 2018
* bpo-35373: Fix PyInit_timezone() error handling

PyInit_timezone() now returns -1 at exit if an exception is raised.
Check also explicitly PyUnicode_DecodeLocale() and Py_BuildValue()
errors.

* bpo-35373: Fix PyInit_time() error handling (GH-10865)

* PyInit_time() now returns NULL if an exception is raised.
* Rename PyInit_timezone() to init_timezone(). "PyInit_" prefix is
  a special prefix for function initializing a module.
  init_timezone() doesn't initialize a module and the function is not
  exported.

(cherry picked from commit 3bb150d)
(cherry picked from commit 5eb78c7)

Co-authored-by: Victor Stinner <vstinner@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants