Thread (1 message) 1 message, 1 author, 2019-06-13

Re: [PATCH 2/4] kwset: allow building with GCC 8

From: Junio C Hamano <hidden>
Date: 2019-06-13 16:11:38

"Johannes Schindelin via GitGitGadget" [off-list ref]
writes:
From: Johannes Schindelin <redacted>

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()`.
Yay.

The above description makes it sound as if this patch is an ugly
workaround, but I think this is "the proper thing" to do, as long as
the use of obstack stuff in this context is meant to allocate less
than MAX_LONG bytes at a time, even if long is somtimes smaller than
size_t.

Thanks.
quoted hunk
Signed-off-by: Johannes Schindelin <redacted>
---
 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))
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help