return 0;
}
+/*
+ * Get the full hierarchical object name for an export, used for diagnostics.
+ * Currently, this does not include the package name (which is actually
+ * required for this to be a "full" name) as it's not yet passed to the
+ * deserialize method.
+ *
+ * Returns a buffer allocated by malloc on success, or NULL on failure.
+ */
+static char *get_obj_fullname(const struct upkg_export *e)
+{
+ size_t total_len = 0, len;
+ char *fullname;
+
+ for (const struct upkg_export *c = e; c; c = c->parent) {
+ len = strlen(c->name) + 1;
+ if (total_len > SIZE_MAX - len)
+ return NULL;
+ total_len += len;
+ }
+
+ fullname = malloc(total_len);
+ if (!fullname)
+ return NULL;
+
+ for (const struct upkg_export *c = e; c; c = c->parent) {
+ len = strlen(c->name);
+ assert(total_len > len);
+
+ total_len -= len + 1;
+ memcpy(fullname + total_len, c->name, len);
+ fullname[total_len + len] = c == e ? '\0' : '.';
+ }
+
+ return fullname;
+}
+
int u_object_deserialize(GObject *obj, struct upkg *pkg, unsigned long idx)
{
g_return_val_if_fail(IS_U_OBJECT(obj), -1);
UObject *uo = U_OBJECT(obj);
+ const struct upkg_export *e;
struct upkg_file *f;
int rc;
uo->pkg = pkg;
uo->pkg_file = f;
+ e = upkg_get_export(pkg, idx);
+ if (!e)
+ return -1;
+ uo->pkg_name = get_obj_fullname(e);
+ if (!uo->pkg_name)
+ return -1;
+
rc = U_OBJECT_GET_CLASS(obj)->deserialize(uo);
if (rc != 0) {
upkg_export_close(f);
upkg_export_close(uo->pkg_file);
}
+ free(uo->pkg_name);
+
G_OBJECT_CLASS(u_object_parent_class)->finalize(o);
}
UObject *uo = U_OBJECT(o);
char *new_fmt = NULL;
- if (uo->pkg_file) {
- /* XXX: Currently, there's no way to get the full object name
- * here because the object path information is discarded
- * after opening it. In principle, there's no reason why
- * we couldn't keep it around to improve log messages. */
- new_fmt = prepend_fmt(uo->pkg_file->name, fmt);
+ if (uo->pkg_name) {
+ new_fmt = prepend_fmt(uo->pkg_name, fmt);
if (!new_fmt) {
g_log(G_OBJECT_TYPE_NAME(o), level, "%s",
uo->pkg_file->name);