Replace uses of alloca() with malloc()
Gets rid of more #ifdef magic.
This commit is contained in:
parent
41f6dbc1a2
commit
8a7ce61575
|
@ -11,9 +11,6 @@
|
||||||
#include "dtypes.h"
|
#include "dtypes.h"
|
||||||
#include "bitvector.h"
|
#include "bitvector.h"
|
||||||
|
|
||||||
// greater than this # of words we use malloc instead of alloca
|
|
||||||
#define MALLOC_CUTOFF 2000
|
|
||||||
|
|
||||||
#ifdef __INTEL_COMPILER
|
#ifdef __INTEL_COMPILER
|
||||||
#define count_bits(b) _popcnt32(b)
|
#define count_bits(b) _popcnt32(b)
|
||||||
#else
|
#else
|
||||||
|
@ -385,7 +382,7 @@ void bitvector_reverse(uint32_t *b, uint32_t offs, uint32_t nbits)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
nw = (offs + nbits + 31) >> 5;
|
nw = (offs + nbits + 31) >> 5;
|
||||||
temp = (nw > MALLOC_CUTOFF) ? malloc(nw * 4) : alloca(nw * 4);
|
temp = malloc(nw * 4);
|
||||||
for (i = 0; i < nw / 2; i++) {
|
for (i = 0; i < nw / 2; i++) {
|
||||||
temp[i] = bitreverse(b[nw - i - 1]);
|
temp[i] = bitreverse(b[nw - i - 1]);
|
||||||
temp[nw - i - 1] = bitreverse(b[i]);
|
temp[nw - i - 1] = bitreverse(b[i]);
|
||||||
|
@ -395,7 +392,6 @@ void bitvector_reverse(uint32_t *b, uint32_t offs, uint32_t nbits)
|
||||||
|
|
||||||
tail = (offs + nbits) & 31;
|
tail = (offs + nbits) & 31;
|
||||||
bitvector_copy(b, offs, temp, (32 - tail) & 31, nbits);
|
bitvector_copy(b, offs, temp, (32 - tail) & 31, nbits);
|
||||||
if (nw > MALLOC_CUTOFF)
|
|
||||||
free(temp);
|
free(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,8 +523,7 @@ static void adjust_offset_to(uint32_t *dest, uint32_t *src, uint32_t nw,
|
||||||
uint32_t boffs, uint32_t nbits) \
|
uint32_t boffs, uint32_t nbits) \
|
||||||
{ \
|
{ \
|
||||||
uint32_t nw = (doffs + nbits + 31) >> 5; \
|
uint32_t nw = (doffs + nbits + 31) >> 5; \
|
||||||
uint32_t *temp = \
|
uint32_t *temp = malloc((nw + 1) * 4); \
|
||||||
nw > MALLOC_CUTOFF ? malloc((nw + 1) * 4) : alloca((nw + 1) * 4); \
|
|
||||||
uint32_t i, anw, bnw; \
|
uint32_t i, anw, bnw; \
|
||||||
if (aoffs == boffs) { \
|
if (aoffs == boffs) { \
|
||||||
anw = (aoffs + nbits + 31) >> 5; \
|
anw = (aoffs + nbits + 31) >> 5; \
|
||||||
|
@ -548,7 +543,6 @@ static void adjust_offset_to(uint32_t *dest, uint32_t *src, uint32_t nw,
|
||||||
for (i = 0; i < anw; i++) \
|
for (i = 0; i < anw; i++) \
|
||||||
temp[i] = OP(a[i], b[i]); \
|
temp[i] = OP(a[i], b[i]); \
|
||||||
bitvector_copy(dest, doffs, temp, aoffs, nbits); \
|
bitvector_copy(dest, doffs, temp, aoffs, nbits); \
|
||||||
if (nw > MALLOC_CUTOFF) \
|
|
||||||
free(temp); \
|
free(temp); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
28
c/utf8.c
28
c/utf8.c
|
@ -23,17 +23,13 @@
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <wctype.h>
|
#include <wctype.h>
|
||||||
|
|
||||||
#include "dtypes.h"
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#define snprintf _snprintf
|
#define snprintf _snprintf
|
||||||
#else
|
|
||||||
#if !defined(__FreeBSD__) && !defined(__OpenBSD__)
|
|
||||||
#include <alloca.h>
|
|
||||||
#endif /* __FreeBSD__ && __OpenBSD__ */
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "dtypes.h"
|
||||||
|
|
||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
|
|
||||||
static const uint32_t offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL,
|
static const uint32_t offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL,
|
||||||
|
@ -618,25 +614,25 @@ int u8_is_locale_utf8(const char *locale)
|
||||||
|
|
||||||
size_t u8_vprintf(const char *fmt, va_list ap)
|
size_t u8_vprintf(const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
size_t cnt, sz = 0, nc, needfree = 0;
|
size_t nc;
|
||||||
char *buf;
|
char *buf;
|
||||||
uint32_t *wcs;
|
uint32_t *wcs;
|
||||||
|
int cnt;
|
||||||
|
|
||||||
sz = 512;
|
if ((cnt = vsnprintf(0, 0, fmt, ap)) < 0) {
|
||||||
buf = (char *)alloca(sz);
|
|
||||||
cnt = vsnprintf(buf, sz, fmt, ap);
|
|
||||||
if ((ssize_t)cnt < 0)
|
|
||||||
return 0;
|
return 0;
|
||||||
if (cnt >= sz) {
|
}
|
||||||
buf = (char *)malloc(cnt + 1);
|
if (!(buf = calloc(cnt + 1, 1))) {
|
||||||
needfree = 1;
|
|
||||||
vsnprintf(buf, cnt + 1, fmt, ap);
|
vsnprintf(buf, cnt + 1, fmt, ap);
|
||||||
}
|
}
|
||||||
wcs = (uint32_t *)alloca((cnt + 1) * sizeof(uint32_t));
|
if (!(wcs = calloc(cnt + 1, sizeof(uint32_t)))) {
|
||||||
|
free(buf);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
nc = u8_toucs(wcs, cnt + 1, buf, cnt);
|
nc = u8_toucs(wcs, cnt + 1, buf, cnt);
|
||||||
wcs[nc] = 0;
|
wcs[nc] = 0;
|
||||||
printf("%ls", (wchar_t *)wcs);
|
printf("%ls", (wchar_t *)wcs);
|
||||||
if (needfree)
|
free(wcs);
|
||||||
free(buf);
|
free(buf);
|
||||||
return nc;
|
return nc;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue