From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jb1L9-0002Wi-14 for mharc-grub-devel@gnu.org; Tue, 19 May 2020 08:27:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jb1L5-0002Po-Op for grub-devel@gnu.org; Tue, 19 May 2020 08:27:19 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:50342) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jb1L4-0003Lh-7m for grub-devel@gnu.org; Tue, 19 May 2020 08:27:19 -0400 Received: by mail-wm1-x343.google.com with SMTP id m12so2879410wmc.0 for ; Tue, 19 May 2020 05:27:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=zzmY7x2D0WMK10wzmSyv4INsMav42WVGmDEXjl+iBjQ=; b=xGeWl3S3xfmCJFPx58h0cDcjXsI/Z9wfhFSaV9y/cmtMxKrS1CH+ByqcpxCd80kMNJ 7p82Rm/Iqlzwj0G8F67+NH5WjlzRHe+tZtwTYO3M5ZBE9JJ1HfXKlpUV5WDCIg84NiKd /JfuknaD7tMWVQf7wNdzkSwW3xpOIW3TfupiRvvT1Nm72m/re9v61E8L8xWektq3HuIe QBi/PufmB9zrqUoAX0kA5sNcbm8YQGdX7uQKms/78t0nXxuWJazTfe3So0d/d/c/jWE3 ZQfjF8fBwMGkIiWZ6/0cY6x9SXfg94uyR/7d+Tay0y1yMiJ5p5c3bI/BydwexyLyzyhG 6V7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=zzmY7x2D0WMK10wzmSyv4INsMav42WVGmDEXjl+iBjQ=; b=ret+4Db/DpPJVk+a6aTjvE5R9Ohvw+j9WHkBd5v2hi6s5UhtnGDkoTeDe6lsUO6sUb mhN0mHdyIKANBV+emY2c2ulIu5BfA0bycNjy+1l4hg/ojo/enneTIPrBIZQm7jguzAPb ClUet+96SRN7aXQgdmq/MsBDvJLiUnJUKqcY0ObkEvNm4pK86z2bzu2q++PR1GWt6JxR GdJ8CgffvgUIKApwPLDGEi9+m0TD9HMyit/bRHW+lHt3axCPsof5DKQaNBbJYs7hvvmX Mx70YjVfQHZFyuhggwOQ4dh2prPF2JNtCXMq8RL5gD1jTvA99C+BTy7FnafVeoHDZLLl oMNQ== X-Gm-Message-State: AOAM533qLfab3QU6wxFUrutj2AFLzWzb2iTcMQICzJU3vWqwXvo1imAS xzbCCEu2LFqIWABa6jpFaBxvPvpEf5N0P4S5KGIrZcPIZHFyqcvPQarj9bVnR1i0sLITRjbdPFi NizAHQHs2XskZua085Lpyw1TplLh3Y1KsvhBjnTvkCAnIERwQngQvgLYiS0ogxt8= X-Google-Smtp-Source: ABdhPJzeIXnP8zsr9AqlZsofNmIyvGvzOre+2si3x8vo+J8OJ3Lz4wXrWxyUFg9j3SXqLcWh/Lclcw== X-Received: by 2002:a1c:27c2:: with SMTP id n185mr5747556wmn.68.1589891236075; Tue, 19 May 2020 05:27:16 -0700 (PDT) Received: from vanye ([2001:470:1f09:12f0:b26e:bfff:fea9:f1b8]) by smtp.gmail.com with ESMTPSA id x22sm3602712wmi.32.2020.05.19.05.27.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 05:27:15 -0700 (PDT) Date: Tue, 19 May 2020 13:27:13 +0100 From: Leif Lindholm To: The development of GNU GRUB Cc: Javier Martinez Canillas , Daniel Axtens , Daniel Kiper Subject: Re: [PATCH] net: Don't use nested functions to allow building with clang Message-ID: <20200519122713.GP10467@vanye> References: <20200519083422.950041-1-javierm@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200519083422.950041-1-javierm@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Received-SPF: pass client-ip=2a00:1450:4864:20::343; envelope-from=leif@nuviainc.com; helo=mail-wm1-x343.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 May 2020 12:27:20 -0000 Hi Javier, On Tue, May 19, 2020 at 10:34:22 +0200, Javier Martinez Canillas wrote: > Nested functions are supported as an extension in GNU C, but are not in > the clang compiler. Commit cb2f15c5448 ("normal/main: Search for specific > config files for netboot") added a nested function which caused the build > to break when compiling with clang. Thanks for this. And apologies for bikeshedding (but since there is a history with GRUB and nested functions, I will) - could we reword this to make fewer references to clang? Nested functions are an abomination not supported by the C language. I.e. something like. --- net: break out nested function Nested functions are not supported in C, but are permitted as an extension in the GNU C dialect. Commit cb2f15c5448 ("normal/main: Search for specific config files for netboot") added a nested function which caused the build to break when compiling with clang. Break that out into a static helper function to make the code portable again. --- > Reported-by: Daniel Axtens > Signed-off-by: Javier Martinez Canillas > --- > > grub-core/net/net.c | 65 +++++++++++++++++++++++---------------------- > 1 file changed, 33 insertions(+), 32 deletions(-) > > diff --git a/grub-core/net/net.c b/grub-core/net/net.c > index c42f0f4f71d..ec7e2899ed5 100644 > --- a/grub-core/net/net.c > +++ b/grub-core/net/net.c > @@ -1735,42 +1735,43 @@ grub_net_restore_hw (void) > return GRUB_ERR_NONE; > } > > -grub_err_t > -grub_net_search_config_file (char *config) > +static int grub_config_search_through (char *config, char *suffix, Style-wise, the function name should start in the first column on its own line. (Running the file through gnu indent with default options usually does the correct thing.) / Leif > + grub_size_t num_tries, > + grub_size_t slice_size) > { > - grub_size_t config_len; > - char *suffix; > + while (num_tries-- > 0) > + { > + grub_file_t file; > > - auto int search_through (grub_size_t num_tries, grub_size_t slice_size); > - int search_through (grub_size_t num_tries, grub_size_t slice_size) > - { > - while (num_tries-- > 0) > - { > - grub_file_t file; > + grub_dprintf ("net", "attempt to fetch config %s\n", config); > > - grub_dprintf ("net", "attempt to fetch config %s\n", config); > + file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG); > > - file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG); > + if (file) > + { > + grub_file_close (file); > + return 0; > + } > + else > + { > + if (grub_errno == GRUB_ERR_IO) > + grub_errno = GRUB_ERR_NONE; > + } > > - if (file) > - { > - grub_file_close (file); > - return 0; > - } > - else > - { > - if (grub_errno == GRUB_ERR_IO) > - grub_errno = GRUB_ERR_NONE; > - } > + if (grub_strlen (suffix) < slice_size) > + break; > > - if (grub_strlen (suffix) < slice_size) > - break; > + config[grub_strlen (config) - slice_size] = '\0'; > + } > > - config[grub_strlen (config) - slice_size] = '\0'; > - } > + return 1; > +} > > - return 1; > - } > +grub_err_t > +grub_net_search_config_file (char *config) > +{ > + grub_size_t config_len; > + char *suffix; > > config_len = grub_strlen (config); > config[config_len] = '-'; > @@ -1801,7 +1802,7 @@ grub_net_search_config_file (char *config) > if (client_uuid) > { > grub_strcpy (suffix, client_uuid); > - if (search_through (1, 0) == 0) > + if (grub_config_search_through (config, suffix, 1, 0) == 0) > return GRUB_ERR_NONE; > } > > @@ -1816,7 +1817,7 @@ grub_net_search_config_file (char *config) > if (*ptr == ':') > *ptr = '-'; > > - if (search_through (1, 0) == 0) > + if (grub_config_search_through (config, suffix, 1, 0) == 0) > return GRUB_ERR_NONE; > > /* By IP address */ > @@ -1831,7 +1832,7 @@ grub_net_search_config_file (char *config) > ((n >> 24) & 0xff), ((n >> 16) & 0xff), \ > ((n >> 8) & 0xff), ((n >> 0) & 0xff)); > > - if (search_through (8, 1) == 0) > + if (grub_config_search_through (config, suffix, 8, 1) == 0) > return GRUB_ERR_NONE; > break; > } > @@ -1848,7 +1849,7 @@ grub_net_search_config_file (char *config) > *ptr = '-'; > > grub_snprintf (suffix, GRUB_NET_MAX_STR_ADDR_LEN, "%s", buf); > - if (search_through (1, 0) == 0) > + if (grub_config_search_through (config, suffix, 1, 0) == 0) > return GRUB_ERR_NONE; > break; > } > -- > 2.26.2 > > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel