+ return list.release ();
+}
+
+/* Compute the list of active python type printers and store them in
+ EXT_PRINTERS->py_type_printers. The product of this function is used by
+ gdbpy_apply_type_printers, and freed by gdbpy_free_type_printers.
+ This is the extension_language_ops.start_type_printers "method". */
+
+static void
+gdbpy_start_type_printers (const struct extension_language_defn *extlang,
+ struct ext_lang_type_printers *ext_printers)
+{
+ PyObject *printers_obj = NULL;
+
+ if (!gdb_python_initialized)
+ return;
+
+ gdbpy_enter enter_py (get_current_arch (), current_language);
+
+ gdbpy_ref<> type_module (PyImport_ImportModule ("gdb.types"));
+ if (type_module == NULL)
+ {
+ gdbpy_print_stack ();
+ return;
+ }
+
+ gdbpy_ref<> func (PyObject_GetAttrString (type_module.get (),
+ "get_type_recognizers"));
+ if (func == NULL)
+ {
+ gdbpy_print_stack ();
+ return;
+ }
+
+ printers_obj = PyObject_CallFunctionObjArgs (func.get (), (char *) NULL);
+ if (printers_obj == NULL)
+ gdbpy_print_stack ();
+ else
+ ext_printers->py_type_printers = printers_obj;
+}
+
+/* If TYPE is recognized by some type printer, store in *PRETTIED_TYPE
+ a newly allocated string holding the type's replacement name, and return
+ EXT_LANG_RC_OK. The caller is responsible for freeing the string.
+ If there's a Python error return EXT_LANG_RC_ERROR.
+ Otherwise, return EXT_LANG_RC_NOP.
+ This is the extension_language_ops.apply_type_printers "method". */
+
+static enum ext_lang_rc
+gdbpy_apply_type_printers (const struct extension_language_defn *extlang,
+ const struct ext_lang_type_printers *ext_printers,
+ struct type *type, char **prettied_type)
+{
+ PyObject *printers_obj = (PyObject *) ext_printers->py_type_printers;
+ gdb::unique_xmalloc_ptr<char> result;
+
+ if (printers_obj == NULL)
+ return EXT_LANG_RC_NOP;
+
+ if (!gdb_python_initialized)
+ return EXT_LANG_RC_NOP;
+
+ gdbpy_enter enter_py (get_current_arch (), current_language);
+
+ gdbpy_ref<> type_obj (type_to_type_object (type));
+ if (type_obj == NULL)
+ {
+ gdbpy_print_stack ();
+ return EXT_LANG_RC_ERROR;
+ }
+
+ gdbpy_ref<> type_module (PyImport_ImportModule ("gdb.types"));
+ if (type_module == NULL)
+ {
+ gdbpy_print_stack ();
+ return EXT_LANG_RC_ERROR;
+ }
+
+ gdbpy_ref<> func (PyObject_GetAttrString (type_module.get (),
+ "apply_type_recognizers"));
+ if (func == NULL)
+ {
+ gdbpy_print_stack ();
+ return EXT_LANG_RC_ERROR;
+ }
+
+ gdbpy_ref<> result_obj (PyObject_CallFunctionObjArgs (func.get (),
+ printers_obj,
+ type_obj.get (),
+ (char *) NULL));
+ if (result_obj == NULL)
+ {
+ gdbpy_print_stack ();
+ return EXT_LANG_RC_ERROR;
+ }
+
+ if (result_obj == Py_None)
+ return EXT_LANG_RC_NOP;
+
+ result = python_string_to_host_string (result_obj.get ());
+ if (result == NULL)
+ {
+ gdbpy_print_stack ();
+ return EXT_LANG_RC_ERROR;
+ }
+
+ *prettied_type = result.release ();
+ return EXT_LANG_RC_OK;
+}
+
+/* Free the result of start_type_printers.
+ This is the extension_language_ops.free_type_printers "method". */
+
+static void
+gdbpy_free_type_printers (const struct extension_language_defn *extlang,
+ struct ext_lang_type_printers *ext_printers)
+{
+ PyObject *printers = (PyObject *) ext_printers->py_type_printers;
+
+ if (printers == NULL)
+ return;
+
+ if (!gdb_python_initialized)
+ return;
+
+ gdbpy_enter enter_py (get_current_arch (), current_language);
+ Py_DECREF (printers);