FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-31566: Fix an assertion failure in _warnings.warn() in case of a bad __name__ global by orenmn · Pull Request #3717 · python/cpython · GitHub

Repository navigation

bpo-31566: Fix an assertion failure in _warnings.warn() in case of a bad __name__ global - #3717

Merged
serhiy-storchaka merged 5 commits into
python:masterfrom
orenmn:bpo31566-fix-assert-fail
Sep 24, 2017
Merged

serhiy-storchaka merged 5 commits into
python:masterfrom
orenmn:bpo31566-fix-assert-fail

Conversation

orenmn commented Sep 24, 2017 •
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Contributor
  • in _warnings.c: add a check whether __name__ isn't a string.
  • in test_warnings/__init__.py: add a test to verify that the assertion failure is no more.

https://bugs.python.org/issue31566

serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

There are many ways to handle this issue and this way looks the right way to me.

Comment thread Lib/test/test_warnings/__init__.py Outdated
with support.swap_item(globals(), '__name__', b'foo'), \
support.swap_item(globals(), '__file__', None), \
support.captured_stderr():
self.module.warn('bar')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Raise an exception with -Werror.

Comment thread Python/_warnings.c Outdated
/* Setup module. */
*module = PyDict_GetItemString(globals, "__name__");
if (*module == NULL) {
if (*module == NULL ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This expression is slightly hard to understand. I would rewrite it as

if (*module == Py_None || (*module != NULL && PyUnicode_Check(*module))) {
    Py_INCREF(*module);
}
else {
    ...

or

if (*module != NULL && (*module == Py_None || PyUnicode_Check(*module))) {
    Py_INCREF(*module);
}
else {
    ...

serhiy-storchaka merged commit 5d3e800 into python:master Sep 24, 2017

Copy link
Copy Markdown
Contributor

Thanks @orenmn for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6.
🐍🍒⛏🤖

Copy link
Copy Markdown

GH-3730 is a backport of this pull request to the 3.6 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 24, 2017
serhiy-storchaka pushed a commit that referenced this pull request Sep 24, 2017
… of a bad __name__ global. (GH-3717) (#3730)

(cherry picked from commit 5d3e800)

Copy link
Copy Markdown
Contributor

Thanks @orenmn for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7.
🐍🍒⛏🤖

Copy link
Copy Markdown
Contributor

Sorry, @orenmn and @serhiy-storchaka, I could not cleanly backport this to 2.7 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 5d3e80021ab33360191eb0fbff34e0246c913884 2.7

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants


Back | FazBrowse Home | New Git URL