From patchwork Tue Dec 10 15:47:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11282871 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 2011A14BD for ; Tue, 10 Dec 2019 15:49:12 +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 F0DE8207FF for ; Tue, 10 Dec 2019 15:49:11 +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="TtKXJkME" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F0DE8207FF 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 1iehkL-00032A-Ty; Tue, 10 Dec 2019 15:48:21 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iehkK-00031j-S6 for xen-devel@lists.xenproject.org; Tue, 10 Dec 2019 15:48:20 +0000 X-Inumbo-ID: 6fe772f2-1b64-11ea-a1e1-bc764e2007e4 Received: from mail-qv1-xf42.google.com (unknown [2607:f8b0:4864:20::f42]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6fe772f2-1b64-11ea-a1e1-bc764e2007e4; Tue, 10 Dec 2019 15:47:57 +0000 (UTC) Received: by mail-qv1-xf42.google.com with SMTP id o18so4362170qvf.1 for ; Tue, 10 Dec 2019 07:47:57 -0800 (PST) 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=LI98nKVqVPVJ264Gwu280nugbkHUVeryCxnErgot7XQ=; b=TtKXJkMEp5aXVuwJn+B49mebLdzJu/zKFtdZYdLXQbgcsk/jiQnURaVor81rxqVTb9 KPwZIlXHa/ofY31DqPMkwuDfGYfrvuNfFJlgKw07FbpJNjz0Xhmf1WBWgy7btudsqac1 oYgMuDOg2JJFjgA8Lb7fwJwoVpLVnYMDa/UQXa+ohE7WIxVxLgvkBUiIvYEuGUYx/u/e HwdgGZYqRqRwQqhwrjChMaskUDRYeNpfAW39fbtMmyTnrbluCHSMlKqE5/pcxR3lD9Xi pVfAmf0jWgMZzW69Lnfu38yFLOQzhC0TLMAxG8K4n5bae0Sg3qRdcsLXqEd4vyZ40oV2 I+iA== 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=LI98nKVqVPVJ264Gwu280nugbkHUVeryCxnErgot7XQ=; b=JLYdbo7TdI01tqpZG2XCcbUEBCmu+MHCyirbcAUS0KQrlxxpPmsgFtZh9MUbmAPnhI Fy9Y/7qkSf/gmeDo1PtB4NDTDxshi5jdZh/xac9ktYOl78fUFjIM13YVz3+yhnUGjmdX hvW2JPtG5MX4N1Mrip1i5jqsjG5d/w9+TKZVRxwU321RrVhc5OlpmvgaeQymg6tyIJv3 9HYaY65ckxi7R/G/Qp2GbzNeVcKpXmYyE3YwTRy71K7qklUrCGRrTTPmVVD4rPI0qhq3 W9BXnVWLeartTFoLfXAezOxQ7C5sfOGbLAx7OnqTm3ClyOd/om1YB7H2VIx0WKbgWYMi ToQw== X-Gm-Message-State: APjAAAWKfwZSpIta/ompBDBbOHNL688Wk0sK6kOjR/p3WwUf6PcVCmF3 t02sBu901vJKy0Pv/eP3jP+D7t/M X-Google-Smtp-Source: APXvYqyhKJwJ4aID2FLPRTM2Ag3jog5KMtO1TPYhCBceOCItIr7Mm6ee7fu+x7PJuTQT04WGE/Muew== X-Received: by 2002:ad4:436d:: with SMTP id u13mr10048515qvt.171.1575992876969; Tue, 10 Dec 2019 07:47:56 -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 m29sm1247848qtf.1.2019.12.10.07.47.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 07:47:56 -0800 (PST) From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Tue, 10 Dec 2019 10:47:21 -0500 Message-Id: <68236a9fc20a48988703da4eb0ab19821b59d271.1575990937.git.rosbrookn@ainfosec.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 06/22] 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 Reviewed-by: George Dunlap --- Changes in v2: - Define fromC with a pointer receiver since a newly-allocated slice is being assigned to the StringList. --- 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 1c5e3c0cc7..72afc3cf14 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -212,6 +212,35 @@ type KeyValueList struct{} func (kvl KeyValueList) fromC(ckvl *C.libxl_key_value_list) error { return nil } func (kvl KeyValueList) toC() (ckvl C.libxl_key_value_list, err error) { return } +// 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