Author: eelco
Date: Thu Oct 28 12:29:40 2010
New Revision: 24512
URL: https://svn.nixos.org/websvn/nix/?rev=24512&sc=1
Log:
* Handle out of memory condition.
Modified:
nix/branches/gc/src/libexpr/eval.cc
nix/branches/gc/src/libmain/Makefile.am
nix/branches/gc/src/libmain/shared.cc
nix/branches/gc/src/nix-env/Makefile.am
nix/branches/gc/src/nix-instantiate/Makefile.am
Modified: nix/branches/gc/src/libexpr/eval.cc
==============================================================================
--- nix/branches/gc/src/libexpr/eval.cc Thu Oct 28 11:10:09 2010 (r24511)
+++ nix/branches/gc/src/libexpr/eval.cc Thu Oct 28 12:29:40 2010 (r24512)
@@ -259,9 +259,8 @@
mkString(v, s.c_str());
if (!context.empty()) {
unsigned int n = 0;
- v.string.context = (const char * *)
- GC_MALLOC((context.size() + 1) * sizeof(char *));
- foreach (PathSet::const_iterator, i, context)
+ 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::allocValue()
{
nrValues++;
- return (Value *) GC_MALLOC(sizeof(Value));
+ return NEW Value;
}
@@ -314,6 +313,7 @@
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 @@
{
v.type = tList;
v.list.length = length;
- v.list.elems = (Value * *) GC_MALLOC(length * sizeof(Value *));
+ v.list.elems = NEW Value *[length];
nrListElems += length;
}
Modified: nix/branches/gc/src/libmain/Makefile.am
==============================================================================
--- nix/branches/gc/src/libmain/Makefile.am Thu Oct 28 11:10:09 2010
(r24511)
+++ nix/branches/gc/src/libmain/Makefile.am Thu Oct 28 12:29:40 2010
(r24512)
@@ -2,7 +2,7 @@
libmain_la_SOURCES = shared.cc
-libmain_la_LIBADD = ../libstore/libstore.la
+libmain_la_LIBADD = ../libstore/libstore.la @boehmgc_lib@
pkginclude_HEADERS = shared.hh
Modified: nix/branches/gc/src/libmain/shared.cc
==============================================================================
--- nix/branches/gc/src/libmain/shared.cc Thu Oct 28 11:10:09 2010
(r24511)
+++ nix/branches/gc/src/libmain/shared.cc Thu Oct 28 12:29:40 2010
(r24512)
@@ -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 @@
}
+/* 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 @@
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);
Modified: nix/branches/gc/src/nix-env/Makefile.am
==============================================================================
--- nix/branches/gc/src/nix-env/Makefile.am Thu Oct 28 11:10:09 2010
(r24511)
+++ nix/branches/gc/src/nix-env/Makefile.am Thu Oct 28 12:29:40 2010
(r24512)
@@ -4,8 +4,7 @@
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
Modified: nix/branches/gc/src/nix-instantiate/Makefile.am
==============================================================================
--- nix/branches/gc/src/nix-instantiate/Makefile.am Thu Oct 28 11:10:09
2010 (r24511)
+++ nix/branches/gc/src/nix-instantiate/Makefile.am Thu Oct 28 12:29:40
2010 (r24512)
@@ -3,8 +3,7 @@
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
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits