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.

classification
Title: _zoneinfo: zoneinfomodule_exec() doesn't check for PyDateTime_IMPORT failure
Type: Stage: resolved
Components: Extension Modules Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Mark.Shannon, miss-islington, shihai1991, vstinner
Priority: normal Keywords: patch

Created on 2021-01-20 17:26 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 24333 merged shihai1991, 2021-01-25 17:31
PR 24351 merged miss-islington, 2021-01-27 10:27
PR 24352 merged vstinner, 2021-01-27 11:04
PR 24356 merged vstinner, 2021-01-28 00:07
Messages (9)
msg385355 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-01-20 17:26
_zoneinfo starts with:

static int
zoneinfomodule_exec(PyObject *m)
{
    PyDateTime_IMPORT;

with:

#define PyDateTime_CAPSULE_NAME "datetime.datetime_CAPI"
#define PyDateTime_IMPORT \
    PyDateTimeAPI = (PyDateTime_CAPI *)PyCapsule_Import(PyDateTime_CAPSULE_NAME, 0)

If PyCapsule_Import() fails, zoneinfomodule_exec() returns 0 (success) with an exception raised.

It should check if the import succeeded or not. Concrete example on AIX where datetime cannot be imported:
https://bugs.python.org/issue42604#msg385347

"./python setup.py build" fails with:

Assertion failed: (item != NULL) ^ (PyErr_Occurred() != NULL), file  Objects/abstract.c, line 163

--

By the way, the import machinery should raise a SystemError if a module exec function raises an exception *and* reports a success: see _Py_CheckFunctionResult().
msg385571 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2021-01-24 07:58
> If PyCapsule_Import() fails, zoneinfomodule_exec() returns 0 (success) with an exception raised.

Why not return -1 directly when PyCapsule_Import() fails?
It looks like more simpler. Do I miss something?
msg385615 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-01-25 10:25
> Why not return -1 directly when PyCapsule_Import() fails?

That would work.

I opened an issue since there is a bug.
msg385754 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-01-27 10:23
New changeset eeb701adc0fc29ba803fddf133d917ff45639a00 by Hai Shi in branch 'master':
bpo-42979: _zoneinfo exec function checks for PyDateTime_IMPORT failure (GH-24333)
https://github.com/python/cpython/commit/eeb701adc0fc29ba803fddf133d917ff45639a00
msg385755 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-01-27 10:28
Thanks for the fix Hai Shi!

> By the way, the import machinery should raise a SystemError if a module exec function raises an exception *and* reports a success: see _Py_CheckFunctionResult().

It's already the case. Example:

>>> import _zoneinfo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: execution of module _zoneinfo raised unreported exception

With this bug:

diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c
index d0c462fb86..fc564b9587 100644
--- a/Modules/_zoneinfo.c
+++ b/Modules/_zoneinfo.c
@@ -2683,6 +2683,7 @@ zoneinfomodule_exec(PyObject *m)
         goto error;
     }
 
+    PyErr_SetString(PyExc_Exception, "BUG");
     return 0;
 
 error:
msg385757 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-01-27 11:09
New changeset 895591c1f0bdec5ad357fe6a5fd0875990061357 by Miss Islington (bot) in branch '3.9':
bpo-42979: _zoneinfo exec function checks for PyDateTime_IMPORT failure (GH-24333) (GH-24351)
https://github.com/python/cpython/commit/895591c1f0bdec5ad357fe6a5fd0875990061357
msg385766 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2021-01-27 12:59
> It's already the case. Example

Nice, interesting case.
msg385787 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-01-27 16:39
New changeset c9b8e9c421b57acdcaf24fab0c93bc29b3ef7c67 by Victor Stinner in branch 'master':
bpo-42979: Enhance abstract.c assertions checking slot result (GH-24352)
https://github.com/python/cpython/commit/c9b8e9c421b57acdcaf24fab0c93bc29b3ef7c67
msg385915 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-01-29 15:53
New changeset a6192635f1e62af2bb8a435487ebb51800edd671 by Victor Stinner in branch 'master':
bpo-42979: Use _Py_CheckSlotResult() to check slots result (GH-24356)
https://github.com/python/cpython/commit/a6192635f1e62af2bb8a435487ebb51800edd671
History
Date User Action Args
2022-04-11 14:59:40adminsetgithub: 87145
2021-01-29 15:53:36vstinnersetmessages: + msg385915
2021-01-28 00:07:45vstinnersetpull_requests: + pull_request23180
2021-01-27 16:39:42Mark.Shannonsetnosy: + Mark.Shannon
messages: + msg385787
2021-01-27 12:59:37shihai1991setmessages: + msg385766
2021-01-27 11:09:05vstinnersetmessages: + msg385757
2021-01-27 11:04:20vstinnersetpull_requests: + pull_request23172
2021-01-27 10:28:15vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg385755

stage: patch review -> resolved
2021-01-27 10:27:23miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request23171
2021-01-27 10:23:42vstinnersetmessages: + msg385754
2021-01-25 17:31:22shihai1991setkeywords: + patch
stage: patch review
pull_requests: + pull_request23152
2021-01-25 10:25:34vstinnersetmessages: + msg385615
2021-01-24 07:58:14shihai1991setnosy: + shihai1991
messages: + msg385571
2021-01-20 17:26:06vstinnercreate