Browse Source

Don?t modify tuples that others may already have references to.

Fixes egg room private chat channels and entering Teledahn buckets with Python 2.7. These and other uses of ptSDL.setIndex() only worked by chance with Python 2.3 because the tuples happened to have reference counts of 1.
sdlsetindex-ou
Christian Walther 13 years ago
parent
commit
38747f3f1b
  1. 16
      MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/plPythonSDLModifier.cpp

16
MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/plPythonSDLModifier.cpp

@ -208,6 +208,22 @@ void plPythonSDLModifier::SetItemIdx(const char* key, int idx, PyObject* value,
return; return;
} }
if (pyTuple && pyTuple->ob_refcnt != 1)
{
// others already have references to the tuple and expect it to be immutable, must make a copy
int n = PyTuple_Size(pyTuple);
PyObject* newTuple = PyTuple_New(n);
for (int j = 0; j < n; j++)
{
PyObject* item = PyTuple_GetItem(pyTuple, j);
Py_INCREF(item);
PyTuple_SetItem(newTuple, j, item);
}
Py_DECREF(pyTuple);
pyTuple = newTuple;
it->second.obj = newTuple;
}
if (pyTuple) if (pyTuple)
{ {
if (PyTuple_Size(pyTuple) <= idx) if (PyTuple_Size(pyTuple) <= idx)

Loading…
Cancel
Save