forked from lix-project/lix
libexpr: Rely on Boehm returning zeroed memory in EvalState::allocEnv()
Boehm guarantees that memory returned by GC_malloc() is zeroed, so take advantage of that.
This commit is contained in:
parent
b8bed7da14
commit
0845cdf944
|
@ -7,13 +7,14 @@
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
||||||
|
/* Note: Various places expect the allocated memory to be zeroed. */
|
||||||
static void * allocBytes(size_t n)
|
static void * allocBytes(size_t n)
|
||||||
{
|
{
|
||||||
void * p;
|
void * p;
|
||||||
#if HAVE_BOEHMGC
|
#if HAVE_BOEHMGC
|
||||||
p = GC_malloc(n);
|
p = GC_malloc(n);
|
||||||
#else
|
#else
|
||||||
p = malloc(n);
|
p = calloc(n, 1);
|
||||||
#endif
|
#endif
|
||||||
if (!p) throw std::bad_alloc();
|
if (!p) throw std::bad_alloc();
|
||||||
return p;
|
return p;
|
||||||
|
|
|
@ -43,13 +43,14 @@ static char * dupString(const char * s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Note: Various places expect the allocated memory to be zeroed. */
|
||||||
static void * allocBytes(size_t n)
|
static void * allocBytes(size_t n)
|
||||||
{
|
{
|
||||||
void * p;
|
void * p;
|
||||||
#if HAVE_BOEHMGC
|
#if HAVE_BOEHMGC
|
||||||
p = GC_malloc(n);
|
p = GC_malloc(n);
|
||||||
#else
|
#else
|
||||||
p = malloc(n);
|
p = calloc(n, 1);
|
||||||
#endif
|
#endif
|
||||||
if (!p) throw std::bad_alloc();
|
if (!p) throw std::bad_alloc();
|
||||||
return p;
|
return p;
|
||||||
|
@ -582,9 +583,7 @@ Env & EvalState::allocEnv(unsigned int size)
|
||||||
Env * env = (Env *) allocBytes(sizeof(Env) + size * sizeof(Value *));
|
Env * env = (Env *) allocBytes(sizeof(Env) + size * sizeof(Value *));
|
||||||
env->size = size;
|
env->size = size;
|
||||||
|
|
||||||
/* Clear the values because maybeThunk() and lookupVar fromWith expect this. */
|
/* We assume that env->values has been cleared by the allocator; maybeThunk() and lookupVar fromWith expect this. */
|
||||||
for (unsigned i = 0; i < size; ++i)
|
|
||||||
env->values[i] = 0;
|
|
||||||
|
|
||||||
return *env;
|
return *env;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue