From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6FD5F428C6; Tue, 4 Apr 2023 18:19:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 057AF40EE3; Tue, 4 Apr 2023 18:19:55 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id 172EA40A7E for ; Tue, 4 Apr 2023 18:19:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680625192; x=1712161192; h=date:from:to:cc:subject:message-id:references: in-reply-to:mime-version; bh=qyqmnjcE1nNrfhBUOjSW1Ve8rBE57VY1E0ACenteCWE=; b=ED2u0TUt0owyTbF4ZeaMrroPNnOlYBQ0pFVhoi5ZebypvuWfzSkHQ1ez k2xCADpVlzCCGEsCEmoO6PNFtQm2BxNimwPj6DwkxuOg8omIBjv4vsOxi 05ESgxyb5MfRF6p4gIGSfxWAV58zZ2dFU10hwPwqiAiTg4D34zNDhWWNS h6Yf6QBgzZwfu+DULudBR7aFeBsU0jKhcOHw6BVbGWqBUCDA6HNfFO6o2 FgCLQ9MoWTpYMDyid2ZWRfxO2PfJOBM0JHchUD/JGyHHpZtEqie2z2XMH 0eb2zdc9txcy9Nqn0jL24umH1d3D/CMse9Q/lPy/3uVKX8k+6CC8EoM0V A==; X-IronPort-AV: E=McAfee;i="6600,9927,10670"; a="342255126" X-IronPort-AV: E=Sophos;i="5.98,318,1673942400"; d="scan'208";a="342255126" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2023 09:19:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10670"; a="1016165826" X-IronPort-AV: E=Sophos;i="5.98,318,1673942400"; d="scan'208";a="1016165826" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by fmsmga005.fm.intel.com with ESMTP; 04 Apr 2023 09:19:39 -0700 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Tue, 4 Apr 2023 09:19:38 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Tue, 4 Apr 2023 09:19:37 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21 via Frontend Transport; Tue, 4 Apr 2023 09:19:37 -0700 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.177) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.21; Tue, 4 Apr 2023 09:19:37 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d/K4HhHYfiyCRXvPt0dbynhJYWvOrZy0ZS334ulYZnelwnzPHcgpl+/RrF01Qge5LilffxvF5JDXt7hSLQ4lCS0VO+GH8BbKYywbKe9zMPcPi+1C/z6E+wCE2uMH5zWN2vOJ5/PIKwgvDuhrbUujtmeamWtyyjD7K7biFCWIa+LJCEkM2FCpvxVglvl4Qzjgc4g4GIZFkGefUWrfRZ/lO4U5CBS1mW+YZmleg+nMM/37UrHJ1nbO6G0r/41ZxrTZcWy5fY3Y9LASVkXsSoDdLq6Tc2OJYxRKv3Z5/njsnle1a2+LSckh3iGdPu4HktZWuDInJtHi0yCj3y+5x4F81g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BUj/iDAMHJOhYVPpodRDNshkk77brNrMzXa7kREvIKA=; b=U6ljxaaiW+0BgEiymxt5kfSe/qnuVlWNAv2lCmFpVttITjpYSzY7F4iJEtTZiwSce0BO56qKjbyGtFaj1vlcr9Q/tdCm81XMNtuyx8KpmLHpxvFeUJTBfNVkPEwSIl+pMbkoZnSPV5oNBp8yth+e+y6tgI7Zl72ofyl8fCgRnlWdsZa9am/kFgv1KAP8o7R6rQnLM2AY/AiQcAXNtXVVoOocI/NRBy8SvkM06Mi1d3UWQRBV1RsfhivwZvIuixYCudKS/pP64hZjfWNBxIwida8nN1bKX2rMtv1+vKM06KVkmicKm1avN6HL0crDjEipv0ZTatUWGyxdeFsh2H/E0Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) by MW3PR11MB4522.namprd11.prod.outlook.com (2603:10b6:303:2d::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.28; Tue, 4 Apr 2023 16:19:35 +0000 Received: from DS0PR11MB7309.namprd11.prod.outlook.com ([fe80::18d0:ac53:aa1d:d19c]) by DS0PR11MB7309.namprd11.prod.outlook.com ([fe80::18d0:ac53:aa1d:d19c%6]) with mapi id 15.20.6254.035; Tue, 4 Apr 2023 16:19:35 +0000 Date: Tue, 4 Apr 2023 17:19:26 +0100 From: Bruce Richardson To: Tyler Retzlaff CC: Konstantin Ananyev , "dev@dpdk.org" , "ciara.power@intel.com" , "david.marchand@redhat.com" , "thomas@monjalon.net" Subject: Re: [PATCH v3] telemetry: use portable syntax to initialize array Message-ID: References: <1680539424-20255-1-git-send-email-roretzla@linux.microsoft.com> <1680548365-16525-1-git-send-email-roretzla@linux.microsoft.com> <1680548365-16525-2-git-send-email-roretzla@linux.microsoft.com> <65480e4a272445779710dcc4c6f21dfa@huawei.com> <20230404155906.GE23247@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20230404155906.GE23247@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> X-ClientProxiedBy: LO4P123CA0626.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:294::11) To DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7309:EE_|MW3PR11MB4522:EE_ X-MS-Office365-Filtering-Correlation-Id: a32d3026-6477-48fe-78c7-08db35286162 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zwRlI1s0IXmYpKOUE9ycZWN/ez/kW92rQqy/isJ5WoyJeZGGDgmqL70FikIGywCJhmyMVB1QcVw43nNeFjd46O8hVKDC61yIm7AKkpuJfki5si1lehqfOGqWivkrPDi7wCMHIkufb1WTPQv/kdE9ep1FJ8kHhtve2itXOje1cs9YKTtdZDDM9N6I4yycf2m8uIGBinELiWUBlgBp/42mZo2bMyGYd+HlUJhkOD8zAYsFneuMPxcxC8ew4ip0lO3H6Ef2llzDiHxFUvbTVnE1qvoJzCyniupNf8Ots7Yr2QLirIfowZ/ESRd3Y0SBnrDGYSlgAljYP20izqRfeoKvhjVAgLS9iefCSLrSniWdy6SWXId9Y74QNV2MBqGNLrKR7RrCxs1zDZcR9tG+jPb51V9wbc8grH2knhuwhB7GhGrcJIA3AlStJjhfvrfxnXisIocG0t3fM60QRZ9ewOackJMfmeOQmFcNl8DB2ym06cqjgqP7Q2u/KUOAs/2vjv0ZU978QooToJydrAuFV/UAV5FYfNTYNDQVzvGsRGvDDuJhJAdLqjYsmE+KLj3VUNnm X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7309.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(396003)(39860400002)(376002)(366004)(136003)(346002)(451199021)(6916009)(66476007)(478600001)(82960400001)(66946007)(66556008)(5660300002)(54906003)(316002)(4326008)(8936002)(38100700002)(41300700001)(8676002)(186003)(53546011)(83380400001)(44832011)(6666004)(6486002)(6506007)(26005)(6512007)(86362001)(2906002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?CmG3N/sMlztrIAgaQWGQFz9WmmmTH5E76P0U7903h8GxHxM2NA0DNjboFDVb?= =?us-ascii?Q?pcG9BmEfYVUHhGnRlFoKiYhylIoUoRyranRzs0Qyamq7Oiff5a4qELRGBKma?= =?us-ascii?Q?D+mXUvptpuRo5pcDzYZcP2WHO9vcskXxQ2GKsZKN88Zt/cWyZWFLZ81c9mKm?= =?us-ascii?Q?rwFppe5haOlcFrfscReULMjxsP161VGJi9aC3EaTpDhjtOYpVpWQE/bto19G?= =?us-ascii?Q?vjTOzzAoV2GMTW1LxAYp/DbeexftAgugU8P9vRZQSRksbwWt91ys+7MqWVKd?= =?us-ascii?Q?tv9EPfBU8S8c8F4e3vaSQ9n5Mong5WM+uebOsJ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W1fSWlhQ+TxaxgHcSU3nvPSIZmf19ojOca2V?= =?us-ascii?Q?WRmBrWuZ75uVpVdPW6XtQ3MM5hVnzFUxp4/qGIVo7J+ivYubl5XbhVTVRm95?= =?us-ascii?Q?PVXLyH0GbdPTryQy4y81GBkF+NlhWbnKkQ4OECqZS3ogtVlCXIM/AIO0djLb?= =?us-ascii?Q?pfvzz78xT34eBujnWhM5WGhmiKme+GoEkAs7OHWmKjxxrSYs/mRjy4T1eVZP?= =?us-ascii?Q?QGClWkaSKZ1gtiwKe47fOgR4i6BxYs6VPC3g2JSxAqOpKddJn4mO+f5ZHMBa?= =?us-ascii?Q?P8cw5aT810McBNOKk3jUfFH4pFZwSSmcIqyoM2xEFZ/tL/Yah9DsQ4HBw+Si?= =?us-ascii?Q?cOMGz7irPn9oBU6fBS54LOrSZUouNdiWTR9A6qa/um4yJEDx/8u/W++m7QCa?= =?us-ascii?Q?qA=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: a32d3026-6477-48fe-78c7-08db35286162 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7309.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2023 16:19:35.4661 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zpzeLUYyOTG4YdLzfDeygvNPr/ScEbqTpspZHDLNS/oZTn2YwEBBEmCLlUgNKij2G24vXrtYLLlg3b7tdyuExROoTFUwHrXPVdJcIXvrHRI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR11MB4522 X-OriginatorOrg: intel.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Tue, Apr 04, 2023 at 08:59:06AM -0700, Tyler Retzlaff wrote: > On Tue, Apr 04, 2023 at 09:01:50AM +0000, Konstantin Ananyev wrote: > > > > > > > -----Original Message----- > > > From: Tyler Retzlaff > > > Sent: Monday, April 3, 2023 7:59 PM > > > To: dev@dpdk.org > > > Cc: ciara.power@intel.com; bruce.richardson@intel.com; david.marchand@redhat.com; thomas@monjalon.net; Tyler Retzlaff > > > > > > Subject: [PATCH v3] telemetry: use portable syntax to initialize array > > > > > > Use of ranges in designated initialization are a non-standard gcc > > > extension. Use loops to initialize permitted characters on first use. > > > > > > Signed-off-by: Tyler Retzlaff > > > --- > > > lib/telemetry/telemetry_data.c | 22 +++++++++++++++------- > > > 1 file changed, 15 insertions(+), 7 deletions(-) > > > > > > diff --git a/lib/telemetry/telemetry_data.c b/lib/telemetry/telemetry_data.c > > > index 2bac2de..562b387 100644 > > > --- a/lib/telemetry/telemetry_data.c > > > +++ b/lib/telemetry/telemetry_data.c > > > @@ -152,13 +152,21 @@ > > > static bool > > > valid_name(const char *name) > > > { > > > - char allowed[128] = { > > > - ['0' ... '9'] = 1, > > > - ['A' ... 'Z'] = 1, > > > - ['a' ... 'z'] = 1, > > > - ['_'] = 1, > > > - ['/'] = 1, > > > - }; > > > + int index; > > > + static bool initialized; > > > + static char allowed[128]; > > > + > > > + if (!initialized) { > > > + for (index = '0'; index <= '9'; index++) > > > + allowed[index] = 1; > > > + for (index = 'A'; index <= 'Z'; index++) > > > + allowed[index] = 1; > > > + for (index = 'a'; index <= 'z'; index++) > > > + allowed[index] = 1; > > > + allowed[(int)'_'] = allowed[(int)'/'] = 1; > > > + initialized = true; > > > + } > > > + > > > while (*name != '\0') { > > > if ((size_t)*name >= RTE_DIM(allowed) || allowed[(int)*name] == 0) > > > return false; > > > > Wonder isn't the same as: > > while (*name != 0) > > if (!isascii(name[0] || (!isalnum(name[0]) && name[0] != '_' && name[0] != '/')) > > return false; > > > > Or MSVC doesn't support these macros? > > it's standard C msvc supports it. Bruce acceptable to take Konstantin's > suggestion here? > Yep, I'm ok with it. If I may confuse things a little, how about combining the two? Use an array with individual initializers for the "special characters", but using isalnum() for the rest. That way we get a clear list of allowed chars at the top of the array, without having a massive list of individual letters and numbers. For example: [completely untested and not compiled!]. { /* non-alpha-numeric characters allowed in names */ static const char allowed[128] = { ['_'] = 1, ['/'] = 1 }; for ( ; *name != '\0'; name++) { if (isalnum(*name)) continue; if ((size_t)*name >= RTE_DIM(allowed) || allowed[(int)*name] == 0) return false; } return true; } I think something like this achieves a good balance between clarity and brevity. 1. We don't have a massive array definition 2. We do have a static constant array 3. We don't have the non-alnum character list hidden inside the middle of an "if" statement. /Bruce