--- sage-4.8/spkg/build/sage-4.8/sage/ext/multi_modular.h.orig	2012-05-03 20:49:31.000000000 +0000
+++ sage-4.8/spkg/build/sage-4.8/sage/ext/multi_modular.h	2012-05-03 20:49:45.000000000 +0000
@@ -1,5 +1,5 @@
 /* #define mod_int size_t */
-#define mod_int size_t
+#define mod_int ssize_t
 
 /* This is the largest value we can do arithmetic on without risking overflowing. 
  * It will be optimized to a constant if any optimization is turned on. 
--- sage-4.8/spkg/build/sage-4.8/sage/libs/linbox/linbox.pxd.orig	2012-05-03 20:49:31.000000000 +0000
+++ sage-4.8/spkg/build/sage-4.8/sage/libs/linbox/linbox.pxd	2012-05-03 20:49:42.000000000 +0000
@@ -5,15 +5,15 @@ include '../../modules/vector_modn_spars
 from sage.matrix.matrix_integer_dense cimport mod_int
 
 cdef class Linbox_modn_dense:
-    cdef mod_int** matrix
+    cdef mod_int* matrix
     cdef mod_int n
     cdef size_t nrows, ncols
     
-    cdef set(self, mod_int n, mod_int** matrix, size_t nrows, size_t ncols)
+    cdef set(self, mod_int n, mod_int* matrix, size_t nrows, size_t ncols)
     cdef int echelonize(self)
     cdef matrix_matrix_multiply(self,
-                                mod_int **ans,
-                                mod_int **B,
+                                mod_int *ans,
+                                mod_int *B,
                                 size_t B_nr, size_t B_nc)
     cdef unsigned long rank(self) except -1
 
--- sage-4.8/spkg/build/sage-4.8/sage/libs/linbox/linbox.pyx.orig	2012-05-03 20:49:31.000000000 +0000
+++ sage-4.8/spkg/build/sage-4.8/sage/libs/linbox/linbox.pyx	2012-05-03 20:49:41.000000000 +0000
@@ -16,32 +16,31 @@ cdef extern from "linbox/linbox-sage.h":
     void linbox_modn_dense_delete_array(mod_int *f)
 
     int linbox_modn_dense_echelonize(unsigned long modulus,  
-                              mod_int **matrix, size_t nrows, size_t ncols)
-    void linbox_modn_dense_minpoly(unsigned long modulus, mod_int **mp, size_t* degree, size_t n,
-                                   mod_int **matrix, int do_minpoly)
-
-    int  linbox_modn_dense_matrix_matrix_multiply(unsigned long modulus, mod_int **ans,
-                                                  mod_int **A, mod_int **B,
-                                                  size_t A_nr, size_t A_nc,
-                                                  size_t B_nr, size_t B_nc)
+                              mod_int *matrix, size_t nrows, size_t ncols)
+    mod_int *linbox_modn_dense_minpoly(unsigned long modulus, mod_int **mp,
+                                      size_t* degree, size_t n, mod_int *matrix)
+    mod_int *linbox_modn_dense_charpoly(unsigned long modulus, mod_int **mp,
+                                        size_t n, mod_int *matrix)
+    mod_int *linbox_modn_dense_matrix_matrix_multiply(unsigned long modulus, mod_int *ans,
+                                                      mod_int *A, mod_int *B,
+                                                      size_t n, size_t n,
+                                                      size_t k)
 
     int linbox_modn_dense_rank(unsigned long modulus,  
-                               mod_int** matrix, size_t nrows, size_t ncols)
+                               mod_int* matrix, size_t nrows, size_t ncols)
 
-    mod_int linbox_modn_dense_det(mod_int modulus, mod_int** matrix, size_t nrows, size_t ncols)
+    mod_int linbox_modn_dense_det(mod_int modulus, mod_int* matrix, size_t nrows, size_t ncols)
 
 
 cdef class Linbox_modn_dense:
     def __init__(self):
-        self.matrix = <mod_int**> 0
+        self.matrix = <mod_int*> 0
 
     def __dealloc__(self):
         if self.matrix:
-            for i from 0 <= i < self.nrows:
-                sage_free(self.matrix[i])
             sage_free(self.matrix)
             
-    cdef set(self, mod_int n, mod_int** matrix,
+    cdef set(self, mod_int n, mod_int* matrix,
              size_t nrows, size_t ncols):
         self.n = n
         self.nrows = nrows
@@ -70,9 +69,12 @@ cdef class Linbox_modn_dense:
         """
         cdef mod_int *f
         cdef size_t degree
-        linbox_modn_dense_minpoly(self.n, &f, &degree,
-                                  self.nrows, self.matrix,
-                                  minpoly)
+        if minpoly:
+            linbox_modn_dense_minpoly(self.n, &f, &degree,
+                                      self.nrows, self.matrix)
+        else:
+            linbox_modn_dense_charpoly(self.n, &f,
+                                       self.nrows, self.matrix)
         v = []
         cdef Py_ssize_t i
         for i from 0 <= i <= degree:
@@ -81,17 +83,15 @@ cdef class Linbox_modn_dense:
         return v
         
     cdef matrix_matrix_multiply(self,
-                                mod_int **ans,
-                                mod_int **B,
+                                mod_int *ans,
+                                mod_int *B,
                                 size_t B_nr, size_t B_nc):
-        cdef int e
-        e = linbox_modn_dense_matrix_matrix_multiply(self.n, ans,
-                                                     self.matrix,  B,
-                                                     self.nrows, self.ncols,
-                                                     B_nr, B_nc)
-        if e:
+        if self.nrows != B_nc:
             raise RuntimeError, "error doing matrix matrix multiply modn using linbox"
-    
+        linbox_modn_dense_matrix_matrix_multiply(self.n, ans,
+                                                 self.matrix,  B,
+                                                 self.nrows, self.ncols,
+                                                 B_nr)
 
     cdef unsigned long rank(self) except -1:
         cdef unsigned long r
@@ -202,10 +202,7 @@ cdef class Linbox_integer_dense:
         cdef mpz_t* poly
         cdef size_t degree
         verbose("using linbox poly comp")
-        if do_minpoly:
-            linbox_integer_dense_minpoly(&poly, &degree, self.nrows, self.matrix)
-        else:
-            linbox_integer_dense_charpoly(&poly, &degree, self.nrows, self.matrix)
+        linbox_integer_dense_minpoly_hacked(&poly, &degree, self.nrows, self.matrix, do_minpoly)
         verbose("computed poly -- now converting back to Sage")
             
         v = []
--- sage-4.8/spkg/build/sage-4.8/sage/matrix/matrix_integer_dense.pyx.orig	2012-05-03 20:49:31.000000000 +0000
+++ sage-4.8/spkg/build/sage-4.8/sage/matrix/matrix_integer_dense.pyx	2012-05-03 20:49:43.000000000 +0000
@@ -1365,17 +1365,14 @@ cdef class Matrix_integer_dense(matrix_d
         """
         if n > 67108879:   # doesn't work for bigger primes -- experimental observation
             raise NotImplementedError("modulus to big")
-        cdef mod_int** matrix = <mod_int**>sage_malloc(sizeof(mod_int*) * self._nrows)
+        cdef mod_int* matrix = <mod_int*>sage_malloc(sizeof(mod_int) * self._nrows * self._ncols)
         if matrix == NULL:
             raise MemoryError("out of memory allocating multi-modular coefficient list")
         
         cdef Py_ssize_t i, j
         for i from 0 <= i < self._nrows:
-            matrix[i] = <mod_int *>sage_malloc(sizeof(mod_int) * self._ncols)
-            if matrix[i] == NULL:
-                raise MemoryError("out of memory allocating multi-modular coefficient list")
             for j from 0 <= j < self._ncols:
-                matrix[i][j] = mpz_fdiv_ui(self._matrix[i][j], n)
+                matrix[i * self._ncols + j] = mpz_fdiv_ui(self._matrix[i][j], n)
 
         cdef Linbox_modn_dense L = Linbox_modn_dense()
         L.set(n, matrix, self._nrows, self._ncols)
--- sage-4.8/spkg/build/sage-4.8/sage/matrix/matrix_modn_dense.pyx.orig	2012-05-03 20:49:31.000000000 +0000
+++ sage-4.8/spkg/build/sage-4.8/sage/matrix/matrix_modn_dense.pyx	2012-05-03 20:49:44.000000000 +0000
@@ -846,7 +846,7 @@ cdef class Matrix_modn_dense(matrix_dens
         B = right
         self._init_linbox()
         sig_on()
-        linbox.matrix_matrix_multiply(ans._matrix, B._matrix, B._nrows, B._ncols)
+        linbox.matrix_matrix_multiply(ans._entries, B._entries, B._nrows, B._ncols)
         sig_off()
         return ans
     
@@ -1094,7 +1094,7 @@ cdef class Matrix_modn_dense(matrix_dens
 
     cdef _init_linbox(self):
         sig_on()
-        linbox.set(self.p, self._matrix, self._nrows, self._ncols)
+        linbox.set(self.p, self._entries, self._nrows, self._ncols)
         sig_off()
 
     def _echelonize_linbox(self):
