convert ewah/bitmap code to use xmalloc
This code was originally written with the idea that it could be spun off into its own ewah library, and uses the overrideable ewah_malloc to do allocations. We plug in xmalloc as our ewah_malloc, of course. But over the years the ewah code itself has become more entangled with git, and the return value of many ewah_malloc sites is not checked. Let's just drop the level of indirection and use xmalloc and friends directly. This saves a few lines, and will let us adapt these sites to our more advanced malloc helpers. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Feb 22, 2016 at 17:45 UTC
fb7dbf3e7a668ab60c158d3d1efc77578ef9db1b
4 files changed
+11
-30
ewah/bitmap.c
+6
-6
@@ -25,8 +25,8 @@
25
26
struct bitmap *bitmap_new(void)
27
{
28
- struct bitmap *bitmap = ewah_malloc(sizeof(struct bitmap));
29
- bitmap->words = ewah_calloc(32, sizeof(eword_t));
28
+ struct bitmap *bitmap = xmalloc(sizeof(struct bitmap));
29
+ bitmap->words = xcalloc(32, sizeof(eword_t));
30
bitmap->word_alloc = 32;
31
return bitmap;
32
}
@@ -38,8 +38,8 @@ void bitmap_set(struct bitmap *self, size_t pos)
38
if (block >= self->word_alloc) {
39
size_t old_size = self->word_alloc;
40
self->word_alloc = block * 2;
41
- self->words = ewah_realloc(self->words,
42
- self->word_alloc * sizeof(eword_t));
41
+ self->words = xrealloc(self->words,
42
+ self->word_alloc * sizeof(eword_t));
43
44
memset(self->words + old_size, 0x0,
45
(self->word_alloc - old_size) * sizeof(eword_t));
@@ -102,7 +102,7 @@ struct bitmap *ewah_to_bitmap(struct ewah_bitmap *ewah)
102
while (ewah_iterator_next(&blowup, &it)) {
103
if (i >= bitmap->word_alloc) {
104
bitmap->word_alloc *= 1.5;
105
- bitmap->words = ewah_realloc(
105
+ bitmap->words = xrealloc(
106
bitmap->words, bitmap->word_alloc * sizeof(eword_t));
107
}
108
@@ -134,7 +134,7 @@ void bitmap_or_ewah(struct bitmap *self, struct ewah_bitmap *other)
134
135
if (self->word_alloc < other_final) {
136
self->word_alloc = other_final;
137
- self->words = ewah_realloc(self->words,
137
+ self->words = xrealloc(self->words,
138
self->word_alloc * sizeof(eword_t));
139
memset(self->words + original_size, 0x0,
140
(self->word_alloc - original_size) * sizeof(eword_t));
ewah/ewah_bitmap.c
+3
-6
@@ -39,7 +39,7 @@ static inline void buffer_grow(struct ewah_bitmap *self, size_t new_size)
39
return;
40
41
self->alloc_size = new_size;
42
- self->buffer = ewah_realloc(self->buffer,
42
+ self->buffer = xrealloc(self->buffer,
43
self->alloc_size * sizeof(eword_t));
44
self->rlw = self->buffer + (rlw_offset / sizeof(eword_t));
45
}
@@ -282,11 +282,8 @@ struct ewah_bitmap *ewah_new(void)
282
{
283
struct ewah_bitmap *self;
284
285
- self = ewah_malloc(sizeof(struct ewah_bitmap));
286
- if (self == NULL)
287
- return NULL;
288
-
289
- self->buffer = ewah_malloc(32 * sizeof(eword_t));
285
+ self = xmalloc(sizeof(struct ewah_bitmap));
286
+ self->buffer = xmalloc(32 * sizeof(eword_t));
287
self->alloc_size = 32;
288
289
ewah_clear(self);
ewah/ewah_io.c
+2
-8
@@ -134,12 +134,9 @@ int ewah_read_mmap(struct ewah_bitmap *self, const void *map, size_t len)
134
self->buffer_size = self->alloc_size = get_be32(ptr);
135
ptr += sizeof(uint32_t);
136
137
- self->buffer = ewah_realloc(self->buffer,
137
+ self->buffer = xrealloc(self->buffer,
138
self->alloc_size * sizeof(eword_t));
139
140
- if (!self->buffer)
141
- return -1;
142
-
140
/*
141
* Copy the raw data for the bitmap as a whole chunk;
142
* if we're in a little-endian platform, we'll perform
@@ -180,12 +177,9 @@ int ewah_deserialize(struct ewah_bitmap *self, int fd)
177
return -1;
178
179
self->buffer_size = self->alloc_size = (size_t)ntohl(word_count);
183
- self->buffer = ewah_realloc(self->buffer,
180
+ self->buffer = xrealloc(self->buffer,
181
self->alloc_size * sizeof(eword_t));
182
186
- if (!self->buffer)
187
- return -1;
188
-
183
/** 64 bit x N -- compressed words */
184
buffer = self->buffer;
185
words_left = self->buffer_size;
ewah/ewok.h
-10
@@ -20,16 +20,6 @@
20
#ifndef __EWOK_BITMAP_H__
21
#define __EWOK_BITMAP_H__
22
23
-#ifndef ewah_malloc
24
-# define ewah_malloc xmalloc
25
-#endif
26
-#ifndef ewah_realloc
27
-# define ewah_realloc xrealloc
28
-#endif
29
-#ifndef ewah_calloc
30
-# define ewah_calloc xcalloc
31
-#endif
32
-
23
struct strbuf;
24
typedef uint64_t eword_t;
25
#define BITS_IN_EWORD (sizeof(eword_t) * 8)