Skip to content

bpo-35813 introduced usage of the deprecated PyErr_SetFromWindowsErrWithUnicodeFilename() function #81116

Closed

Description

@ZackerySpytz
BPO 36935
Nosy @vstinner, @serhiy-storchaka, @eryksun, @applio, @ZackerySpytz
PRs
  • bpo-36935: Remove usage of the deprecated PyErr_SetFromWindowsErrWithUnicodeFilename() #13355
  • 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 2019-06-05.12:07:33.059>
    created_at = <Date 2019-05-16.05:13:20.909>
    labels = ['extension-modules', '3.8']
    title = 'bpo-35813 introduced usage of the deprecated PyErr_SetFromWindowsErrWithUnicodeFilename() function'
    updated_at = <Date 2019-06-05.12:07:33.058>
    user = 'https://github.com/ZackerySpytz'

    bugs.python.org fields:

    activity = <Date 2019-06-05.12:07:33.058>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-06-05.12:07:33.059>
    closer = 'vstinner'
    components = ['Extension Modules']
    creation = <Date 2019-05-16.05:13:20.909>
    creator = 'ZackerySpytz'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36935
    keywords = ['patch']
    message_count = 5.0
    messages = ['342626', '342628', '343819', '343847', '343956']
    nosy_count = 5.0
    nosy_names = ['vstinner', 'serhiy.storchaka', 'eryksun', 'davin', 'ZackerySpytz']
    pr_nums = ['13355']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue36935'
    versions = ['Python 3.8']

    Activity

    1. ZackerySpytz commented on May 16, 2019

      ZackerySpytzmannequin
      MannequinAuthor

      In e895de3 / bpo-35813, the deprecated function PyErr_SetFromWindowsErrWithUnicodeFilename() was added in two functions in Modules/_winapi.c. This function was deprecated in 3.3 (and all occurrences of it were removed). Also, if bpo-33407 is accepted, usage of this function will cause compiler warnings.

      See also bpo-19569.

    2. eryksun commented on May 16, 2019

      @eryksun
      Contributor

      This was my fault for recommending PyErr_SetFromWindowsErrWithUnicodeFilename without checking the header for deprecation.

      PyErr_SetFromWindowsErrWithUnicodeFilename is an internal function (added for PEP-277, circa 2.4), which was never documented in the C API. I don't follow why Serhiy deprecated it in 2016, since at the same time he updated it to use PyUnicode_FromWideChar instead of PyUnicode_FromUnicode. I see no fundamental difference in terms of resource usage between it and PyErr_SetExcFromWindowsErrWithFilename, which instead calls PyUnicode_DecodeFSDefault.

      In this case, the section object (file mapping) name is useful information in the exception. If the deprecation isn't lifted, it puts the onus on us to implement this functionality -- i.e. PyUnicode_FromWideChar, PyErr_SetExcFromWindowsErrWithFilenameObjects, Py_XDECREF. Or maybe add a new PyErr_SetExcFromWindowsErrWithWideCharFilename function that takes a const wchar_t * string, and document it in the C API.

    3. ZackerySpytz commented on May 28, 2019

      ZackerySpytzmannequin
      MannequinAuthor

      The PR for bpo-33407 has been merged, so two warnings are now emitted in Modules/_winapi.c. I think it would be best to replace the two calls with PyErr_SetFromWindowsErr(0) (for now).

      Eryk, I think a discussion on python-dev would be necessary for something like PyErr_SetExcFromWindowsErrWithWideCharFilename().

    4. eryksun commented on May 29, 2019

      @eryksun
      Contributor

      I think it would be best to replace the two calls with
      PyErr_SetFromWindowsErr(0) (for now).

      For now it can at least be implemented inline. For example:

          if (handle == NULL) {
              PyObject *temp = name ? PyUnicode_FromWideChar(name, -1) : NULL;
              PyErr_SetExcFromWindowsErrWithFilenameObjects(PyExc_OSError,
                  0, temp, NULL);
              Py_XDECREF(temp);
              handle = INVALID_HANDLE_VALUE;
          }

      I think undeprecating the two PyErr_ functions with a modified signature in 3.8 is okay since they were never in the documented API, never in the stable (limited) API, and Py_UNICODE has been a typedef for wchar_t since 3.3.

    5. vstinner commented on May 30, 2019

      @vstinner
      Member

      New changeset eda385c by Victor Stinner (Zackery Spytz) in branch 'master':
      bpo-36935: Remove usage of the deprecated PyErr_SetFromWindowsErrWithUnicodeFilename() (GH-13355)
      eda385c

    6. 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

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions