From nobody Mon Feb 9 15:11:55 2026 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1573847170; cv=none; d=zoho.com; s=zohoarc; b=O/t4QdroxdSIkz9lcIqRB0XdFEmUkF86+8JjbqH3xbdKYuJKSFnB5oxAhCMFNKPD33BxHT3PcYSUEA/5RDNMJacvE2Jori7P7hz3QYG8rWSfzSiSRwg+TKxp3alt1N6u576kv5p79E5RxyZSpaBDMOVlOLc5OiEfNHSyfGwZWq8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573847170; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Oi/sb4fLu75ov0fMyb3cCBFERMeS3Ui0J3/yiJ1XdOk=; b=OYICW2b7nVMnugkQrjtRTzkxEkD7Egj6wgwJXFqno7fZb8xRLVDNWXIkNg0ydt42xzbna3IGoFrj7XSORAcjLAXFowmH3COTZ5dZ8hVAv6KhFyeWkhm8lgCdmublH165kZHPXUkJE7Z1Zuce6cEmxicSJK6rLcc8cvPFs9i0ENA= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1573847170241742.2772615282428; Fri, 15 Nov 2019 11:46:10 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iVhWp-0001I0-5u; Fri, 15 Nov 2019 19:45:11 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iVhWn-0001Hb-FQ for xen-devel@lists.xenproject.org; Fri, 15 Nov 2019 19:45:09 +0000 Received: from mail-qv1-xf43.google.com (unknown [2607:f8b0:4864:20::f43]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 69ee5754-07e0-11ea-984a-bc764e2007e4; Fri, 15 Nov 2019 19:45:02 +0000 (UTC) Received: by mail-qv1-xf43.google.com with SMTP id n4so1108033qvq.9 for ; Fri, 15 Nov 2019 11:45:02 -0800 (PST) Received: from five.crux.rad.ainfosec.com (209-217-208-226.northland.net. [209.217.208.226]) by smtp.googlemail.com with ESMTPSA id y10sm4649679qkb.55.2019.11.15.11.44.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 11:44:59 -0800 (PST) X-Inumbo-ID: 69ee5754-07e0-11ea-984a-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Z2NYMlNEa239ID0p7i58khGBjYrcb8RrDrNqVGHrC6k=; b=cHdSGO5Pa9hdZtK9gT4kafagfrh6aiA0qIAmH9YQTSpUp9ficR2/GL30rydigxnGc1 NIdBOM41LqTqmaayhgaGb4skovSBXW7PqX4WLpCK38yOlkRlMkoHPbQBf881A5hVPPpc nDFcCLnMFIdlLja4RD1ZBYP1fOS4fVKh0JHSXn1DV7xHP+yuT0AAVez913x6io/nj7z5 DY+LSRU0KnAaDM9qaDKoJ4PrlBYrBO6/zgPW+eggGPYKkVNdlFRSj9DGqNm4rUed9eHF EZIxeq+6I5uVJEb8K/bPetyruwzuaTjRPpWXjH+lWZBd2gJodr0HzKZdJl4nY962zrpo BXEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z2NYMlNEa239ID0p7i58khGBjYrcb8RrDrNqVGHrC6k=; b=WyjCso08xUn4dDs2JFlwvclIreVJIk4BPLJ9kRL03LffbJn8ih6pEbFUbluwp8FXnS xxMpu5N2QgKljB37UqrMtrJhgulfRtDRmVBA+0PCrL+ZqcfTsxLVLjgFJ6kSCENLfqbX jIJahMDJlsy02m1Oo/lHHALc2UfrW+HX3Aya5sF7qoyc1gpVbX1At/NRIQvKxIfDN/C0 6iLATFbsTjPI+dTjRHa1hVncYGpQGJY14OXNrnCtsT61+1F9xja7fcgRK0BpJ6X5ANvO 3xKbs4o3CPSJu7I4/2SX1Cn0xaRb54KXb+DopeuIqicPpf5wOJwnEUoBMEMPrEFHxxXl VthQ== X-Gm-Message-State: APjAAAWDIKmi1FEstoiL6+YoETJnh1qzlZ9LlpYZhSEG4QrMmDjRlvP3 CqmRsTYfyZMbGuWkmHNR6r3rWi9X X-Google-Smtp-Source: APXvYqw7FNPqkFy7t/u/nhyR6YxN0OXdubmFgFsW0T5uwZMUYuJVA3G/BPPUiJw4eIraEM3kfhdR2A== X-Received: by 2002:a0c:e603:: with SMTP id z3mr14478483qvm.50.1573847100797; Fri, 15 Nov 2019 11:45:00 -0800 (PST) From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Fri, 15 Nov 2019 14:44:09 -0500 Message-Id: <1997f553223508247777fb47fce9af3f658c5d74.1573840474.git.rosbrookn@ainfosec.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 02/22] golang/xenlight: define Defbool builtin type X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Nick Rosbrook , Ian Jackson , kerriganb@ainfosec.com, George Dunlap , Wei Liu Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Nick Rosbrook Define Defbool as struct analagous to the C type, and define the type 'defboolVal' that represent true, false, and default defbool values. Implement Set, Unset, SetIfDefault, IsDefault, Val, and String functions on Defbool so that the type can be used in Go analagously to how its used in C. Finally, implement fromC and toC functions. Signed-off-by: Nick Rosbrook Reviewed-by: George Dunlap --- tools/golang/xenlight/xenlight.go | 93 +++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenl= ight.go index 89ed439fd0..640d82f35f 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -85,6 +85,99 @@ type MemKB uint64 =20 type Uuid C.libxl_uuid =20 +// defboolVal represents a defbool value. +type defboolVal int + +const ( + defboolDefault defboolVal =3D 0 + defboolFalse defboolVal =3D -1 + defboolTrue defboolVal =3D 1 +) + +// Defbool represents a libxl_defbool. +type Defbool struct { + val defboolVal +} + +func (d Defbool) String() string { + switch d.val { + case defboolDefault: + return "" + case defboolFalse: + return "False" + case defboolTrue: + return "True" + } + + return "" +} + +// Set sets the value of the Defbool. +func (d *Defbool) Set(b bool) { + if b { + d.val =3D defboolTrue + return + } + d.val =3D defboolFalse +} + +// Unset resets the Defbool to default value. +func (d *Defbool) Unset() { + d.val =3D defboolDefault +} + +// SetIfDefault sets the value of Defbool only if +// its current value is default. +func (d *Defbool) SetIfDefault(b bool) { + if d.IsDefault() { + d.Set(b) + } +} + +// IsDefault returns true if the value of Defbool +// is default, returns false otherwise. +func (d *Defbool) IsDefault() bool { + return d.val =3D=3D defboolDefault +} + +// Val returns the boolean value associated with the +// Defbool value. An error is returned if the value +// is default. +func (d *Defbool) Val() (bool, error) { + if d.IsDefault() { + return false, fmt.Errorf("%v: cannot take value of default defbool", Err= orInval) + } + + return (d.val > 0), nil +} + +func (d *Defbool) fromC(c *C.libxl_defbool) error { + if C.libxl_defbool_is_default(*c) { + d.val =3D defboolDefault + return nil + } + + if C.libxl_defbool_val(*c) { + d.val =3D defboolTrue + return nil + } + + d.val =3D defboolFalse + + return nil +} + +func (d *Defbool) toC() (C.libxl_defbool, error) { + var c C.libxl_defbool + + if !d.IsDefault() { + val, _ :=3D d.Val() + C.libxl_defbool_set(&c, C.bool(val)) + } + + return c, nil +} + type Context struct { ctx *C.libxl_ctx logger *C.xentoollog_logger_stdiostream --=20 2.19.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel