changeset 10830:b4ebfd675321

avoid static initialization disaster in dim_vector
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 29 Jul 2010 08:47:26 +0200
parents 61cb53ae9db3
children 1646bd8e3735
files liboctave/ChangeLog liboctave/dim-vector.cc liboctave/dim-vector.h src/bitfcns.cc
diffstat 4 files changed, 14 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/ChangeLog	Thu Jul 29 08:28:24 2010 +0200
+++ b/liboctave/ChangeLog	Thu Jul 29 08:47:26 2010 +0200
@@ -1,3 +1,9 @@
+2010-07-29  Jaroslav Hajek  <highegg@gmail.com>
+
+	* dim-vector.cc (dim_vector::dim_max (void)): Turn it into a function.
+	(dim_vector::safe_numel): Update usage.
+	* dim-vector.h: Update declaration.
+
 2010-07-27  Jaroslav Hajek  <highegg@gmail.com>
 
 	* dbleSCHUR.cc (SCHUR::SCHUR (const Matrix&, const Matrix&)): 
--- a/liboctave/dim-vector.cc	Thu Jul 29 08:28:24 2010 +0200
+++ b/liboctave/dim-vector.cc	Thu Jul 29 08:47:26 2010 +0200
@@ -33,8 +33,11 @@
 // off the maximum value of octave_idx_type.
 // Currently 1 is subtracted to allow safe conversion of any 2D Array into Sparse,
 // but this offset may change in the future.
-const octave_idx_type
-dim_vector::dim_max = std::numeric_limits<octave_idx_type>::max () - 1;
+octave_idx_type
+dim_vector::dim_max (void)
+{
+  return std::numeric_limits<octave_idx_type>::max () - 1;
+}
 
 void
 dim_vector::chop_all_singletons (void)
@@ -89,7 +92,7 @@
 octave_idx_type
 dim_vector::safe_numel (void) const
 {
-  octave_idx_type idx_max = dim_max;
+  octave_idx_type idx_max = dim_max ();
   octave_idx_type n = 1;
   int n_dims = length ();
 
--- a/liboctave/dim-vector.h	Thu Jul 29 08:28:24 2010 +0200
+++ b/liboctave/dim-vector.h	Thu Jul 29 08:47:26 2010 +0200
@@ -219,7 +219,7 @@
 
 public:
 
-  static const octave_idx_type dim_max;
+  static octave_idx_type dim_max (void);
 
   explicit dim_vector (void) : rep (nil_rep ()) { count()++; }
 
--- a/src/bitfcns.cc	Thu Jul 29 08:28:24 2010 +0200
+++ b/src/bitfcns.cc	Thu Jul 29 08:47:26 2010 +0200
@@ -666,7 +666,7 @@
   octave_value retval;
 
   if (args.length () == 0)
-    retval = octave_int<octave_idx_type> (dim_vector::dim_max);
+    retval = octave_int<octave_idx_type> (dim_vector::dim_max ());
   else
     print_usage ();