Navigation Menu

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

Clean up path_converter in posixmodule.c #70858

Closed
serhiy-storchaka opened this issue Mar 30, 2016 · 13 comments
Closed

Clean up path_converter in posixmodule.c #70858

serhiy-storchaka opened this issue Mar 30, 2016 · 13 comments
Assignees
Labels
extension-modules C modules in the Modules dir type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

BPO 26671
Nosy @vstinner, @larryhastings, @vadmium, @serhiy-storchaka
Files
  • path_converter_cleanup.patch
  • path_converter_cleanup_2.patch
  • path_converter_cleanup_3.patch
  • 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/serhiy-storchaka'
    closed_at = <Date 2016-04-08.05:49:25.604>
    created_at = <Date 2016-03-30.09:31:14.450>
    labels = ['extension-modules', 'type-feature']
    title = 'Clean up path_converter in posixmodule.c'
    updated_at = <Date 2016-04-08.05:49:25.603>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2016-04-08.05:49:25.603>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2016-04-08.05:49:25.604>
    closer = 'serhiy.storchaka'
    components = ['Extension Modules']
    creation = <Date 2016-03-30.09:31:14.450>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['42327', '42341', '42380']
    hgrepos = []
    issue_num = 26671
    keywords = ['patch']
    message_count = 13.0
    messages = ['262657', '262695', '262734', '262950', '262953', '262954', '262955', '262956', '262959', '262961', '263005', '263007', '263008']
    nosy_count = 5.0
    nosy_names = ['vstinner', 'larry', 'python-dev', 'martin.panter', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue26671'
    versions = ['Python 3.6']

    @serhiy-storchaka
    Copy link
    Member Author

    path_converter in Modules/posixmodule.c sequentially tries to convert an argument to str, bytes, and int. If previous conversion is failed, it clears the error and tries with type. This can hide some errors (such as MemoryError) and even cause using unexpected conversion.

    Proposed patch cleans up path_converter. In addition it avoids copying the content of instances of string subclass.

    @serhiy-storchaka serhiy-storchaka self-assigned this Mar 30, 2016
    @serhiy-storchaka serhiy-storchaka added extension-modules C modules in the Modules dir type-feature A feature request or enhancement labels Mar 30, 2016
    @larryhastings
    Copy link
    Contributor

    I approve in principle, but this patch isn't ready.

    If we compile on Win32, and allow_fd is on, and they pass in an invalid fd, your patched code will reach line 914 "length = PyBytes_GET_SIZE(bytes);" but bytes will be uninitialized.

    @serhiy-storchaka
    Copy link
    Member Author

    Good catch! Here is updated patch. It fixes also hiding exception in dir_fd converter.

    @larryhastings
    Copy link
    Contributor

    Can you post the updated patch please?

    @serhiy-storchaka
    Copy link
    Member Author

    Here it is.

    @larryhastings
    Copy link
    Contributor

    LGTM.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 6, 2016

    New changeset a866f5727b7f by Serhiy Storchaka in branch 'default':
    Issue bpo-26671: Enhanced path_converter.
    https://hg.python.org/cpython/rev/a866f5727b7f

    @serhiy-storchaka
    Copy link
    Member Author

    Thank you for your review Larry.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 6, 2016

    New changeset 8dc144e47252 by Serhiy Storchaka in branch 'default':
    Issue bpo-26671: Fixed #ifdef indentation.
    https://hg.python.org/cpython/rev/8dc144e47252

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 6, 2016

    New changeset 4acdb324a430 by Serhiy Storchaka in branch 'default':
    Issue bpo-26671: Fixed #ifdef indentation.
    https://hg.python.org/cpython/rev/4acdb324a430

    @vadmium
    Copy link
    Member

    vadmium commented Apr 8, 2016

    Looks like the tests may need updating for a changed exception message:

    http://buildbot.python.org/all/builders/x86%20Ubuntu%20Shared%203.x/builds/12996/steps/test/logs/stdio
    ======================================================================
    FAIL: test_stat (test.test_posix.PosixTester)
    ----------------------------------------------------------------------
    TypeError: stat: path should be string, bytes or integer, not NoneType

    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/srv/buildbot/buildarea/3.x.bolen-ubuntu/build/Lib/test/test_posix.py", line 415, in test_stat
        posix.stat, None)
    AssertionError: "can't specify None for path argument" does not match "stat: path should be string, bytes or integer, not NoneType"

    ======================================================================
    FAIL: test_stat_dir_fd (test.test_posix.PosixTester)
    ----------------------------------------------------------------------
    TypeError: argument should be integer or None, not str

    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/srv/buildbot/buildarea/3.x.bolen-ubuntu/build/Lib/test/test_posix.py", line 867, in test_stat_dir_fd
        posix.stat, support.TESTFN, dir_fd=posix.getcwd())
    AssertionError: "should be integer, not" does not match "argument should be integer or None, not str"

    @vadmium vadmium reopened this Apr 8, 2016
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 8, 2016

    New changeset 633bb190fb76 by Serhiy Storchaka in branch 'default':
    Issue bpo-26671: Fixed tests for changed error messages.
    https://hg.python.org/cpython/rev/633bb190fb76

    @serhiy-storchaka
    Copy link
    Member Author

    Thank you Martin.

    @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
    extension-modules C modules in the Modules dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants