Mercurial > hg > octave-lyh
diff src/DLD-FUNCTIONS/rand.cc @ 10066:2cd940306a06
make unwind_protect frames local
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 06 Jan 2010 13:18:41 +0100 |
parents | 09da0bd91412 |
children | 40dfc0c99116 |
line wrap: on
line diff
--- a/src/DLD-FUNCTIONS/rand.cc +++ b/src/DLD-FUNCTIONS/rand.cc @@ -464,7 +464,7 @@ static std::string current_distribution = octave_rand::distribution (); static void -reset_rand_generator (void *) +reset_rand_generator (void) { octave_rand::distribution (current_distribution); } @@ -492,15 +492,15 @@ int nargin = args.length (); - unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); + unwind_protect frame; // This relies on the fact that elements are popped from the unwind // stack in the reverse of the order they are pushed // (i.e. current_distribution will be reset before calling // reset_rand_generator()). - unwind_protect::add (reset_rand_generator, 0); - unwind_protect::protect_var (current_distribution); + frame.add_fcn (reset_rand_generator); + frame.protect_var (current_distribution); current_distribution = "normal"; @@ -508,8 +508,6 @@ retval = do_rand (args, nargin, "randn"); - unwind_protect::run_frame (uwp_frame); - return retval; } @@ -565,15 +563,15 @@ int nargin = args.length (); - unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); + unwind_protect frame; // This relies on the fact that elements are popped from the unwind // stack in the reverse of the order they are pushed // (i.e. current_distribution will be reset before calling // reset_rand_generator()). - unwind_protect::add (reset_rand_generator, 0); - unwind_protect::protect_var (current_distribution); + frame.add_fcn (reset_rand_generator); + frame.protect_var (current_distribution); current_distribution = "exponential"; @@ -581,8 +579,6 @@ retval = do_rand (args, nargin, "rande"); - unwind_protect::run_frame (uwp_frame); - return retval; } @@ -697,23 +693,21 @@ error ("randg: insufficient arguments"); else { - unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); + unwind_protect frame; // This relies on the fact that elements are popped from the unwind // stack in the reverse of the order they are pushed // (i.e. current_distribution will be reset before calling // reset_rand_generator()). - unwind_protect::add (reset_rand_generator, 0); - unwind_protect::protect_var (current_distribution); + frame.add_fcn (reset_rand_generator); + frame.protect_var (current_distribution); current_distribution = "gamma"; octave_rand::distribution (current_distribution); retval = do_rand (args, nargin, "randg", true); - - unwind_protect::run_frame (uwp_frame); } return retval; @@ -911,23 +905,21 @@ error ("randp: insufficient arguments"); else { - unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); + unwind_protect frame; // This relies on the fact that elements are popped from the unwind // stack in the reverse of the order they are pushed // (i.e. current_distribution will be reset before calling // reset_rand_generator()). - unwind_protect::add (reset_rand_generator, 0); - unwind_protect::protect_var (current_distribution); + frame.add_fcn (reset_rand_generator); + frame.protect_var (current_distribution); current_distribution = "poisson"; octave_rand::distribution (current_distribution); retval = do_rand (args, nargin, "randp", true); - - unwind_protect::run_frame (uwp_frame); } return retval;