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

Rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString(): don't cache the result #66519

Closed
vstinner opened this issue Sep 1, 2014 · 5 comments
Labels
type-feature A feature request or enhancement

Comments

@vstinner
Copy link
Member

vstinner commented Sep 1, 2014

BPO 22323
Nosy @loewis, @pitrou, @vstinner, @serhiy-storchaka
Files
  • unicode_aswidechar.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 = None
    closed_at = <Date 2015-10-02.21:06:09.492>
    created_at = <Date 2014-09-01.21:32:14.109>
    labels = ['type-feature']
    title = "Rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString(): don't cache the result"
    updated_at = <Date 2018-07-23.20:12:05.868>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2018-07-23.20:12:05.868>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2015-10-02.21:06:09.492>
    closer = 'vstinner'
    components = []
    creation = <Date 2014-09-01.21:32:14.109>
    creator = 'vstinner'
    dependencies = []
    files = ['36527']
    hgrepos = []
    issue_num = 22323
    keywords = ['patch']
    message_count = 5.0
    messages = ['226244', '226260', '226264', '226515', '322253']
    nosy_count = 4.0
    nosy_names = ['loewis', 'pitrou', 'vstinner', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue22323'
    versions = ['Python 3.5']

    @vstinner
    Copy link
    Member Author

    vstinner commented Sep 1, 2014

    I would like to deprecate PyUnicode_AsUnicode(), see the issue bpo-22271 for the rationale (hint: memory footprint). The first step is to rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString() to not call PyUnicode_AsUnicode() anymore.

    Attached patch implements this.

    The code is based on PyUnicode_AsUnicode(), but it's more tricky because PyUnicode_AsWideChar() can truncate the string, and PyUnicode_AsUnicode() does no copy characters if kind == sizeof(wchar_t), PyASCIIObject.wstr "just" points to data.

    I hate PyUnicode_AsWideChar(), but we must keep it for backward compatibility :-)

    It would be possible to write an optimized PyUnicode_AsWideCharString() which computes the length, allocate memory and write wide characters, but I don't want to have 3 functions converting a Python string to a wide character string. There are already PyUnicode_AsUnicodeAndSize() and unicode_aswidechar() (+ unicode_aswidechar_len()).

    @vstinner vstinner added the type-feature A feature request or enhancement label Sep 1, 2014
    @pitrou
    Copy link
    Member

    pitrou commented Sep 2, 2014

    Attached patch implements this.

    There is no patch.

    @vstinner
    Copy link
    Member Author

    vstinner commented Sep 2, 2014

    There is no patch.

    You're right. Here it is.

    @pitrou
    Copy link
    Member

    pitrou commented Sep 6, 2014

    Hmm... sorry for the delay, there's no review link. Perhaps the patch is not against the latest default?

    @vstinner vstinner changed the title Rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString() Rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString(): don't cache the result Oct 9, 2014
    @vstinner vstinner closed this as completed Oct 2, 2015
    @serhiy-storchaka
    Copy link
    Member

    Oh, I have reimplemented this in bpo-30863.

    @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
    type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants