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

Use WinAPI GetFileType() in is_valid_fd() #90077

Closed
eryksun opened this issue Nov 28, 2021 · 3 comments
Closed

Use WinAPI GetFileType() in is_valid_fd() #90077

eryksun opened this issue Nov 28, 2021 · 3 comments
Labels
3.11 only security fixes easy interpreter-core (Objects, Python, Grammar, and Parser dirs) OS-windows type-feature A feature request or enhancement

Comments

@eryksun
Copy link
Contributor

eryksun commented Nov 28, 2021

BPO 45919
Nosy @pfmoore, @tjguk, @zware, @eryksun, @zooba, @corona10
PRs
  • bpo-45919: Use WinAPI GetFileType() in is_valid_fd() #30082
  • bpo-45919: Remove out of date comment #30090
  • 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 = None
    closed_at = <Date 2021-12-13.13:06:50.961>
    created_at = <Date 2021-11-28.19:21:47.738>
    labels = ['interpreter-core', 'easy', 'type-feature', 'OS-windows', '3.11']
    title = 'Use WinAPI GetFileType() in is_valid_fd()'
    updated_at = <Date 2021-12-14.01:31:45.274>
    user = 'https://github.com/eryksun'

    bugs.python.org fields:

    activity = <Date 2021-12-14.01:31:45.274>
    actor = 'corona10'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-12-13.13:06:50.961>
    closer = 'corona10'
    components = ['Interpreter Core', 'Windows']
    creation = <Date 2021-11-28.19:21:47.738>
    creator = 'eryksun'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 45919
    keywords = ['patch', 'easy (C)']
    message_count = 3.0
    messages = ['407221', '408449', '408511']
    nosy_count = 6.0
    nosy_names = ['paul.moore', 'tim.golden', 'zach.ware', 'eryksun', 'steve.dower', 'corona10']
    pr_nums = ['30082', '30090']
    priority = 'normal'
    resolution = None
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue45919'
    versions = ['Python 3.11']

    @eryksun
    Copy link
    Contributor Author

    eryksun commented Nov 28, 2021

    During startup, is_valid_fd() in Python/pylifecycle.c is called to validate stdin, stdout, and stderr. Performance isn't critical here, but every bit helps in reducing startup time. In my tests, implementing this check in Windows via GetFileType((HANDLE)_get_osfhandle(fd)) is 5-6 times faster than close(dup(fd)). For example:

    #if defined(MS_WINDOWS)
        HANDLE hfile;
        _Py_BEGIN_SUPPRESS_IPH
        hfile = (HANDLE)_get_osfhandle(fd);
        _Py_END_SUPPRESS_IPH
        return (hfile != INVALID_HANDLE_VALUE &&
                  GetFileType(hfile) != FILE_TYPE_UNKNOWN);
    #endif

    @eryksun eryksun added 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) OS-windows easy type-feature A feature request or enhancement labels Nov 28, 2021
    @corona10
    Copy link
    Member

    New changeset 191c431 by Dong-hee Na in branch 'main':
    bpo-45919: Use WinAPI GetFileType() in is_valid_fd() (GH-30082)
    191c431

    @corona10
    Copy link
    Member

    New changeset 9130a4d by Dong-hee Na in branch 'main':
    bpo-45919: Remove out of date comment (GH-30090)
    9130a4d

    @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
    3.11 only security fixes easy interpreter-core (Objects, Python, Grammar, and Parser dirs) OS-windows type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants