def __init__(self):
Chris Angelico
rosuav at gmail.com
Tue Apr 26 13:30:02 EDT 2016
On Wed, Apr 27, 2016 at 3:13 AM, Chris Kaynor <ckaynor at zindagigames.com> wrote:
> Yah, if you really wanted to make it work properly, you'd need to incref
> the newValue, while decref the oldValue. The incref would not be that
> difficult, but the decref would be more challenging, as you may have to
> also destroy the old object, though that might be possible by casting it
> back to a python object without the incref,. One way or the other, I did
> not exactly spend a ton of time to make it work properly :)
Exactly. :) Actually, the easiest fix is probably this:
import ctypes
def low_change_tuple(tuple, index, newValue):
obj = ctypes.cast(id(tuple), ctypes.POINTER(ctypes.c_long))
obj[3+index] = id(newValue)
def change_tuple(tup, idx, val):
dummy = (val,)
low_change_tuple(dummy, 0, tup[idx])
low_change_tuple(tup, idx, val)
Refcounts are handled by the switch.
ChrisA
More information about the Python-list
mailing list