From ee563973094a8235631d5208bd672f8cbbe15fdc Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: 2011年12月18日 00:02:19 +0100 Subject: Eliminate C++ exceptions from graphical system implementation The rationale is that everything is simpler without C++ exceptions. No exceptions are raised in the C++ code and errors are handler in the tradition C fashion. lua_error is not directly called from C++ functions that may allocate a non POD object on the stack. If the C++ "new" operator raise an exception the program will abort. The idea is that handle such an improbable occurrence greatly complicates the code. Where big chunks of memory are allocated the nothrow variant of "new" is used, the returned pointer is verified and an error is raised if the allocation failed. In the Windows code the bitmap allocation for image may raise an unhandled exception in there is not enough memory. The memory allocation is done inside the AGG library so it difficult to change its behavior. --- agg-plot/lua-cpp-utils.h | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) (limited to 'agg-plot/lua-cpp-utils.h') diff --git a/agg-plot/lua-cpp-utils.h b/agg-plot/lua-cpp-utils.h index b2d506a5..7111aa5f 100644 --- a/agg-plot/lua-cpp-utils.h +++ b/agg-plot/lua-cpp-utils.h @@ -1,7 +1,6 @@ #ifndef LUA_CPP_UTILS_H #define LUA_CPP_UTILS_H -#include #include #include "defs.h" @@ -45,31 +44,13 @@ inline void* operator new(size_t nbytes, lua_State *L, enum gs_type_e tp) template T* push_new_object (lua_State *L, enum gs_type_e tp) { - try - { - return new(L, tp) T(); - } - catch (std::bad_alloc&) - { - luaL_error (L, "out of memory"); - } - - return 0; + return new(L, tp) T(); } template T* push_new_object (lua_State *L, enum gs_type_e tp, init_type& init) { - try - { - return new(L, tp) T(init); - } - catch (std::bad_alloc&) - { - luaL_error (L, "out of memory"); - } - - return 0; + return new(L, tp) T(init); } template -- cgit v1.2.3

AltStyle によって変換されたページ (->オリジナル) /