Skip to content
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

Check for errors when using PyTokenizer_FindEncoding() #48023

Closed
brettcannon opened this issue Sep 4, 2008 · 10 comments
Closed

Check for errors when using PyTokenizer_FindEncoding() #48023

brettcannon opened this issue Sep 4, 2008 · 10 comments
Assignees
Labels
deferred-blocker interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@brettcannon
Copy link
Member

BPO 3773
Nosy @brettcannon, @amauryfa, @benjaminp
Files
  • check_findencoding_errors.diff: Call PyErr_Occurred() to verify no error when using PyTokenizer_FindEncoding()
  • check_findencoding_malloc.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/amauryfa'
    closed_at = <Date 2008-09-04.23:24:33.836>
    created_at = <Date 2008-09-04.05:24:14.253>
    labels = ['interpreter-core', 'deferred-blocker', 'type-bug']
    title = 'Check for errors when using PyTokenizer_FindEncoding()'
    updated_at = <Date 2008-09-04.23:24:33.825>
    user = 'https://github.com/brettcannon'

    bugs.python.org fields:

    activity = <Date 2008-09-04.23:24:33.825>
    actor = 'amaury.forgeotdarc'
    assignee = 'amaury.forgeotdarc'
    closed = True
    closed_date = <Date 2008-09-04.23:24:33.836>
    closer = 'amaury.forgeotdarc'
    components = ['Interpreter Core']
    creation = <Date 2008-09-04.05:24:14.253>
    creator = 'brett.cannon'
    dependencies = []
    files = ['11371', '11376']
    hgrepos = []
    issue_num = 3773
    keywords = ['patch']
    message_count = 10.0
    messages = ['72484', '72489', '72513', '72514', '72515', '72539', '72542', '72543', '72545', '72554']
    nosy_count = 3.0
    nosy_names = ['brett.cannon', 'amaury.forgeotdarc', 'benjamin.peterson']
    pr_nums = []
    priority = 'deferred blocker'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue3773'
    versions = ['Python 3.0']

    @brettcannon
    Copy link
    Member Author

    The patch adds two lines to call_find_module() to check for errors after
    calling PyTokenizer_FindEncoding() since it returns NULL as a default
    value so a call to PyErr_Occurred() is needed.

    @brettcannon brettcannon added release-blocker interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Sep 4, 2008
    @brettcannon brettcannon changed the title Check for errors Check for errors when using PyTokenizer_FindEncoding() Sep 4, 2008
    @amauryfa
    Copy link
    Member

    amauryfa commented Sep 4, 2008

    In PyTokenizer_FindEncoding(), PyMem_MALLOC may return NULL.
    Another patch attached.

    @brettcannon
    Copy link
    Member Author

    If PyMem_MALLOC() returns NULL, shouldn't MemoryError be set?

    @amauryfa
    Copy link
    Member

    amauryfa commented Sep 4, 2008

    Right, here is an updated patch

    @brettcannon
    Copy link
    Member Author

    Your patch looks fine, Amaury.

    @benjaminp
    Copy link
    Contributor

    I think this patch should be reverted. It causes a linking error because
    pgen isn't linked to libpython; it doesn't find the _PyErr_NoMemory symbol.

    @amauryfa
    Copy link
    Member

    amauryfa commented Sep 4, 2008

    pgen does not exist on Windows...

    What if I simply remove the call to PyErr_NoMemory?
    It is not strictly necessary: the function already returns NULL without
    an exception set, for example when the file cannot be opened.

    @benjaminp
    Copy link
    Contributor

    On Thu, Sep 4, 2008 at 5:48 PM, Amaury Forgeot d'Arc
    <report@bugs.python.org> wrote:

    Amaury Forgeot d'Arc <amauryfa@gmail.com> added the comment:

    pgen does not exist on Windows...

    What if I simply remove the call to PyErr_NoMemory?
    It is not strictly necessary: the function already returns NULL without
    an exception set, for example when the file cannot be opened.

    That sounds ok. I can't remember what the rest of the parse does when
    there's no memory, though.


    Python tracker <report@bugs.python.org>
    <http://bugs.python.org/issue3773\>


    @benjaminp
    Copy link
    Contributor

    You could also surround the PyErr_NoMemory with #ifndef PGEN.

    @amauryfa
    Copy link
    Member

    amauryfa commented Sep 4, 2008

    committed r66224 + r66225.

    @amauryfa amauryfa closed this as completed Sep 4, 2008
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    deferred-blocker interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants