From patchwork Mon Oct 7 15:12:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11177787 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4852313BD for ; Mon, 7 Oct 2019 15:15:10 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 23F852070B for ; Mon, 7 Oct 2019 15:15:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pxr13ILi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 23F852070B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iHUhs-0006sX-P0; Mon, 07 Oct 2019 15:13:52 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iHUhr-0006s4-NT for xen-devel@lists.xenproject.org; Mon, 07 Oct 2019 15:13:51 +0000 X-Inumbo-ID: 01a48838-e915-11e9-96dc-bc764e2007e4 Received: from mail-qt1-x841.google.com (unknown [2607:f8b0:4864:20::841]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 01a48838-e915-11e9-96dc-bc764e2007e4; Mon, 07 Oct 2019 15:13:24 +0000 (UTC) Received: by mail-qt1-x841.google.com with SMTP id i26so2647377qtm.8 for ; Mon, 07 Oct 2019 08:13:24 -0700 (PDT) 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=x6JGuVoR7EXpvX1Eyn2HjZht2i/5NyzftbPM9QkorXQ=; b=pxr13ILiir8WEMJ4gFxv70t61cLWLhJie4SDBlSrMhJKoi100fA8WW3P4VDVTDoHVg BA8CaQENFFWnNf7gw8V1LciQ5ZoXT2vKJR8L66MGWLx1//dRSWYVCDCDBv0KSj+Zp0H7 06aofXOaUFFDrHG1cKqc/4Bomr6CcgW35je4v7MwnCxWDfQr1wE23APpRj+c33dyDR4C 3eP5/rPgJ5lC0EhZiB1Iq6gZrqSfY5W5ZfWJT11gkSK4Zb//wXQJ0bcO9kBFmbq5vCVj hJQd9vsW6flfHvsteGSJcu56tjMCuL2m36Eg3NeDPQqWchavc6PMDnxzoPvhlBmpUsWI /1IQ== 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=x6JGuVoR7EXpvX1Eyn2HjZht2i/5NyzftbPM9QkorXQ=; b=cbT+BL2SK7ZWuYBxV9d4mUpWZAkW7PFdmOoy0gZ1PaJM1ozPP8x4ahOF8a32FJoNS4 vhr++EtmUfRzM1SXIvmGrSowlzURAjrtNZPUEbWf7I3jbpSC0dkZ8yF+dzsf9P7VC/3G LMF5Uazj3YCkO8kN5aM+9m8RklSDJYAA01POHWBdi/UHcgSit4NHK5NIz3eaCwUkH/x4 IjeR4TcVhXqQmeHnTMCtN7RJvl/G87zmlYw/dWCxPaKgkOTKBTcb+0h+R8si1Odq8413 AeUHywCvQvg+uNqZV5yR1+SlQdFmpSg3yo954/Y357pk55W0vqhfu1I5sD+FbSyQCCU0 izoQ== X-Gm-Message-State: APjAAAV6i4gX9CgA5fvevSVHXGGK+yb+eDp+DVIXvabt3SG61VP4i/Qj jYzvCrQ3pGbV0xbp9XGgvyfm8ivX X-Google-Smtp-Source: APXvYqzt8npUM/Zb/KWEetdN45k+WfbIfHqr19m2vq9VclNfNJXfc1DGyDZIKlbBVeZgBP08fZ2iUA== X-Received: by 2002:ac8:5046:: with SMTP id h6mr30894932qtm.13.1570461203690; Mon, 07 Oct 2019 08:13:23 -0700 (PDT) Received: from five.crux.rad.ainfosec.com (209-217-208-226.northland.net. [209.217.208.226]) by smtp.googlemail.com with ESMTPSA id c185sm8354313qkg.74.2019.10.07.08.13.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 08:13:23 -0700 (PDT) From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Mon, 7 Oct 2019 11:12:54 -0400 Message-Id: <1644cc12566ebdbcaddde8994a65dde029d0226a.1570456846.git.rosbrookn@ainfosec.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 07/24] golang/xenlight: define StringList 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 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Nick Rosbrook Define StringList as []string an implement fromC and toC functions. Signed-off-by: Nick Rosbrook --- Cc: George Dunlap Cc: Ian Jackson Cc: Wei Liu tools/golang/xenlight/xenlight.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index 09fcdca5d1..a3a1836d31 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -234,6 +234,35 @@ func (kvl KeyValueList) toC() (C.libxl_key_value_list, error) { return ckvl, nil } +// StringList represents a libxl_string_list. +type StringList []string + +func (sl StringList) fromC(csl *C.libxl_string_list) error { + size := int(C.libxl_string_list_length(csl)) + list := (*[1 << 30]*C.char)(unsafe.Pointer(csl))[:size:size] + + sl = make([]string, size) + + for i, v := range list { + sl[i] = C.GoString(v) + } + + return nil +} + +func (sl StringList) toC() (C.libxl_string_list, error) { + var char *C.char + size := len(sl) + csl := (C.libxl_string_list)(C.malloc(C.ulong(size) * C.ulong(unsafe.Sizeof(char)))) + clist := (*[1 << 30]*C.char)(unsafe.Pointer(csl))[:size:size] + + for i, v := range sl { + clist[i] = C.CString(v) + } + + return csl, nil +} + // Bitmap represents a libxl_bitmap. // // Implement the Go bitmap type such that the underlying data can