# HG changeset patch # User Rik # Date 1400101184 25200 # Node ID 83c85d95ac7bae52c00433a63b7b8dd8270c8474 # Parent 6cd4d0af8547a2a3d6b52e26309fbbc30e27f9ec Fix assert() segfaults with profiler (bug #39587, bug #39586). * profiler.cc (profile_data_accumulator::tree_node::exit, profile_data_accumulator::exit_function, ): Comment out assert() statements which are not valid when profile is called from within a function. * profiler.cc (F__profiler_reset__, F__profiler_data__, F__profiler_enable__): Use correct function name in Texinfo docstring. * profiler.cc (F__profiler_data__): define retval(1) first to resize return vector just once. diff -r 6cd4d0af8547 -r 83c85d95ac7b libinterp/corefcn/profiler.cc --- a/libinterp/corefcn/profiler.cc Tue May 13 21:56:39 2014 -0700 +++ b/libinterp/corefcn/profiler.cc Wed May 14 13:59:44 2014 -0700 @@ -108,8 +108,10 @@ profile_data_accumulator::tree_node* profile_data_accumulator::tree_node::exit (octave_idx_type fcn) { - assert (parent); - assert (fcn_id == fcn); + // FIXME: These assert statements don't make sense if profile() is called + // from within a function hierarchy to begin with. See bug #39587. + // assert (parent); + // assert (fcn_id == fcn); return parent; } @@ -132,7 +134,7 @@ data[parent->fcn_id - 1].children.insert (fcn_id); } - if (!entry.recursive) + if (! entry.recursive) for (const tree_node* i = parent; i; i = i->parent) if (i->fcn_id == fcn_id) { @@ -211,7 +213,7 @@ if (value) { // Create a call-tree top-node if there isn't yet one. - if (!call_tree) + if (! call_tree) call_tree = new tree_node (0, 0); // Let the top-node be the active one. This ensures we have a clean @@ -253,13 +255,16 @@ active_fcn = active_fcn->enter (fcn_idx); last_time = query_time (); + } void profile_data_accumulator::exit_function (const std::string& fcn) { assert (call_tree); - assert (active_fcn != call_tree); + // FIXME: This assert statements doesn't make sense if profile() is called + // from within a function hierarchy to begin with. See bug #39587. + //assert (active_fcn != call_tree); // Usually, if we are disabled this function is not even called. But the // call disabling the profiler is an exception. So also check here @@ -268,7 +273,9 @@ add_current_time (); fcn_index_map::iterator pos = fcn_index.find (fcn); - assert (pos != fcn_index.end ()); + // FIXME: This assert statements doesn't make sense if profile() is called + // from within a function hierarchy to begin with. See bug #39587. + //assert (pos != fcn_index.end ()); active_fcn = active_fcn->exit (pos->second); // If this was an "inner call", we resume executing the parent function @@ -412,7 +419,7 @@ // Enable or disable the profiler data collection. DEFUN (__profiler_enable__, args, , "-*- texinfo -*-\n\ -@deftypefn {Function File} __profiler_enable ()\n\ +@deftypefn {Function File} __profiler_enable__ ()\n\ Undocumented internal function.\n\ @end deftypefn") { @@ -438,7 +445,7 @@ // Clear all collected profiling data. DEFUN (__profiler_reset__, args, , "-*- texinfo -*-\n\ -@deftypefn {Function File} __profiler_reset ()\n\ +@deftypefn {Function File} __profiler_reset__ ()\n\ Undocumented internal function.\n\ @end deftypefn") { @@ -456,7 +463,7 @@ // Query the timings collected by the profiler. DEFUN (__profiler_data__, args, nargout, "-*- texinfo -*-\n\ -@deftypefn {Function File} __profiler_data ()\n\ +@deftypefn {Function File} __profiler_data__ ()\n\ Undocumented internal function.\n\ @end deftypefn") { @@ -466,9 +473,10 @@ if (nargin > 0) warning ("profiler_data: ignoring extra arguments"); - retval(0) = profiler.get_flat (); if (nargout > 1) retval(1) = profiler.get_hierarchical (); + retval(0) = profiler.get_flat (); return retval; } +