Skip to content

PyUnicode_FromFormatV handles %R and %S incorrectly. #51857

Closed

Description

@avassalotti
BPO 7608
Nosy @avassalotti
Superseder
  • bpo-7574: PyUnicode_FromFormat broken and not documented for 2.x
  • 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 2009-12-30.23:20:18.970>
    created_at = <Date 2009-12-30.23:16:53.630>
    labels = ['interpreter-core', 'type-bug', 'library']
    title = 'PyUnicode_FromFormatV handles %R and %S incorrectly.'
    updated_at = <Date 2009-12-30.23:20:38.981>
    user = 'https://github.com/avassalotti'

    bugs.python.org fields:

    activity = <Date 2009-12-30.23:20:38.981>
    actor = 'alexandre.vassalotti'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-12-30.23:20:18.970>
    closer = 'alexandre.vassalotti'
    components = ['Interpreter Core', 'Library (Lib)']
    creation = <Date 2009-12-30.23:16:53.630>
    creator = 'alexandre.vassalotti'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 7608
    keywords = []
    message_count = 1.0
    messages = ['97067']
    nosy_count = 1.0
    nosy_names = ['alexandre.vassalotti']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '7574'
    type = 'behavior'
    url = 'https://bugs.python.org/issue7608'
    versions = ['Python 2.7']

    Activity

    1. avassalotti commented on Dec 30, 2009

      @avassalotti
      MemberAuthor

      It seems PyUnicode_FromFormatV wrongly assumes that the return value of
      PyObject_Str and PyObject_Repr is a unicode object. It looks like the
      %S and %R feature was backported from 3.x without updating the code for 2.x.

      PyObject *
      PyUnicode_FromFormatV(const char *format, va_list vargs)
      {
      ...
                  case 'S':
                  {
                      PyObject *obj = va_arg(count, PyObject *);
                      PyObject *str;
                      assert(obj);
                      str = PyObject_Str(obj);
                      if (!str)
                          goto fail;
                      n += PyUnicode_GET_SIZE(str);
                      /* Remember the str and switch to the next slot */
                      *callresult++ = str;
                      break;
                  }
                  case 'R':
                  {
                      PyObject *obj = va_arg(count, PyObject *);
                      PyObject *repr;
                      assert(obj);
                      repr = PyObject_Repr(obj);
                      if (!repr)
                          goto fail;
                      n += PyUnicode_GET_SIZE(repr);
                      /* Remember the repr and switch to the next slot */
                      *callresult++ = repr;
                      break;
                  }
      ...
      }
    2. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Dec 30, 2009
    3. 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

      interpreter-core(Objects, Python, Grammar, and Parser dirs)stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions