summaryrefslogtreecommitdiff
path: root/ewah
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-03-10 19:13:43 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-03-10 19:13:43 (GMT)
commitb7a6ec609ff10652541e7f716fcecf7865b94b23 (patch)
tree92c449ecb681311c3713a1d2be178776b05bd259 /ewah
parentaa6c22ec43fa9e2ac531360b5f274446e27d8be1 (diff)
parent8d5b3325e72444d365ded113487d2345c365f6d3 (diff)
downloadgit-b7a6ec609ff10652541e7f716fcecf7865b94b23.zip
git-b7a6ec609ff10652541e7f716fcecf7865b94b23.tar.gz
git-b7a6ec609ff10652541e7f716fcecf7865b94b23.tar.bz2
Merge branch 'jk/tighten-alloc' into maint
* jk/tighten-alloc: (23 commits) compat/mingw: brown paper bag fix for 50a6c8e ewah: convert to REALLOC_ARRAY, etc convert ewah/bitmap code to use xmalloc diff_populate_gitlink: use a strbuf transport_anonymize_url: use xstrfmt git-compat-util: drop mempcpy compat code sequencer: simplify memory allocation of get_message test-path-utils: fix normalize_path_copy output buffer size fetch-pack: simplify add_sought_entry fast-import: simplify allocation in start_packfile write_untracked_extension: use FLEX_ALLOC helper prepare_{git,shell}_cmd: use argv_array use st_add and st_mult for allocation size computation convert trivial cases to FLEX_ARRAY macros use xmallocz to avoid size arithmetic convert trivial cases to ALLOC_ARRAY convert manual allocations to argv_array argv-array: add detach function add helpers for allocating flex-array structs harden REALLOC_ARRAY and xcalloc against size_t overflow ...
Diffstat (limited to 'ewah')
-rw-r--r--ewah/bitmap.c20
-rw-r--r--ewah/ewah_bitmap.c10
-rw-r--r--ewah/ewah_io.c12
-rw-r--r--ewah/ewok.h10
4 files changed, 11 insertions, 41 deletions
diff --git a/ewah/bitmap.c b/ewah/bitmap.c
index 47ad674..7103cee 100644
--- a/ewah/bitmap.c
+++ b/ewah/bitmap.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "git-compat-util.h"
+#include "cache.h"
#include "ewok.h"
#define EWAH_MASK(x) ((eword_t)1 << (x % BITS_IN_EWORD))
@@ -25,8 +25,8 @@
struct bitmap *bitmap_new(void)
{
- struct bitmap *bitmap = ewah_malloc(sizeof(struct bitmap));
- bitmap->words = ewah_calloc(32, sizeof(eword_t));
+ struct bitmap *bitmap = xmalloc(sizeof(struct bitmap));
+ bitmap->words = xcalloc(32, sizeof(eword_t));
bitmap->word_alloc = 32;
return bitmap;
}
@@ -38,9 +38,7 @@ void bitmap_set(struct bitmap *self, size_t pos)
if (block >= self->word_alloc) {
size_t old_size = self->word_alloc;
self->word_alloc = block * 2;
- self->words = ewah_realloc(self->words,
- self->word_alloc * sizeof(eword_t));
-
+ REALLOC_ARRAY(self->words, self->word_alloc);
memset(self->words + old_size, 0x0,
(self->word_alloc - old_size) * sizeof(eword_t));
}
@@ -100,12 +98,7 @@ struct bitmap *ewah_to_bitmap(struct ewah_bitmap *ewah)
ewah_iterator_init(&it, ewah);
while (ewah_iterator_next(&blowup, &it)) {
- if (i >= bitmap->word_alloc) {
- bitmap->word_alloc *= 1.5;
- bitmap->words = ewah_realloc(
- bitmap->words, bitmap->word_alloc * sizeof(eword_t));
- }
-
+ ALLOC_GROW(bitmap->words, i + 1, bitmap->word_alloc);
bitmap->words[i++] = blowup;
}
@@ -134,8 +127,7 @@ void bitmap_or_ewah(struct bitmap *self, struct ewah_bitmap *other)
if (self->word_alloc < other_final) {
self->word_alloc = other_final;
- self->words = ewah_realloc(self->words,
- self->word_alloc * sizeof(eword_t));
+ REALLOC_ARRAY(self->words, self->word_alloc);
memset(self->words + original_size, 0x0,
(self->word_alloc - original_size) * sizeof(eword_t));
}
diff --git a/ewah/ewah_bitmap.c b/ewah/ewah_bitmap.c
index b522437..2dc9c82 100644
--- a/ewah/ewah_bitmap.c
+++ b/ewah/ewah_bitmap.c
@@ -39,8 +39,7 @@ static inline void buffer_grow(struct ewah_bitmap *self, size_t new_size)
return;
self->alloc_size = new_size;
- self->buffer = ewah_realloc(self->buffer,
- self->alloc_size * sizeof(eword_t));
+ REALLOC_ARRAY(self->buffer, self->alloc_size);
self->rlw = self->buffer + (rlw_offset / sizeof(eword_t));
}
@@ -282,12 +281,9 @@ struct ewah_bitmap *ewah_new(void)
{
struct ewah_bitmap *self;
- self = ewah_malloc(sizeof(struct ewah_bitmap));
- if (self == NULL)
- return NULL;
-
- self->buffer = ewah_malloc(32 * sizeof(eword_t));
+ self = xmalloc(sizeof(struct ewah_bitmap));
self->alloc_size = 32;
+ ALLOC_ARRAY(self->buffer, self->alloc_size);
ewah_clear(self);
return self;
diff --git a/ewah/ewah_io.c b/ewah/ewah_io.c
index 43481b9..61f6a43 100644
--- a/ewah/ewah_io.c
+++ b/ewah/ewah_io.c
@@ -134,11 +134,7 @@ int ewah_read_mmap(struct ewah_bitmap *self, const void *map, size_t len)
self->buffer_size = self->alloc_size = get_be32(ptr);
ptr += sizeof(uint32_t);
- self->buffer = ewah_realloc(self->buffer,
- self->alloc_size * sizeof(eword_t));
-
- if (!self->buffer)
- return -1;
+ REALLOC_ARRAY(self->buffer, self->alloc_size);
/*
* Copy the raw data for the bitmap as a whole chunk;
@@ -180,11 +176,7 @@ int ewah_deserialize(struct ewah_bitmap *self, int fd)
return -1;
self->buffer_size = self->alloc_size = (size_t)ntohl(word_count);
- self->buffer = ewah_realloc(self->buffer,
- self->alloc_size * sizeof(eword_t));
-
- if (!self->buffer)
- return -1;
+ REALLOC_ARRAY(self->buffer, self->alloc_size);
/** 64 bit x N -- compressed words */
buffer = self->buffer;
diff --git a/ewah/ewok.h b/ewah/ewok.h
index 6e2c5e1..269a1a8 100644
--- a/ewah/ewok.h
+++ b/ewah/ewok.h
@@ -20,16 +20,6 @@
#ifndef __EWOK_BITMAP_H__
#define __EWOK_BITMAP_H__
-#ifndef ewah_malloc
-# define ewah_malloc xmalloc
-#endif
-#ifndef ewah_realloc
-# define ewah_realloc xrealloc
-#endif
-#ifndef ewah_calloc
-# define ewah_calloc xcalloc
-#endif
-
struct strbuf;
typedef uint64_t eword_t;
#define BITS_IN_EWORD (sizeof(eword_t) * 8)