Solaris: bus error when sorting cell array

John W. Eaton jwe at bevo.che.wisc.edu
Mon Dec 3 17:06:48 CST 2007


On  2-Dec-2007, Moritz Borgmann wrote:

| so apparently, we enter the destructor with garbage in rep. I have
| no idea why.
| 
| To facilitate debugging, I replaced the member initialization list in 
| octave_value::octave_value by explicit assignments. Sure, this is not 
| the same, but it should work in principle.
| 
| So, in ov.cc, I turned
| 
| octave_value::octave_value (const ArrayN<octave_value>& a, bool is_csl)
|    : rep (is_csl
| 	 ? dynamic_cast<octave_base_value *> (new octave_cs_list (Cell (a)))
| 	 : dynamic_cast<octave_base_value *> (new octave_cell (Cell (a))))
| {
| }
| 
| into
| 
| octave_value::octave_value (const ArrayN<octave_value>& a, bool is_csl)
| {
|    Cell c(a);
|        
|    if(is_csl)
|    {
|      octave_cs_list* oc;
|     
|      oc = new octave_cs_list (c);
|      rep = dynamic_cast<octave_base_value *> (oc);
|    }
|    else
|    {
|      octave_cell* oc;
|     
|      oc = new octave_cell (c);
|      rep = dynamic_cast<octave_base_value *> (oc);  
|    }
| }

Instead of the change you suggest above, does the following patch also
work for you?

--- ov.cc	25 Oct 2007 01:49:18 -0400	1.158
+++ ov.cc	03 Dec 2007 18:02:51 -0500	
@@ -357,17 +357,22 @@
 {
 }
 
+static octave_base_value *
+foobar (bool is_csl)
+{
+  if (is_csl)
+    return new octave_cs_list (c);
+  else
+    return new octave_cell (c);
+}
+
 octave_value::octave_value (const Cell& c, bool is_csl)
-  : rep (is_csl
-	 ? dynamic_cast<octave_base_value *> (new octave_cs_list (c))
-	 : dynamic_cast<octave_base_value *> (new octave_cell (c)))
+  : rep (foobar (is_csl))
 {
 }
 
 octave_value::octave_value (const ArrayN<octave_value>& a, bool is_csl)
-  : rep (is_csl
-	 ? dynamic_cast<octave_base_value *> (new octave_cs_list (Cell (a)))
-	 : dynamic_cast<octave_base_value *> (new octave_cell (Cell (a))))
+  : rep (foobar (is_csl))
 {
 }
 

Or, instead of that, what about this patch?

--- ov.cc	25 Oct 2007 01:49:18 -0400	1.158
+++ ov.cc	03 Dec 2007 18:04:52 -0500	
@@ -357,17 +357,21 @@
 {
 }
 
+static octave_base_value *
+foobar (bool is_csl)
+{
+  return (is_csl
+	  ? dynamic_cast<octave_base_value *> (new octave_cs_list (c))
+	  : dynamic_cast<octave_base_value *> (new new octave_cell (c)));
+}
+
 octave_value::octave_value (const Cell& c, bool is_csl)
-  : rep (is_csl
-	 ? dynamic_cast<octave_base_value *> (new octave_cs_list (c))
-	 : dynamic_cast<octave_base_value *> (new octave_cell (c)))
+  : rep (foobar (is_csl))
 {
 }
 
 octave_value::octave_value (const ArrayN<octave_value>& a, bool is_csl)
-  : rep (is_csl
-	 ? dynamic_cast<octave_base_value *> (new octave_cs_list (Cell (a)))
-	 : dynamic_cast<octave_base_value *> (new octave_cell (Cell (a))))
+  : rep (foobar (is_csl))
 {
 }
 

Shouldn't all of these be equivalent?  If not, then what part of the
standard says they aren't?  If they should be the same, then I'd guess
it is a compiler bug.

jwe


More information about the Bug-octave mailing list