summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert Vermeulen <bert@biot.com>2013-10-17 16:27:54 +0200
committerBert Vermeulen <bert@biot.com>2013-10-17 16:28:18 +0200
commit119d62586036f4436de8e11824e388c3f0a882c4 (patch)
tree1a44072ec07172b79e7533838b3661ed254923b3
parent308d9958c9b4ca8f7126d7e8c81be3b93749a2b1 (diff)
downloadlibsigrokdecode-119d62586036f4436de8e11824e388c3f0a882c4.tar.gz
libsigrokdecode-119d62586036f4436de8e11824e388c3f0a882c4.zip
Avoid clobbering class variables when setting instance options
-rw-r--r--controller.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/controller.c b/controller.c
index c196dad..d8325ac 100644
--- a/controller.c
+++ b/controller.c
@@ -326,8 +326,18 @@ SRD_API int srd_inst_option_set(struct srd_decoder_inst *di,
/* All of these are synthesized objects, so they're good. */
py_dec_optkeys = PyDict_Keys(py_dec_options);
num_optkeys = PyList_Size(py_dec_optkeys);
+
+ /*
+ * The 'options' dictionary is a class variable, but we need to
+ * change it. Changing it directly will affect the entire class,
+ * so we need to create a new object for it, and populate that
+ * instead.
+ */
if (!(py_di_options = PyObject_GetAttrString(di->py_inst, "options")))
goto err_out;
+ Py_DECREF(py_di_options);
+ py_di_options = PyDict_New();
+ PyObject_SetAttrString(di->py_inst, "options", py_di_options);
for (i = 0; i < num_optkeys; i++) {
/* Get the default class value for this option. */
py_str_as_str(PyList_GetItem(py_dec_optkeys, i), &key);