[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/5] xen/lib: Move simple_strtoul from common/vsprintf.c to lib


  • To: Shawn Anastasio <sanastasio@xxxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 1 Aug 2023 08:02:10 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • 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=VSdxrGNiCrZdrayjyWvZ3Jn8fHxqXvISrwMl3XFogzQ=; b=PQN0v2BZKMtLpom/H1HbOYJKWUwAXsfg8mplvIPAWj9b6KC3oZwXfQxiC1AsfMdx7/MnCq3nKMMnIDkzfa62R1M7ydBfUP3vHB3PmYqIFNLyBDomB/rYSK2ry21ieLlL0eWEB2wqb3qm6w4avRQwYVFWLA6Eaqhmp7FfkfNL0h7MdKawj7wzAzrGR6fnCrfhBXxqojRfOCiXQz0PT6OQ5XXnEovCrd/4+2gucrmaF7ufQLjaXXvsMjRXffC7bT4HApgtnGw0z/IFt4M1/pHgwGAVRInmAk7dsL0OEMbNaqI1F7hojsUu2PaRVMivGL6BqCo5Ua6Qf61lTsi1d3yjgg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MnAcJlPfDSZ7LkZZ5QakF7zAqsyNSHzTgww3UHTVVG3fPh8k8uOGmIyt29avpoNv2JblDlVlA5BlT6poo3nhDpiwA4675j7f76f/14BpxR+/pR799RdlUm4VeK/Ee+o2OAn27TyR5zBN+cJHgfPBm6iwX2wohP4AYoNN6aum4SsTujqJum+xt/XNSvxeVBdudlDw9uLqHveLHmJGWm6695jWOWY45HgrZ0ynKD4k+oiN2p4nUqwVLWTS9wCoNlPuTSnYKo1yAXQlKGCGU+g1ZgaZrNNoPasMSaR139DgBqMSJFw5Z0W3RkNZRmymtf1sneQK+tEzorA+3n0RpNRuyA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Timothy Pearson <tpearson@xxxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 01 Aug 2023 06:02:34 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 31.07.2023 21:03, Shawn Anastasio wrote:
> On 7/31/23 10:52 AM, Jan Beulich wrote:
>> On 28.07.2023 23:35, Shawn Anastasio wrote:
>>> Move the simple_strtoul routine which is used throughout the codebase
>>> from vsprintf.c to its own file in xen/lib.
>>>
>>> This allows libfdt to be built on ppc64 even though xen/common doesn't
>>> build yet.
>>>
>>> Signed-off-by: Shawn Anastasio <sanastasio@xxxxxxxxxxxxxxxxxxxxx>
>>> ---
>>>  xen/common/vsprintf.c    | 37 -------------------------------------
>>>  xen/lib/Makefile         |  1 +
>>>  xen/lib/simple_strtoul.c | 40 ++++++++++++++++++++++++++++++++++++++++
>>>  3 files changed, 41 insertions(+), 37 deletions(-)
>>>  create mode 100644 xen/lib/simple_strtoul.c
>>
>> What about its siblings? It'll be irritating to find one here and the
>> other there.
> 
> I was debating whether to do this or not and ultimately decided to only
> make the minimum changes that were required right now. I can go ahead
> and make the change for its siblings as well.
> 
>> Also please no underscores in (new) filenames unless there's a reason
>> for this. In the case here, though, I question the need for "simple"
>> in the file name in the first place.
> 
> From a look at the other files in xen/lib there seemed to be a
> convention of naming files after the exact function they implement.
> Would you rather I rename it to just strtoul.c? Or simple-strotoul.c?

I'd prefer the former over the latter. While your observation of
convention has been true so far, I think the shorter names are to
be preferred here. They're not going to cause issues, as I don't
see us gaining non-simple_* functions.

>>> --- /dev/null
>>> +++ b/xen/lib/simple_strtoul.c
>>> @@ -0,0 +1,40 @@
>>> +/*
>>> + *  Copyright (C) 1991, 1992  Linus Torvalds
>>> + */
>>> +
>>> +#include <xen/ctype.h>
>>> +
>>> +/**
>>> + * simple_strtoul - convert a string to an unsigned long
>>> + * @cp: The start of the string
>>> + * @endp: A pointer to the end of the parsed string will be placed here
>>> + * @base: The number base to use
>>> + */
>>> +unsigned long simple_strtoul(
>>> +    const char *cp, const char **endp, unsigned int base)
>>> +{
>>> +    unsigned long result = 0,value;
>>> +
>>> +    if (!base) {
>>> +        base = 10;
>>> +        if (*cp == '0') {
>>> +            base = 8;
>>> +            cp++;
>>> +            if ((toupper(*cp) == 'X') && isxdigit(cp[1])) {
>>> +                cp++;
>>> +                base = 16;
>>> +            }
>>> +        }
>>> +    } else if (base == 16) {
>>> +        if (cp[0] == '0' && toupper(cp[1]) == 'X')
>>> +            cp += 2;
>>> +    }
>>> +    while (isxdigit(*cp) &&
>>> +           (value = isdigit(*cp) ? *cp-'0' : toupper(*cp)-'A'+10) < base) {
>>> +        result = result*base + value;
>>> +        cp++;
>>> +    }
>>> +    if (endp)
>>> +        *endp = cp;
>>> +    return result;
>>> +}
>>
>> While moving, I think it would be nice if this stopped using neither
>> Xen nor Linux style. I'm not going to insist, but doing such style
>> adjustments right here would be quite nice.
> 
> Especially if I'm going to be moving its siblings, I'd rather just copy
> the functions verbatim for this patch, if that's acceptable.

As said - I wouldn't insist, but in this case maybe I take the time
and make the slightly more "complete" change.

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.