Author Jeffrey.Kintscher
Recipients Jeffrey.Kintscher, bup, ezio.melotti, mrabarnett, serhiy.storchaka, terry.reedy
Date 2019-07-04.08:07:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1562227670.83.0.0849872417261.issue37367@roundup.psfhosted.org>
In-reply-to
Content
>>> 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.
History
Date User Action Args
2019-07-04 08:07:50Jeffrey.Kintschersetrecipients: + Jeffrey.Kintscher, terry.reedy, ezio.melotti, mrabarnett, serhiy.storchaka, bup
2019-07-04 08:07:50Jeffrey.Kintschersetmessageid: <1562227670.83.0.0849872417261.issue37367@roundup.psfhosted.org>
2019-07-04 08:07:50Jeffrey.Kintscherlinkissue37367 messages
2019-07-04 08:07:50Jeffrey.Kintschercreate