gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot/lua-plot.cpp
diff options
context:
space:
mode:
authorfrancesco-ST <francesco.abbate@st.com>2010年12月01日 18:02:37 +0100
committerfrancesco-ST <francesco.abbate@st.com>2010年12月01日 18:02:37 +0100
commit9a2e6443e486a5b417c7e0bfbcfef15ac9e0b6d8 (patch)
tree1596af5d11196151403c4a02aadb623495e265f9 /agg-plot/lua-plot.cpp
parent812299dcac716252de50f92dc389f6c87da0880f (diff)
downloadgsl-shell-9a2e6443e486a5b417c7e0bfbcfef15ac9e0b6d8.tar.gz
better C++/lua error handling in agg-parse-trans.cpp and lua-plot.cpp
Design change: now C++ never call lua_error directly but can throw an exception or return a value that indicate a failure in operation. This kind of function should use also auto_ptr and stack-allocated (automatic) object instance to ensure the deallocation of memory and strong exception safety. The lua_error can be allocated only by C-style function that does not need proper stack unwinding (no auto-ptr neither automatic allocated object). The rationale is that lua_error use setjmp/longjmp that will bypass C++ stack unwinding.
Diffstat (limited to 'agg-plot/lua-plot.cpp')
-rw-r--r--agg-plot/lua-plot.cpp 25
1 files changed, 18 insertions, 7 deletions
diff --git a/agg-plot/lua-plot.cpp b/agg-plot/lua-plot.cpp
index 12971bb7..6f036514 100644
--- a/agg-plot/lua-plot.cpp
+++ b/agg-plot/lua-plot.cpp
@@ -154,18 +154,29 @@ plot_add_gener (lua_State *L, bool as_line)
lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT);
agg::rgba8 color;
- drawable *obj = parse_graph_args (L, color);
- object_refs_add (L, table_plot_obj, p->current_layer_index(), 1, 2);
+ try {
+ drawable *obj = parse_graph_args (L, color);
- AGG_LOCK();
+ object_refs_add (L, table_plot_obj, p->current_layer_index(), 1, 2);
- p->add(obj, color, as_line);
+ AGG_LOCK();
- AGG_UNLOCK();
+ p->add(obj, color, as_line);
- if (p->sync_mode())
- plot_flush (L);
+ AGG_UNLOCK();
+
+ if (p->sync_mode())
+ plot_flush (L);
+ }
+ catch (std::bad_alloc&)
+ {
+ return luaL_error (L, OUT_OF_MEMORY_MSG);
+ }
+ catch (agg_spec_error& e)
+ {
+ return luaL_error (L, e.message());
+ }
return 0;
}
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月12日 11:23:13 +0000

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