From patchwork Fri Nov 15 19:44:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11247027 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 7D51613BD for ; Fri, 15 Nov 2019 19:46:37 +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 592DF2063A for ; Fri, 15 Nov 2019 19:46:37 +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="c27jSecj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 592DF2063A 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 1iVhX9-0001S0-JA; Fri, 15 Nov 2019 19:45:31 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iVhX7-0001R7-H3 for xen-devel@lists.xenproject.org; Fri, 15 Nov 2019 19:45:29 +0000 X-Inumbo-ID: 6c90e576-07e0-11ea-b678-bc764e2007e4 Received: from mail-qk1-x741.google.com (unknown [2607:f8b0:4864:20::741]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6c90e576-07e0-11ea-b678-bc764e2007e4; Fri, 15 Nov 2019 19:45:06 +0000 (UTC) Received: by mail-qk1-x741.google.com with SMTP id z23so9018171qkj.10 for ; Fri, 15 Nov 2019 11:45:06 -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=j+D3dXLMNwiMvNOw7Ex7Mwtiy4OdwQ8VSO0q/w4NLMs=; b=c27jSecjkQJFdWQ9qVPnLGwZFgnIfADW1fy6Z8DwOsiv8LIarDbVNAxDs2y0YpnVHT OovuzlqQLaTL15Q2ISYFnldHAKd+IM3gtFRdy6F3pIwAmD4l/6Gr3CRBw5Xm7SaLO/xF WqQMnlkE1voWiVXUrmM3atYq2wLSDGXZQ44LLbV+YhG2a+UFOMzjI4/vFqAfJd/xJNK5 BioG/rON3/nVgPJvCNhDx8KFA+Kli9WuImUDZcdqSyZxestARn7Qt9mhkhZqxpur0lPr ZyiDuRp0anNO1zWYJsoLQug00nG+m7WgPfPZNR1GEA+CfviQDR0H+dtaxENxFDUKixmQ lJoQ== 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=j+D3dXLMNwiMvNOw7Ex7Mwtiy4OdwQ8VSO0q/w4NLMs=; b=Khy3FI3tpm5TOe05tBgx3DhT51wjiLCZrc8Spz6pmCUOlwErbh7RSEAfbK8qsvFZQv Gz3ZJv7mgPDWs7xnpAmxOaw7FKlDaJvZpINiR1JbvfDJTia7nbU3jGaD8FM1g+f8bFso MtaCQFC3qocJGNTyfnpfe3FBZ7YWFof+9hiuKRGA6nxzfoZsKHXfuABI/u4fuwvNLhMR soqz2lWSDqwTwarQXgxvG79XaON+nlX59wgrVYgZu2UnX+9B4Yy9GMWMLN11l64pGTud NwtAFsXALAhGlFMaDW/vJmNAD58d1xy84fyIRMgR84zOfL3Du2hlLWzRbmiiPu8tMg7F 9VFw== X-Gm-Message-State: APjAAAUgbq7yQI1tDfRfyr1z1FSGpIdDVxazBjQQRTZhZar67YiRVrS7 AwrHXfI28mDvL5ZVhaG4Jn/dcP2B X-Google-Smtp-Source: APXvYqyJk+68pGRGEPVra5iaCU43gtDpdSScxnEQFrHu3gXnXaA1A1AjL0bzqNbE/O5EpsJjULJtaQ== X-Received: by 2002:ae9:e8c5:: with SMTP id a188mr13988570qkg.17.1573847105681; Fri, 15 Nov 2019 11:45:05 -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.45.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 11:45:04 -0800 (PST) From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Fri, 15 Nov 2019 14:44:13 -0500 Message-Id: <10f1969a1431879c2f1f4bdbcb3f29a3dd81ea6d.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 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