diff options
author | Paul Baltescu <pauldb89@gmail.com> | 2013-02-21 14:13:55 +0000 |
---|---|---|
committer | Paul Baltescu <pauldb89@gmail.com> | 2013-02-21 14:13:55 +0000 |
commit | b5491898549c61bd799d199aa9178a8394a1ef69 (patch) | |
tree | fb2686a2aae03ff07bcdf4cd47e8c3191eff8d1e /klm/util/scoped.hh | |
parent | 0187447a643c3ea262b13b3052cb1531990eafe6 (diff) | |
parent | c17d9c23d023a5c08656376944f636180f0a437b (diff) |
Merge branch 'master' of https://github.com/pauldb89/cdec
Diffstat (limited to 'klm/util/scoped.hh')
-rw-r--r-- | klm/util/scoped.hh | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/klm/util/scoped.hh b/klm/util/scoped.hh index d62c6df1..d0a5aabd 100644 --- a/klm/util/scoped.hh +++ b/klm/util/scoped.hh @@ -4,28 +4,31 @@ #include "util/exception.hh" #include <cstddef> -#include <cstdlib> namespace util { +class MallocException : public ErrnoException { + public: + explicit MallocException(std::size_t requested) throw(); + ~MallocException() throw(); +}; + +void *MallocOrThrow(std::size_t requested); + class scoped_malloc { public: scoped_malloc() : p_(NULL) {} scoped_malloc(void *p) : p_(p) {} - ~scoped_malloc() { std::free(p_); } + ~scoped_malloc(); void reset(void *p = NULL) { scoped_malloc other(p_); p_ = p; } - void call_realloc(std::size_t to) { - void *ret; - UTIL_THROW_IF(!(ret = std::realloc(p_, to)) && to, util::ErrnoException, "realloc to " << to << " bytes failed."); - p_ = ret; - } + void call_realloc(std::size_t to); void *get() { return p_; } const void *get() const { return p_; } |