Python 2.2 chr representation errors with embedded C

Tim Peters tim.one at comcast.net
Fri Mar 29 14:50:13 EST 2002


[Mark Szigety; chopped python-dev from the address list]
> I have recently made the upgrade to Python 2.2 from 1.5.2.  In the
> Python application which I develop, we have several embedded C
> functions, one of which is a simple function to convert a hex string to
> octal--it simply chars each byte and returns the new buffer.

Post the function -- I can't guess what that means.

> However, I have noticed a 0.01% error rate in Python 2.2 which I
> did not see in Python 1.5.2 (it was 100% accurate).  That is, 1 out
> of 10,000 hex strings will be converted incorrectly in the C function,
> usually one byte is returned as \x00 instead of what is should be.

Post the function <wink>.

> I also have noticed that in Python 2.2, chr(0xff) returns \xff instead
> of \377 in Python 1.5.2.

The return value of chr(0xff) has never changed.  I expect you're mistaking
the change in what repr(a_string) produces for a change in what chr()
returns.  repr(a_string) has changed to use hex escapes instead of octal
escapes; chr() has not changed.  Note that

>>> '\377' == '\xff'
1
>>>

in all versions of Python.

> Could this be the source of the communication breakdown?

No.

> I should mention that writing a similar conversion function totally in
> Python is 100% accurate in Python 2.2 as well as Python 1.5.2, although
> it is an order of magnitude slower.

Post your C function; it's quite likely got a subtle bug, or other C code is
corrupting the memory it writes into.





More information about the Python-list mailing list