static PyObject * stpy_get_type (PyObject *self, void *closure) { lazy_string_object *str_obj = (lazy_string_object *) self; return type_to_type_object (str_obj->type); }
/* Return the type, stripped of typedefs. */ static PyObject * typy_strip_typedefs (PyObject *self, PyObject *args) { struct type *type = ((type_object *) self)->type; return type_to_type_object (check_typedef (type)); }
static PyObject * sympy_get_type (PyObject *self, void *closure) { struct symbol *symbol = NULL; SYMPY_REQUIRE_VALID (self, symbol); if (SYMBOL_TYPE (symbol) == NULL) { Py_INCREF (Py_None); return Py_None; } return type_to_type_object (SYMBOL_TYPE (symbol)); }
/* Helper function for typy_fields which converts a single field to a dictionary. Returns NULL on error. */ static PyObject * convert_field (struct type *type, int field) { PyObject *result = field_new (); PyObject *arg; if (!result) return NULL; if (!field_is_static (&TYPE_FIELD (type, field))) { arg = PyLong_FromLong (TYPE_FIELD_BITPOS (type, field)); if (!arg) goto fail; if (PyObject_SetAttrString (result, "bitpos", arg) < 0) goto failarg; } if (TYPE_FIELD_NAME (type, field)) arg = PyString_FromString (TYPE_FIELD_NAME (type, field)); else { arg = Py_None; Py_INCREF (arg); } if (!arg) goto fail; if (PyObject_SetAttrString (result, "name", arg) < 0) goto failarg; arg = TYPE_FIELD_ARTIFICIAL (type, field) ? Py_True : Py_False; Py_INCREF (arg); if (PyObject_SetAttrString (result, "artificial", arg) < 0) goto failarg; if (TYPE_CODE (type) == TYPE_CODE_CLASS) arg = field < TYPE_N_BASECLASSES (type) ? Py_True : Py_False; else arg = Py_False; Py_INCREF (arg); if (PyObject_SetAttrString (result, "is_base_class", arg) < 0) goto failarg; arg = PyLong_FromLong (TYPE_FIELD_BITSIZE (type, field)); if (!arg) goto fail; if (PyObject_SetAttrString (result, "bitsize", arg) < 0) goto failarg; /* A field can have a NULL type in some situations. */ if (TYPE_FIELD_TYPE (type, field) == NULL) { arg = Py_None; Py_INCREF (arg); } else arg = type_to_type_object (TYPE_FIELD_TYPE (type, field)); if (!arg) goto fail; if (PyObject_SetAttrString (result, "type", arg) < 0) goto failarg; return result; failarg: Py_DECREF (arg); fail: Py_DECREF (result); return NULL; }
static PyObject * convert_field (struct type *type, int field) { gdbpy_ref<> result (field_new ()); if (result == NULL) return NULL; gdbpy_ref<> arg (type_to_type_object (type)); if (arg == NULL) return NULL; if (PyObject_SetAttrString (result.get (), "parent_type", arg.get ()) < 0) return NULL; if (!field_is_static (&TYPE_FIELD (type, field))) { const char *attrstring; if (TYPE_CODE (type) == TYPE_CODE_ENUM) { arg.reset (gdb_py_long_from_longest (TYPE_FIELD_ENUMVAL (type, field))); attrstring = "enumval"; } else { arg.reset (gdb_py_long_from_longest (TYPE_FIELD_BITPOS (type, field))); attrstring = "bitpos"; } if (arg == NULL) return NULL; /* At least python-2.4 had the second parameter non-const. */ if (PyObject_SetAttrString (result.get (), (char *) attrstring, arg.get ()) < 0) return NULL; } arg.reset (NULL); if (TYPE_FIELD_NAME (type, field)) { const char *field_name = TYPE_FIELD_NAME (type, field); if (field_name[0] != '\0') { arg.reset (PyString_FromString (TYPE_FIELD_NAME (type, field))); if (arg == NULL) return NULL; } } if (arg == NULL) { arg.reset (Py_None); Py_INCREF (arg.get ()); } if (PyObject_SetAttrString (result.get (), "name", arg.get ()) < 0) return NULL; arg.reset (TYPE_FIELD_ARTIFICIAL (type, field) ? Py_True : Py_False); Py_INCREF (arg.get ()); if (PyObject_SetAttrString (result.get (), "artificial", arg.get ()) < 0) return NULL; if (TYPE_CODE (type) == TYPE_CODE_STRUCT) arg.reset (field < TYPE_N_BASECLASSES (type) ? Py_True : Py_False); else arg.reset (Py_False); Py_INCREF (arg.get ()); if (PyObject_SetAttrString (result.get (), "is_base_class", arg.get ()) < 0) return NULL; arg.reset (PyLong_FromLong (TYPE_FIELD_BITSIZE (type, field))); if (arg == NULL) return NULL; if (PyObject_SetAttrString (result.get (), "bitsize", arg.get ()) < 0) return NULL; /* A field can have a NULL type in some situations. */ if (TYPE_FIELD_TYPE (type, field) == NULL) { arg.reset (Py_None); Py_INCREF (arg.get ()); } else arg.reset (type_to_type_object (TYPE_FIELD_TYPE (type, field))); if (arg == NULL) return NULL; if (PyObject_SetAttrString (result.get (), "type", arg.get ()) < 0) return NULL; return result.release (); }
PyObject *result = NULL, *iter = NULL; struct type *type = ((type_object *) py_type)->type; struct type *checked_type = type; TRY { checked_type = check_typedef (checked_type); } CATCH (except, RETURN_MASK_ALL) { GDB_PY_HANDLE_EXCEPTION (except); } END_CATCH if (checked_type != type) py_type = type_to_type_object (checked_type); iter = typy_make_iter (py_type, kind); if (checked_type != type) { /* Need to wrap this in braces because Py_DECREF isn't wrapped in a do{}while(0). */ Py_DECREF (py_type); } if (iter != NULL) { result = PySequence_List (iter); Py_DECREF (iter); } return result; }