Python String Immutability Broken!

Hendrik van Rooyen mail at microcorp.co.za
Mon Aug 25 16:31:22 EDT 2008


 
Patrick Maupin <pmau....ail.com> wrote:

>Very entertaining.
>

Thanks. Nice to see that there is still some sense of humour
left somewhere - its all been so serious here lately - people
seem to forget that hacking is fun!

>But let me get this straight:   Are you just complaining that if you
>pass a string to an arbitrary C function using ctypes, that that
>arbitrary function can modify the string?
>

Actually, I am not complaining - I am asking for advice on the side
effects of what I am doing, which is replacing a bunch of bits
in what is essentially an output bit field with the corresponding
input bits at the same addresses read back from a simulated i/o
bus structure.  And I would also like to know if there is a better
way of doing this.

The C code actually works, doing what was intended - the \xff that
one sees appearing back comes from the pullup resistors on the
eBox's i/o.  I can show that it is working by adding some resistance
and capacitance (by holding the connector against my tongue) in which
case I get a munged version of the fox back.  (- evidently my tongue
is not such a perfect communications medium as I would like to believe.)

Passing the fox is actually deceptive and misleading, as in real
use there would be no such correlation sideways across bits, as
they are just representations of output lines.
(Think "coils" in PLC jargon)

>Because if you are, then I think you share a great deal of
>responsibility for the death of that string -- sending the poor thing
>to its grave through some unknown C function.

This string is NOT dead - it is alive, and not even stunned -
it just looks as if it is sleeping because of the \xff - which
comes from the fact that there is no real hardware out there yet.

The C functions are very simple ones actually - they just do
what are essentially Linux I/O system calls - setting direction
bits for a port (in or out) and then reading or writing the data.

- Hendrik






More information about the Python-list mailing list