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 A179743B0F; Thu, 15 Feb 2024 10:08:58 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 88A5242EA1; Thu, 15 Feb 2024 10:08:58 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 2EAC5406B6 for ; Thu, 15 Feb 2024 10:08:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707988136; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hQ/uRjDxQfYbNaEzvJfsUNZO2q6qiXdLMnqsfdvJI+o=; b=IvveH06/W9Dav5TEyGC4Eg8W08qM2sa7VdETcg3Y2HNV2odNuVOsEhKYZVtMwXu8SMq+5t f2SLWtIdn7aEtvLl+MpGcEWp3mrs0lcxl897Kq6XcUILnPeUtwx3whgkwd76OaCLpJVwzp muUlo2SWpyYjce+a9DWe9wuupmjoiKo= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-684-isuBsduQNkq2zKvgan_WBQ-1; Thu, 15 Feb 2024 04:08:54 -0500 X-MC-Unique: isuBsduQNkq2zKvgan_WBQ-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-511559b30edso336133e87.3 for ; Thu, 15 Feb 2024 01:08:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707988132; x=1708592932; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hQ/uRjDxQfYbNaEzvJfsUNZO2q6qiXdLMnqsfdvJI+o=; b=RYSxsky6NJyXzJu7RL78MAZZzje3SLs9rWnv059Z0Q2eoZIdK1KmXjDWgeKtYdOwUU jxR0ITRSOkG6tnDKhYmbeUSi7EdiJn6NH8evS3J7b843Jz4fMA1nclVAhlsqJ+g+pdBb G86waXuNeMeuDPPA/bAgeM/xnqdsYmwobfwhzen2IJ79Rcu86fxDlA4lbM1C6l65XhbB xDZ8WXrrMiAn9HHdsKYVLbsZtXflmRrFTKm/KxZe21CDUupjcHisuAJFqQJDoL1ObZAZ SvPBNLQJMO/7Sf3mI0BGdKkKQwaoWnK8OYBtDCWe+OkfEHZvqv3zfxCtHpPXFS6/LfmJ mHIA== X-Gm-Message-State: AOJu0YyhW8C3X/7idcWPhf97p+zeMM9Rsb3b9H1H+OcGtUbzFghNlboP sklwy1/yW2qdAAlV17LxMnheh4AYuBSrqlte97xKE6yrVQdOU6UOoIYL7lG2fXCnIJPWErWMuV7 IGPmdHAsDDB/t6M2cbheOOF9+REJBA56Nmlb1ZHloEMMegA/l6f/eH/r6clxW+iS1FEhQY2fhuY jdc1Xypou6xncYT3E= X-Received: by 2002:ac2:58f3:0:b0:511:86ce:3920 with SMTP id v19-20020ac258f3000000b0051186ce3920mr1053101lfo.7.1707988132728; Thu, 15 Feb 2024 01:08:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IGrSc/+7xHp+O7Na6TLhGv3cfI07i+NAMDeuevrAx76G93KJs3d49JZTFF/HjScEjVvnBojrbQikkWRCAQiaxE= X-Received: by 2002:ac2:58f3:0:b0:511:86ce:3920 with SMTP id v19-20020ac258f3000000b0051186ce3920mr1053075lfo.7.1707988132403; Thu, 15 Feb 2024 01:08:52 -0800 (PST) MIME-Version: 1.0 References: <20240214121219.3408867-1-david.marchand@redhat.com> In-Reply-To: From: David Marchand Date: Thu, 15 Feb 2024 10:08:40 +0100 Message-ID: Subject: Re: [PATCH] eal: add helper to skip whitespaces To: Bruce Richardson Cc: dev@dpdk.org, roretzla@linux.microsoft.com, Sunil Kumar Kori , Rakesh Kudurumalla , Jerin Jacob , Srikanth Yalavarthi , Cristian Dumitrescu , Aman Singh , Yuying Zhang , Brian Dooley , Gowrishankar Muthukrishnan X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Wed, Feb 14, 2024 at 2:07=E2=80=AFPM Bruce Richardson wrote: > > On Wed, Feb 14, 2024 at 01:12:19PM +0100, David Marchand wrote: > > Reduce code duplication by providing a simple inline helper. > > > > Signed-off-by: David Marchand > > --- > > app/graph/utils.c | 13 ++------ > > app/test-eventdev/parser.c | 14 ++++----- > > app/test-eventdev/parser.h | 8 ----- > > app/test-mldev/parser.c | 17 ++++++----- > > app/test-mldev/parser.h | 8 ----- > > app/test-pmd/cmdline_tm.c | 13 ++------ > > app/test/test_string_fns.c | 35 ++++++++++++++++++++++ > > examples/fips_validation/fips_validation.c | 16 +++------- > > examples/ip_pipeline/parser.c | 14 ++++----- > > examples/ip_pipeline/parser.h | 8 ----- > > examples/pipeline/cli.c | 13 ++------ > > lib/eal/include/rte_string_fns.h | 27 +++++++++++++++++ > > 12 files changed, 98 insertions(+), 88 deletions(-) > > > > diff --git a/app/graph/utils.c b/app/graph/utils.c > > index c7b6ae83cf..1f5ee68273 100644 > > --- a/app/graph/utils.c > > +++ b/app/graph/utils.c > > @@ -9,17 +9,10 @@ > > #include > > > > #include > > +#include > > > > #include "module_api.h" > > > > -#define white_spaces_skip(pos) \ > > -({ \ > > - __typeof__(pos) _p =3D (pos); \ > > - for ( ; isspace(*_p); _p++) \ > > - ; \ > > - _p; \ > > -}) > > - > > static void > > hex_string_to_uint64(uint64_t *dst, const char *hexs) > > { > > @@ -47,7 +40,7 @@ parser_uint64_read(uint64_t *value, const char *p) > > char *next; > > uint64_t val; > > > > - p =3D white_spaces_skip(p); > > + p =3D rte_str_skip_whitespaces(p); > > if (!isdigit(*p)) > > return -EINVAL; > > > > @@ -73,7 +66,7 @@ parser_uint64_read(uint64_t *value, const char *p) > > break; > > } > > > > - p =3D white_spaces_skip(p); > > + p =3D rte_str_skip_whitespaces(p); > > I like the idea of this. However, a question on naming. Do we want to mak= e > it clear in the name that it only skips leading whitespace, and doesn't > e.g. trim whitespace off the end? How about: > > rte_str_skip_leading_spaces() > > It's longer, but I wonder if it's a bit clearer. It is clearer. > > Also, might it be worthwhile providing an "rte_str_ltrim()" function alon= g > with this, basically combining the skip_spaces call, with an memmove? Mos= t > string handling in DPDK is not perf-sensitive and so a function with > similar name and behaviour to the python ltrim function may be appreciate= d > for its simplicity. Well, most intree users won't touch the data (and simply pass around const char * pointers). This new API you propose is probably fine, but I suspect it won't be of much use for now. Looking at those intree users, the stripping of whitespaces is just the tip of the iceberg. Every users is parsing integers etc... So maybe a better work would be to list what is needed and provide such hel= pers. This would further reduce code duplication. To be franck, I have no big motivation behind this patch. I found out this copy/paste statement expression macro everywhere while reviewing Tyler series, and I wanted to shoot it. If someone wants to take over, they are welcome. --=20 David Marchand