+static int
+update_dynamic_varobj_children (struct varobj *var,
+ VEC (varobj_p) **changed,
+ VEC (varobj_p) **new_and_unchanged,
+ int *cchanged)
+
+{
+#if HAVE_PYTHON
+ /* FIXME: we *might* want to provide this functionality as
+ a standalone function, so that other interested parties
+ than varobj code can benefit for this. */
+ struct cleanup *back_to;
+ PyObject *children;
+ PyObject *iterator;
+ int i;
+ int children_changed = 0;
+ PyObject *printer = var->pretty_printer;
+ PyGILState_STATE state;
+
+ state = PyGILState_Ensure ();
+ back_to = make_cleanup_py_restore_gil (&state);
+
+ *cchanged = 0;
+ if (!PyObject_HasAttr (printer, gdbpy_children_cst))
+ {
+ do_cleanups (back_to);
+ return 0;
+ }
+
+ children = PyObject_CallMethodObjArgs (printer, gdbpy_children_cst,
+ NULL);
+
+ if (!children)
+ {
+ gdbpy_print_stack ();
+ error ("Null value returned for children");
+ }
+
+ make_cleanup_py_decref (children);
+
+ if (!PyIter_Check (children))
+ error ("Returned value is not iterable");
+
+ iterator = PyObject_GetIter (children);
+ if (!iterator)
+ {
+ gdbpy_print_stack ();
+ error ("Could not get children iterator");
+ }
+ make_cleanup_py_decref (iterator);
+
+ for (i = 0; ; ++i)
+ {
+ PyObject *item = PyIter_Next (iterator);
+ PyObject *py_v;
+ struct value *v;
+ char *name;
+ struct cleanup *inner;
+
+ if (!item)
+ break;
+ inner = make_cleanup_py_decref (item);
+
+ if (!PyArg_ParseTuple (item, "sO", &name, &py_v))
+ error ("Invalid item from the child list");
+
+ if (PyObject_TypeCheck (py_v, &value_object_type))
+ {
+ /* If we just call convert_value_from_python for this type,
+ we won't know who owns the result. For this one case we
+ need to copy the resulting value. */
+ v = value_object_to_value (py_v);
+ v = value_copy (v);
+ }
+ else
+ v = convert_value_from_python (py_v);
+
+ /* TODO: This assume the name of the i-th child never changes. */
+
+ /* Now see what to do here. */
+ if (VEC_length (varobj_p, var->children) < i + 1)
+ {
+ /* There's no child yet. */
+ struct varobj *child = varobj_add_child (var, name, v);
+ if (new_and_unchanged)
+ VEC_safe_push (varobj_p, *new_and_unchanged, child);
+ children_changed = 1;
+ }
+ else
+ {
+ varobj_p existing = VEC_index (varobj_p, var->children, i);
+ if (install_new_value (existing, v, 0) && changed)
+ {
+ if (changed)
+ VEC_safe_push (varobj_p, *changed, existing);
+ }
+ else
+ {
+ if (new_and_unchanged)
+ VEC_safe_push (varobj_p, *new_and_unchanged, existing);
+ }
+ }
+
+ do_cleanups (inner);
+ }
+
+ if (i < VEC_length (varobj_p, var->children))
+ {
+ int i;
+ children_changed = 1;
+ for (i = 0; i < VEC_length (varobj_p, var->children); ++i)
+ varobj_delete (VEC_index (varobj_p, var->children, i), NULL, 0);
+ }
+ VEC_truncate (varobj_p, var->children, i);
+ var->num_children = VEC_length (varobj_p, var->children);
+
+ do_cleanups (back_to);
+
+ *cchanged = children_changed;
+ return 1;
+#else
+ gdb_assert (0 && "should never be called if Python is not enabled");
+#endif
+}