From nobody Sun Feb 8 05:27:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1570704888; cv=none; d=zoho.com; s=zohoarc; b=RvzpMag2K/KqDRce6Ssee4I56OMqgqwAmUSK72Z+KBITh1WRreZaI1sb6fpDXZIAM1CC2ud9MMSE5PYr450TWgzLZfPPM80JMjTWTw8u2MNyfA+Fkn8JxuLEH+HFAUmzDWofbC2LVGoX+6ZEDzYEnfvms8Do0Nt63SSV4WfEtDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704888; 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=DnZG+87AR0H6eaNjeAupxl1EXMT9YyNAonWXbcfANKk=; b=VvWE2y0ckQvA1AoUQBGzYiMaajzqS3/bHd7qAEItEz8ur6OC9pH+hcKvNyUFValEeKZS/XJxxAMTD/0tbapj6vJFALlxDzhoHFv2/2iSgkFcsI0C9Ea3X8/Zz5HM8Vo7+GCFBPaWswxYjUrESZoPpkqpaVLLqNemcpb5d0LLih8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570704888407374.4257633945963; Thu, 10 Oct 2019 03:54:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D3A426696C; Thu, 10 Oct 2019 10:54:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B359960A9F; Thu, 10 Oct 2019 10:54:46 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7B2F3180BA9B; Thu, 10 Oct 2019 10:54:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAseHK010509 for ; Thu, 10 Oct 2019 06:54:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7D4A75C1B5; Thu, 10 Oct 2019 10:54:40 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB9EB5C22C; Thu, 10 Oct 2019 10:54:39 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:54:10 +0100 Message-Id: <20191010105413.4091-17-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= , Pavel Hrdina Subject: [libvirt] [PATCH v3 16/19] libxl: convert over to use GRegex for regular expressions X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 10 Oct 2019 10:54:47 +0000 (UTC) Reviewed-by: J=C3=A1n Tomko Reviewed-by: Pavel Hrdina Signed-off-by: Daniel P. Berrang=C3=A9 --- src/libxl/libxl_capabilities.c | 42 +++++++++++++++------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index 73ae0b3fa1..65c68ffb52 100644 --- a/src/libxl/libxl_capabilities.c +++ b/src/libxl/libxl_capabilities.c @@ -21,7 +21,6 @@ #include =20 #include -#include =20 #include "internal.h" #include "virlog.h" @@ -374,10 +373,10 @@ static int libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps) { const libxl_version_info *ver_info; - int err; - regex_t regex; + g_autoptr(GRegex) regex =3D NULL; + g_autoptr(GError) err =3D NULL; + g_autoptr(GMatchInfo) info =3D NULL; char *str, *token; - regmatch_t subs[4]; char *saveptr =3D NULL; size_t i; =20 @@ -398,12 +397,10 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps) return -1; } =20 - err =3D regcomp(®ex, XEN_CAP_REGEX, REG_EXTENDED); - if (err !=3D 0) { - char error[100]; - regerror(err, ®ex, error, sizeof(error)); + regex =3D g_regex_new(XEN_CAP_REGEX, G_REGEX_EXTENDED, 0, &err); + if (!regex) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to compile regex %s"), error); + _("Failed to compile regex %s"), err->message); return -1; } =20 @@ -436,31 +433,31 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps) nr_guest_archs < sizeof(guest_archs) / sizeof(guest_archs[0]) && (token =3D strtok_r(str, " ", &saveptr)) !=3D NULL; str =3D NULL) { - if (regexec(®ex, token, sizeof(subs) / sizeof(subs[0]), - subs, 0) =3D=3D 0) { - int hvm =3D STRPREFIX(&token[subs[1].rm_so], "hvm"); + if (g_regex_match(regex, token, 0, &info)) { + g_autofree char *modestr =3D g_match_info_fetch(info, 1); + g_autofree char *archstr =3D g_match_info_fetch(info, 2); + g_autofree char *suffixstr =3D g_match_info_fetch(info, 3); + int hvm =3D STRPREFIX(modestr, "hvm"); virArch arch; int pae =3D 0, nonpae =3D 0, ia64_be =3D 0; =20 - if (STRPREFIX(&token[subs[2].rm_so], "x86_32")) { + if (STRPREFIX(archstr, "x86_32")) { arch =3D VIR_ARCH_I686; - if (subs[3].rm_so !=3D -1 && - STRPREFIX(&token[subs[3].rm_so], "p")) + if (suffixstr !=3D NULL && STRPREFIX(suffixstr, "p")) pae =3D 1; else nonpae =3D 1; - } else if (STRPREFIX(&token[subs[2].rm_so], "x86_64")) { + } else if (STRPREFIX(archstr, "x86_64")) { arch =3D VIR_ARCH_X86_64; - } else if (STRPREFIX(&token[subs[2].rm_so], "ia64")) { + } else if (STRPREFIX(archstr, "ia64")) { arch =3D VIR_ARCH_ITANIUM; - if (subs[3].rm_so !=3D -1 && - STRPREFIX(&token[subs[3].rm_so], "be")) + if (suffixstr !=3D NULL && STRPREFIX(suffixstr, "be")) ia64_be =3D 1; - } else if (STRPREFIX(&token[subs[2].rm_so], "powerpc64")) { + } else if (STRPREFIX(archstr, "powerpc64")) { arch =3D VIR_ARCH_PPC64; - } else if (STRPREFIX(&token[subs[2].rm_so], "armv7l")) { + } else if (STRPREFIX(archstr, "armv7l")) { arch =3D VIR_ARCH_ARMV7L; - } else if (STRPREFIX(&token[subs[2].rm_so], "aarch64")) { + } else if (STRPREFIX(archstr, "aarch64")) { arch =3D VIR_ARCH_AARCH64; } else { continue; @@ -515,7 +512,6 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps) #endif } } - regfree(®ex); =20 for (i =3D 0; i < nr_guest_archs; ++i) { virCapsGuestPtr guest; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list