From nobody Mon Feb 9 20:34:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579797166; cv=none; d=zohomail.com; s=zohoarc; b=W6hJ6jUXGHsTJpSq32xbfST14+ShuBG2snYHhi+d22fmNWip6kgRByZfwDmJ23fcm3dR5WYUMZNL/sQ57HZiSjTYb76XLmuckYcAMCJ/rfSHmBvccWgT/Q7oCt7/P+nMfM82p16f1BFXrn3uPxKjCzwTIuCBPmHDI1GRaLv42xA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579797166; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cd+8u3Y9MnihrkwTGy/lli6q5rm4tiEDd8ttjlcyi+Y=; b=Er28akSDvDmGN1eAFe2BzmwGKzcSdGj86dSWmbxLZx7gYInaiPPwytXRW90Q/mZLdVjcuSwiccVW6JIz8TOzy+rdtjVwTMj9ESNW8K/M3bEo4TTdJotJSNahaFnsKCUqJumGy6z83Jyae1oBiC6SCBzkFOGH9sOIxOd9TEqsG2o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579797166486448.3299103831131; Thu, 23 Jan 2020 08:32:46 -0800 (PST) Received: from localhost ([::1]:60476 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iufPQ-00029l-77 for importer@patchew.org; Thu, 23 Jan 2020 11:32:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51873) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iucrl-0005YP-9Y for qemu-devel@nongnu.org; Thu, 23 Jan 2020 08:49:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iucrk-0004Qo-40 for qemu-devel@nongnu.org; Thu, 23 Jan 2020 08:49:49 -0500 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:35780) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iucrj-0004Pt-U6 for qemu-devel@nongnu.org; Thu, 23 Jan 2020 08:49:48 -0500 Received: by mail-wm1-x32a.google.com with SMTP id p17so2627021wmb.0 for ; Thu, 23 Jan 2020 05:49:47 -0800 (PST) Received: from 640k.localdomain.com ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id s15sm3073171wrp.4.2020.01.23.05.49.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Jan 2020 05:49:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cd+8u3Y9MnihrkwTGy/lli6q5rm4tiEDd8ttjlcyi+Y=; b=fY5gi3b+R/Q7Y5xcOLoFItIkBhJhfFs34vhQXuPdWE9iPIKzleSFiM0PCOBAiObV0L xWJaW2u6zEuI8yNJ6wx0zlg+OVEs7gaI1NMiVqWSWIvWdYELS6zgHTB9jJPt23rge7vJ M7eCOG0knkh3rFmACPVORZdCtc41DABpbK8DG4Wr0fhEJInjqG2XRpdsy2WrSxM+T+Xm V7XMbDbZJSOMzZOI64wEwMPCGYeN5trSMZynZVTySfHZ7a0ZnIqLxnTWa4Y6HhR1xwVD Ss0wdQm2g+bOeLIbXLb8w9TKUWr99L7d+rw1S6bYuFmffo316/mfBumFWAlNr4xExNue Fy2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=cd+8u3Y9MnihrkwTGy/lli6q5rm4tiEDd8ttjlcyi+Y=; b=mXP1ksujRHc+kEmiLxCweVRn3ym+R6TyrUWsIFog/HeHwIRvE0iQAJxZVWWT4sR+3j pPa11AkvL79Xz2J8RnN0bKwekh0ZwDajJyijeSCphjeCst7jjgRA74i166Fv3zYnweMB KQ20RAldFavwkR0tdyqd6c9pU6NbJ82UUQRwLMdfp9Kgyu86G0tI74FjyvQUHdAtsHCi z/kHUqCQwhHlx8rjsR6thwn0KG8FfNPxN3O5g6HdcX/4HZvQZXOjqlkkN92O8W56bo6x 2GqDtV7caCSGLblpaMe4/H5udLLWqaYwIZ8GMG7AjwlgNRYkrMp+fN90ylqncHBOnnRa okcQ== X-Gm-Message-State: APjAAAUtfvOnjcp27QW7zraRks7oyuhTn+ETvZAiyzztyCCM+5ft4+PP GMHbcXV5GJtUzpFk674Lh8ncO1Z7 X-Google-Smtp-Source: APXvYqx2PDnXFhMA/Tsr13uvWIGvpsVKECzYy3SETcNwBjVH2Rqf/nfbpj5nKAZ8pVDwpJtQwwT7wQ== X-Received: by 2002:a7b:cae9:: with SMTP id t9mr4281454wml.186.1579787386872; Thu, 23 Jan 2020 05:49:46 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 46/59] object: add object_class_property_add_link() Date: Thu, 23 Jan 2020 14:48:49 +0100 Message-Id: <1579787342-27146-47-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1579787342-27146-1-git-send-email-pbonzini@redhat.com> References: <1579787342-27146-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32a X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau Message-Id: <20200110153039.1379601-17-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini --- include/qom/object.h | 9 +++++++++ qom/object.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/include/qom/object.h b/include/qom/object.h index 5b02be6..ead9129 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1531,6 +1531,7 @@ typedef enum { =20 /* private */ OBJ_PROP_LINK_DIRECT =3D 0x2, + OBJ_PROP_LINK_CLASS =3D 0x4, } ObjectPropertyLinkFlags; =20 /** @@ -1579,6 +1580,14 @@ void object_property_add_link(Object *obj, const cha= r *name, ObjectPropertyLinkFlags flags, Error **errp); =20 +ObjectProperty *object_class_property_add_link(ObjectClass *oc, + const char *name, + const char *type, ptrdiff_t offset, + void (*check)(const Object *obj, const char = *name, + Object *val, Error **errp), + ObjectPropertyLinkFlags flags, + Error **errp); + /** * object_property_add_str: * @obj: the object to add a property to diff --git a/qom/object.c b/qom/object.c index e6617c2..202d576 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1732,6 +1732,7 @@ typedef struct { union { Object **targetp; Object *target; /* if OBJ_PROP_LINK_DIRECT, when holding the point= er */ + ptrdiff_t offset; /* if OBJ_PROP_LINK_CLASS */ }; void (*check)(const Object *, const char *, Object *, Error **); ObjectPropertyLinkFlags flags; @@ -1742,6 +1743,8 @@ object_link_get_targetp(Object *obj, LinkProperty *lp= rop) { if (lprop->flags & OBJ_PROP_LINK_DIRECT) { return &lprop->target; + } else if (lprop->flags & OBJ_PROP_LINK_CLASS) { + return (void *)obj + lprop->offset; } else { return lprop->targetp; } @@ -1857,7 +1860,9 @@ static void object_release_link_property(Object *obj,= const char *name, if ((prop->flags & OBJ_PROP_LINK_STRONG) && *targetp) { object_unref(*targetp); } - g_free(prop); + if (!(prop->flags & OBJ_PROP_LINK_CLASS)) { + g_free(prop); + } } =20 static void object_add_link_prop(Object *obj, const char *name, @@ -1910,6 +1915,45 @@ void object_property_add_link(Object *obj, const cha= r *name, object_add_link_prop(obj, name, type, targetp, check, flags, errp); } =20 +ObjectProperty * +object_class_property_add_link(ObjectClass *oc, + const char *name, + const char *type, ptrdiff_t offset, + void (*check)(const Object *obj, const char *name, + Object *val, Error **errp), + ObjectPropertyLinkFlags flags, + Error **errp) +{ + Error *local_err =3D NULL; + LinkProperty *prop =3D g_new0(LinkProperty, 1); + gchar *full_type; + ObjectProperty *op; + + prop->offset =3D offset; + prop->check =3D check; + prop->flags =3D flags | OBJ_PROP_LINK_CLASS; + + full_type =3D g_strdup_printf("link<%s>", type); + + op =3D object_class_property_add(oc, name, full_type, + object_get_link_property, + check ? object_set_link_property : NULL, + object_release_link_property, + prop, + &local_err); + if (local_err) { + error_propagate(errp, local_err); + g_free(prop); + goto out; + } + + op->resolve =3D object_resolve_link_property; + +out: + g_free(full_type); + return op; +} + void object_property_add_const_link(Object *obj, const char *name, Object *target, Error **errp) { --=20 1.8.3.1