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

Not very good strcpy implementation in cpython/Python/strdup.c #85512

Closed
wasiher mannequin opened this issue Jul 19, 2020 · 11 comments
Closed

Not very good strcpy implementation in cpython/Python/strdup.c #85512

wasiher mannequin opened this issue Jul 19, 2020 · 11 comments
Labels
3.10 only security fixes performance Performance or resource usage topic-C-API

Comments

@wasiher
Copy link
Mannequin

wasiher mannequin commented Jul 19, 2020

BPO 41340
Nosy @benjaminp, @methane, @shihai1991, @wasiher
PRs
  • bpo-41340: Removed strcpy from strdup function #21544
  • bpo-41340: Removed fallback implementation for strdup #21634
  • 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 2020-07-27.03:29:02.695>
    created_at = <Date 2020-07-19.10:36:04.764>
    labels = ['expert-C-API', '3.10', 'performance']
    title = 'Not very good strcpy implementation in cpython/Python/strdup.c'
    updated_at = <Date 2020-07-27.03:29:02.694>
    user = 'https://github.com/wasiher'

    bugs.python.org fields:

    activity = <Date 2020-07-27.03:29:02.694>
    actor = 'methane'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-07-27.03:29:02.695>
    closer = 'methane'
    components = ['C API']
    creation = <Date 2020-07-19.10:36:04.764>
    creator = 'fj92f3jj923f923'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41340
    keywords = ['patch']
    message_count = 11.0
    messages = ['373955', '373976', '373986', '373989', '374199', '374241', '374302', '374319', '374345', '374353', '374359']
    nosy_count = 4.0
    nosy_names = ['benjamin.peterson', 'methane', 'shihai1991', 'fj92f3jj923f923']
    pr_nums = ['21544', '21634']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue41340'
    versions = ['Python 3.10']

    @wasiher
    Copy link
    Mannequin Author

    wasiher mannequin commented Jul 19, 2020

    Hi, all!

    strdup implementation inside cpython/Python/strdup.c is not the best one.
    It calls strlen + strcpy, which is the same as calling strlen twice + memcpy.
    So I replaced it by the call of strlen + memcpy.

    It is easy to look any implementation in any library.
    Here for example:
    https://code.woboq.org/userspace/glibc/string/strdup.c.html

    So I fixed it here:
    #21544

    @wasiher wasiher mannequin added 3.10 only security fixes topic-C-API performance Performance or resource usage labels Jul 19, 2020
    @benjaminp
    Copy link
    Contributor

    I don't think we need to spend much effort on this implementation, since it will only be used if the system libc doesn't have a strdup already.

    @wasiher
    Copy link
    Mannequin Author

    wasiher mannequin commented Jul 20, 2020

    Got it.
    But the fix is quite easy as I see, and does not require much affort too.

    @methane
    Copy link
    Member

    methane commented Jul 20, 2020

    Can we just remove strdup.c? How about hypot.c?

    @gvanrossum
    Copy link
    Member

    Either remove it or close this issue as won’t fix.

    @shihai1991
    Copy link
    Member

    What's change for the performance benchmark?

    @methane
    Copy link
    Member

    methane commented Jul 26, 2020

    @fj92f3jj923f923 Would you update the PR to remove the strdup.c?

    @gvanrossum
    Copy link
    Member

    There’s probably also something in configure.in that can switch this on.

    @wasiher
    Copy link
    Mannequin Author

    wasiher mannequin commented Jul 26, 2020

    I can give a try with removing
    Please, wait
    Thanks everyone for giving a chance to make a PR :)

    @wasiher
    Copy link
    Mannequin Author

    wasiher mannequin commented Jul 27, 2020

    Created a new PR for removal of strdup (Hope it is correct)
    #21634
    Closed old one

    @methane
    Copy link
    Member

    methane commented Jul 27, 2020

    New changeset 5798f78 by wasiher in branch 'master':
    bpo-41340: Removed fallback implementation for strdup (GH-21634)
    5798f78

    @methane methane closed this as completed Jul 27, 2020
    @methane methane closed this as completed Jul 27, 2020
    @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.10 only security fixes performance Performance or resource usage topic-C-API
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants