[issue37367] octal escapes applied inconsistently throughout the interpreter and lib

Jeffrey Kintscher report at bugs.python.org
Thu Jul 4 04:07:50 EDT 2019


Jeffrey Kintscher <websurfer at surf2c.net> added the comment:

>>> b'\407'
b'\x07'
>>> ord(b'\407')
7

This is the object structure passed to builtin_ord():

(lldb) p *((PyBytesObject *)(c))
(PyBytesObject) $19 = {
  ob_base = {
    ob_base = {
      ob_refcnt = 4
      ob_type = 0x00000001003cb0b0
    }
    ob_size = 1
  }
  ob_shash = 8685212186264880044
  ob_sval = {
    [0] = '\a'
  }
}

If two bytes were stored (0x107), I would expect ob_sval[0] to be 7 ('\a') and ob_sval[1] to be 1 on a little endian system, but ob_sval[1] is 0:

(lldb) p (long)(unsigned char) (((PyBytesObject *)(c))->ob_sval[0])
(long) $23 = 7
(lldb) p (long)(unsigned char) (((PyBytesObject *)(c))->ob_sval[1])
(long) $24 = 0

This means the truncation to a single byte is happening when the byte string object is created.

----------
nosy: +Jeffrey.Kintscher

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37367>
_______________________________________


More information about the Python-bugs-list mailing list