Skip to content

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

Closed

Description

@vstinner
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']

    Activity

    1. vstinner commented on Sep 1, 2014

      @vstinner
      MemberAuthor

      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()).

    2. pitrou commented on Sep 2, 2014

      @pitrou
      Member

      Attached patch implements this.

      There is no patch.

    3. vstinner commented on Sep 2, 2014

      @vstinner
      MemberAuthor

      There is no patch.

      You're right. Here it is.

    4. pitrou commented on Sep 6, 2014

      @pitrou
      Member

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

    5. changed the title [-]Rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString()[/-] [+]Rewrite PyUnicode_AsWideChar() and PyUnicode_AsWideCharString(): don't cache the result[/+] on Oct 9, 2014
    6. serhiy-storchaka commented on Jul 23, 2018

      @serhiy-storchaka
      Member

      Oh, I have reimplemented this in bpo-30863.

    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      type-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions