#include "qom/object.h"
#include "qom/object_interfaces.h"
#include "qemu/cutils.h"
+#include "qemu/memalign.h"
#include "qapi/visitor.h"
#include "qapi/string-input-visitor.h"
#include "qapi/string-output-visitor.h"
Object *object_ref(void *objptr)
{
Object *obj = OBJECT(objptr);
+ uint32_t ref;
+
if (!obj) {
return NULL;
}
- qatomic_inc(&obj->ref);
+ ref = qatomic_fetch_inc(&obj->ref);
+ /* Assert waaay before the integer overflows */
+ g_assert(ref < INT_MAX);
return obj;
}
bool object_property_set(Object *obj, const char *name, Visitor *v,
Error **errp)
{
- Error *err = NULL;
+ ERRP_GUARD();
ObjectProperty *prop = object_property_find_err(obj, name, errp);
if (prop == NULL) {
error_setg(errp, QERR_PERMISSION_DENIED);
return false;
}
- prop->set(obj, v, name, prop->opaque, &err);
- error_propagate(errp, err);
- return !err;
+ prop->set(obj, v, name, prop->opaque, errp);
+ return !*errp;
}
bool object_property_set_str(Object *obj, const char *name,
return object_resolve_path_type(path, TYPE_OBJECT, ambiguous);
}
+Object *object_resolve_path_at(Object *parent, const char *path)
+{
+ g_auto(GStrv) parts = g_strsplit(path, "/", 0);
+
+ if (*path == '/') {
+ return object_resolve_abs_path(object_get_root(), parts + 1,
+ TYPE_OBJECT);
+ }
+ return object_resolve_abs_path(parent, parts, TYPE_OBJECT);
+}
+
typedef struct StringProperty
{
char *(*get)(Object *, Error **);
static void register_types(void)
{
- static TypeInfo interface_info = {
+ static const TypeInfo interface_info = {
.name = TYPE_INTERFACE,
.class_size = sizeof(InterfaceClass),
.abstract = true,
};
- static TypeInfo object_info = {
+ static const TypeInfo object_info = {
.name = TYPE_OBJECT,
.instance_size = sizeof(Object),
.class_init = object_class_init,