Re: [PATCH 2/4] kwset: allow building with GCC 8
- From
SZEDER Gábor <szeder.dev@gmail.com>
- Date
- Jun 14, 2019, 09:53 UTC
- Message-ID
- <20190614095308.GG31952@szeder.dev>
- In-Reply-To
- <c1527a71672056859a4613f2318bcbfce31e8b50.1560426581.git.gitgitgadget@gmail.com>
> Subject: Re: [PATCH 2/4] kwset: allow building with GCC 8
The subject could benefit from a "on Windows" at the end; 'kwset' and compat/obstack can be build with GCC 8 and 9 just fine on some other platforms.
On Thu, Jun 13, 2019 at 04:49:45AM -0700, Johannes Schindelin via GitGitGadget wrote:
Show 11 quoted lines
> From: Johannes Schindelin <johannes.schindelin@gmx.de> > > The kwset functionality makes use of the obstack code, which expects to > be handed a function that can allocate large chunks of data. It expects > that function to accept a `size` parameter of type `long`. > > This upsets GCC 8 on Windows, because `long` does not have the same > bit size as `size_t` there. > > Now, the proper thing to do would be to switch to `size_t`. But this > would make us deviate from the "upstream" code even further,
This is not entirely true: upstream already uses 'size_t', so the switch would actually bring our copy closer to upstream.
But look out for the patches that I'll send out in a minute...
Show 34 quoted lines
> making it
> hard to synchronize with newer versions, and also it would be quite
> involved because that `long` type is so invasive in that code.
>
> Let's punt, and instead provide a super small wrapper around
> `xmalloc()`.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> kwset.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/kwset.c b/kwset.c
> index 4fb6455aca..efc2ff41bc 100644
> --- a/kwset.c
> +++ b/kwset.c
> @@ -38,7 +38,13 @@
> #include "compat/obstack.h"
>
> #define NCHAR (UCHAR_MAX + 1)
> -#define obstack_chunk_alloc xmalloc
> +/* adapter for `xmalloc()`, which takes `size_t`, not `long` */
> +static void *obstack_chunk_alloc(long size)
> +{
> + if (size < 0)
> + BUG("Cannot allocate a negative amount: %ld", size);
> + return xmalloc(size);
> +}
> #define obstack_chunk_free free
>
> #define U(c) ((unsigned char) (c))
> --
> gitgitgadget
>