+/**
+ * Finds a decoder instance by its python object, i.e. that instance's
+ * instantiation of the sigrokdecode.Decoder class. This will recurse
+ * to find the instance anywhere in the stack tree.
+ *
+ * @param stack Pointer to a GSList of struct srd_decoder_instance,
+ * indicating the stack to search. To start searching at the bottom
+ * level of decoder instances, pass NULL.
+ * @param obj The python class instantiation.
+ *
+ * @return Pointer to struct srd_decoder_instance, or NULL if not found.
+ */
+struct srd_decoder_instance *srd_instance_find_by_obj(GSList *stack,
+ PyObject *obj)
+{
+ GSList *l;
+ struct srd_decoder_instance *tmp, *di;
+
+ di = NULL;
+ for (l = stack ? stack : di_list; di == NULL && l != NULL; l = l->next) {
+ tmp = l->data;
+ if (tmp->py_instance == obj)
+ di = tmp;
+ else if (tmp->next_di)
+ di = srd_instance_find_by_obj(tmp->next_di, obj);
+ }
+
+ return di;
+}
+