Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-880

"ValueError: underlying buffer has been detached" when building in non-UTF8 locale

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P4: Low
    • 5.12.1
    • 5.12.0
    • PySide, Shiboken
    • None
    • Linux/X11
    • 77de5fb2d02551eb7563ba1a42c74ad6581815fb (pyside/pyside-setup/5.12)

    Description

      After the changes in https://codereview.qt-project.org/gitweb?p=pyside/pyside-setup.git;a=commitdiff;h=43fe3494a9d902034896e3afa7b5158c77163be0;hp=c6c9f057cddc0e0b885a648489264538eba0a158

      run_process() from build_scripts/utils.py may fail in the nested invocation, e.g. for
      /usr/bin/python3 setup.py build --reuse-build --ignore-git --internal-build-type=shiboken2

      Prerequisites:
      LC_CTYPE (or LC_ALL) is POSIX aka C, or any other non-UTF8 locale

      -> setuptools/dist.py calls detach() on sys.stdout in handle_display_options
      
              if sys.stdout.encoding.lower() in ('utf-8', 'utf8'):
                  return _Distribution.handle_display_options(self, option_order)
      ...
              sys.stdout = io.TextIOWrapper(
                  sys.stdout.detach(), 'utf-8', errors, newline, line_buffering)
      

      Afterwards, sys.stdout is valid, but sys._stdout_ no longer is.

      subprocess tries to reassign STDERR to STDOUT (see _get_handles()), as run_process called from build_extension() uses kwargs['stderr'] = subprocess.STDOUT, but fails:

      elif stderr == STDOUT:
                      if c2pwrite != -1:
                          errwrite = c2pwrite
                      else: # child's stdout is not set, use parent's stdout
                          errwrite = sys.__stdout__.fileno()
      

      c2pwrite is -1, sys._stdout_ is detached, see https://docs.python.org/3/library/io.html#io.BufferedIOBase

      One possible workaround is to use set LC_ALL=C.utf8.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kleint Friedemann Kleint
            bruns Stefan BrĂ¼ns
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes