On Wed, Apr 27, 2016 at 3:13 AM, Chris Kaynor <ckay...@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 -- https://mail.python.org/mailman/listinfo/python-list