* Handle out of memory condition.
This commit is contained in:
parent
8a788e38ac
commit
e11e6fb1c6
|
@ -259,8 +259,7 @@ void mkString(Value & v, const string & s, const PathSet & context)
|
|||
mkString(v, s.c_str());
|
||||
if (!context.empty()) {
|
||||
unsigned int n = 0;
|
||||
v.string.context = (const char * *)
|
||||
GC_MALLOC((context.size() + 1) * sizeof(char *));
|
||||
v.string.context = NEW const char *[context.size() + 1];
|
||||
foreach (PathSet::const_iterator, i, context)
|
||||
v.string.context[n++] = GC_STRDUP(i->c_str());
|
||||
v.string.context[n] = 0;
|
||||
|
@ -305,7 +304,7 @@ Value * EvalState::lookupVar(Env * env, const VarRef & var)
|
|||
Value * EvalState::allocValue()
|
||||
{
|
||||
nrValues++;
|
||||
return (Value *) GC_MALLOC(sizeof(Value));
|
||||
return NEW Value;
|
||||
}
|
||||
|
||||
|
||||
|
@ -314,6 +313,7 @@ Env & EvalState::allocEnv(unsigned int size)
|
|||
nrEnvs++;
|
||||
nrValuesInEnvs += size;
|
||||
Env * env = (Env *) GC_MALLOC(sizeof(Env) + size * sizeof(Value *));
|
||||
if (!env) throw std::bad_alloc();
|
||||
|
||||
/* Clear the values because maybeThunk() expects this. */
|
||||
for (unsigned i = 0; i < size; ++i)
|
||||
|
@ -335,7 +335,7 @@ void EvalState::mkList(Value & v, unsigned int length)
|
|||
{
|
||||
v.type = tList;
|
||||
v.list.length = length;
|
||||
v.list.elems = (Value * *) GC_MALLOC(length * sizeof(Value *));
|
||||
v.list.elems = NEW Value *[length];
|
||||
nrListElems += length;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ pkglib_LTLIBRARIES = libmain.la
|
|||
|
||||
libmain_la_SOURCES = shared.cc
|
||||
|
||||
libmain_la_LIBADD = ../libstore/libstore.la
|
||||
libmain_la_LIBADD = ../libstore/libstore.la @boehmgc_lib@
|
||||
|
||||
pkginclude_HEADERS = shared.hh
|
||||
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if HAVE_BOEHMGC
|
||||
#include <gc/gc.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
@ -314,6 +318,14 @@ static void setuidInit()
|
|||
}
|
||||
|
||||
|
||||
/* Called when the Boehm GC runs out of memory. */
|
||||
static void * oomHandler(size_t requested)
|
||||
{
|
||||
/* Convert this to a proper C++ exception. */
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -335,6 +347,14 @@ int main(int argc, char * * argv)
|
|||
|
||||
std::ios::sync_with_stdio(false);
|
||||
|
||||
#if HAVE_BOEHMGC
|
||||
/* Initialise the Boehm garbage collector. This isn't necessary
|
||||
on most platforms, but for portability we do it anyway. */
|
||||
GC_INIT();
|
||||
|
||||
GC_oom_fn = oomHandler;
|
||||
#endif
|
||||
|
||||
try {
|
||||
try {
|
||||
initAndRun(argc, argv);
|
||||
|
|
|
@ -4,8 +4,7 @@ nix_env_SOURCES = nix-env.cc profiles.cc profiles.hh user-env.cc user-env.hh hel
|
|||
|
||||
nix_env_LDADD = ../libmain/libmain.la ../libexpr/libexpr.la \
|
||||
../libstore/libstore.la ../libutil/libutil.la \
|
||||
../boost/format/libformat.la @ADDITIONAL_NETWORK_LIBS@ \
|
||||
@boehmgc_lib@
|
||||
../boost/format/libformat.la @ADDITIONAL_NETWORK_LIBS@
|
||||
|
||||
nix-env.o: help.txt.hh
|
||||
|
||||
|
|
|
@ -3,8 +3,7 @@ bin_PROGRAMS = nix-instantiate
|
|||
nix_instantiate_SOURCES = nix-instantiate.cc help.txt
|
||||
nix_instantiate_LDADD = ../libmain/libmain.la ../libexpr/libexpr.la \
|
||||
../libstore/libstore.la ../libutil/libutil.la \
|
||||
../boost/format/libformat.la @ADDITIONAL_NETWORK_LIBS@ \
|
||||
@boehmgc_lib@
|
||||
../boost/format/libformat.la @ADDITIONAL_NETWORK_LIBS@
|
||||
|
||||
nix-instantiate.o: help.txt.hh
|
||||
|
||||
|
|
Loading…
Reference in a new issue