kwset: allow building with GCC 8

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, 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jun 13, 2019 at 04:49 UTC 08e0450690b8f4aa0f51d8c096520817f96de3dd
1 file changed +7 -1
kwset.c
+7 -1
@@ -38,7 +38,13 @@
38 #include "compat/obstack.h"
39
40 #define NCHAR (UCHAR_MAX + 1)
41 -#define obstack_chunk_alloc xmalloc
41 +/* adapter for `xmalloc()`, which takes `size_t`, not `long` */
42 +static void *obstack_chunk_alloc(long size)
43 +{
44 + if (size < 0)
45 + BUG("Cannot allocate a negative amount: %ld", size);
46 + return xmalloc(size);
47 +}
48 #define obstack_chunk_free free
49
50 #define U(c) ((unsigned char) (c))