--- linbox-1.2.2/interfaces/sage/linbox-sage.C.orig	2012-05-03 20:38:53.000000000 +0000
+++ linbox-1.2.2/interfaces/sage/linbox-sage.C	2012-05-03 20:38:57.000000000 +0000
@@ -71,10 +71,19 @@ using namespace LinBox;
    most don't build.  This combination below does though.
    */
 
-void linbox_modn_dense_delete_array_double(double * f) {delete[] f;
+template <class Element>
+void linbox_modn_dense_delete_array (Element* f)
+{
+    delete[] f;
+}
+void linbox_modn_dense_delete_array_double(double * f) {
+	return linbox_modn_dense_delete_array<double>(f);
 }
-void linbox_modn_dense_delete_array_float(float * f) {delete[] f;
+void linbox_modn_dense_delete_array_float(float * f) {
+	return linbox_modn_dense_delete_array<float>(f);
 }
+template void
+linbox_modn_dense_delete_array<long>(long*);
 
 template <class Element>
 unsigned long int linbox_modn_dense_echelonize (Element modulus, Element* matrix,
@@ -110,6 +119,9 @@ EXTERN unsigned long int linbox_modn_den
 	return (unsigned long) linbox_modn_dense_echelonize<float>(modulus,matrix,nrows,ncols);
 }
 
+template unsigned long int
+linbox_modn_dense_echelonize<long>(long, long*, size_t, size_t);
+
 template<class Element>
 unsigned long int linbox_modn_dense_rank (Element modulus,  Element* matrix, size_t nrows, size_t ncols)
 {
@@ -133,6 +145,8 @@ EXTERN unsigned long int linbox_modn_den
 {
 	return linbox_modn_dense_rank<float>(modulus,matrix,nrows,ncols);
 }
+template unsigned long int
+linbox_modn_dense_rank<long>(long, long*, size_t, size_t);
 
 template<class Element>
 Element linbox_modn_dense_det(Element modulus,Element*matrix,size_t nrows,size_t ncols)
@@ -156,6 +170,8 @@ EXTERN float linbox_modn_dense_det_float
 {
 	return linbox_modn_dense_det<float>(modulus,matrix,nrows,ncols);
 }
+template long
+linbox_modn_dense_det<long>(long, long*, size_t, size_t);
 
 template<class Element>
 Element* linbox_modn_dense_minpoly (Element modulus, Element ** mp, size_t* degree,
@@ -189,7 +205,8 @@ EXTERN float* linbox_modn_dense_minpoly_
 {
 	return linbox_modn_dense_minpoly<float> (modulus, mp, degree, n, matrix);
 }
-
+template long*
+linbox_modn_dense_minpoly<long>(long, long**, size_t*, size_t, long*);
 
 template<class Polynomial, class Field>
 Polynomial & mulpoly(const Field& F, Polynomial &res, const Polynomial & P1, const Polynomial & P2)
@@ -207,7 +224,7 @@ Polynomial & mulpoly(const Field& F, Pol
 }
 
 template<class Element>
-Element* linbox_modn_dense_charpoly (Element modulus, Element *& cp, size_t n, Element *matrix)
+Element* linbox_modn_dense_charpoly (Element modulus, Element ** cp, size_t n, Element *matrix)
 {
 
 	Modular<Element> F(modulus);
@@ -231,18 +248,20 @@ Element* linbox_modn_dense_charpoly (Ele
 		//	delete &(*it);
 		++it;
 	}
-	return cp = &(*tmp)[0];
+	return *cp = &(*tmp)[0];
 
 }
 
 EXTERN double* linbox_modn_dense_charpoly_double (double modulus, double ** cp, size_t n, double * matrix)
 {
-	return linbox_modn_dense_charpoly<double>(modulus,*cp,n,matrix);
+	return linbox_modn_dense_charpoly<double>(modulus,cp,n,matrix);
 }
 EXTERN float* linbox_modn_dense_charpoly_float (float modulus, float ** cp, size_t n, float * matrix)
 {
-	return linbox_modn_dense_charpoly<float>(modulus,*cp,n,matrix);
+	return linbox_modn_dense_charpoly<float>(modulus,cp,n,matrix);
 }
+template long*
+linbox_modn_dense_charpoly<long>(long, long**, size_t, long*);
 
 template<class Element>
 unsigned long linbox_modn_dense_col_rankprofile_submatrix_indices (Element modulus,
@@ -322,6 +341,9 @@ EXTERN float* linbox_modn_dense_matrix_m
 {
 	return linbox_modn_dense_matrix_matrix_multiply<float>(modulus,ans,A,B,m,n,k);
 }
+template long*
+linbox_modn_dense_matrix_matrix_multiply<long>(long, long*, long*, long*,
+					       size_t, size_t, size_t);
 
 template<class Element>
 Element *  linbox_modn_dense_matrix_matrix_general_multiply(Element modulus,
--- linbox-1.2.2/interfaces/sage/linbox-sage.h.orig	2012-05-03 20:38:52.000000000 +0000
+++ linbox-1.2.2/interfaces/sage/linbox-sage.h	2012-05-03 20:39:02.000000000 +0000
@@ -45,13 +45,19 @@
 
 // Element could be either double or float
 
+template <class Element>
+void linbox_modn_dense_delete_array (Element* f);
 EXTERN void linbox_modn_dense_delete_array_double (double *f);
 EXTERN void linbox_modn_dense_delete_array_float (float *f);
 
-
+template <class Element>
+unsigned long int linbox_modn_dense_echelonize (Element modulus, Element* matrix,
+						size_t nrows, size_t ncols);
 EXTERN unsigned long int linbox_modn_dense_echelonize_double (double modulus, double*matrix, size_t nrows, size_t ncols);
 EXTERN unsigned long int linbox_modn_dense_echelonize_float (float modulus, float * matrix,size_t nrows, size_t ncols);
 
+template<class Element>
+unsigned long int linbox_modn_dense_rank (Element modulus,  Element* matrix, size_t nrows, size_t ncols);
 EXTERN unsigned long int linbox_modn_dense_rank_double (double modulus, double* matrix, size_t nrows, size_t ncols);
 EXTERN unsigned long int linbox_modn_dense_rank_float (float modulus, float* matrix, size_t nrows, size_t ncols);
 
@@ -68,7 +74,7 @@ EXTERN float* linbox_modn_dense_minpoly_
 
 
 template <class Element>
-Element* linbox_modn_dense_charpoly (Element modulus, Element *& cp, size_t n, Element * matrix);
+Element* linbox_modn_dense_charpoly (Element modulus, Element ** cp, size_t n, Element * matrix);
 EXTERN double* linbox_modn_dense_charpoly_double (double modulus, double ** cp, size_t n, double * matrix);
 EXTERN float* linbox_modn_dense_charpoly_float (float modulus, float ** cp, size_t n, float * matrix);
 
@@ -104,6 +110,8 @@ EXTERN unsigned long linbox_modn_dense_c
 
 /* linbox_minpoly allocates space for minpoly, so you have to call linbox_delete_array
    to free it up afterwards. */
+EXTERN void linbox_integer_dense_minpoly_hacked(mpz_t** minpoly, size_t* degree,
+                  size_t n, mpz_t** matrix, int do_minpoly);
 
 void linbox_integer_dense_minpoly (mpz_t*& minpoly, size_t& degree, size_t n, mpz_t** matrix);
 
@@ -112,7 +120,8 @@ void linbox_integer_dense_charpoly (mpz_
 void linbox_integer_dense_delete_array (mpz_t* f);
 
 /* ans must be a pre-allocated and pre-initialized array of GMP ints. */
-int linbox_integer_dense_matrix_matrix_multiply (mpz_t** ans, mpz_t **A, mpz_t **B, size_t m, size_t n, size_t k);
+int linbox_integer_dense_matrix_matrix_multiply (mpz_t** ans, mpz_t **A, mpz_t **B,
+						 size_t A_nr, size_t A_nc, size_t B_nr, size_t B_nc);
 
 unsigned long linbox_integer_dense_rank(mpz_t** matrix, size_t nrows, size_t ncols);
 
--- linbox-1.2.2/linbox/field/Modular/modular-int64.h.orig	2012-05-03 20:38:48.000000000 +0000
+++ linbox-1.2.2/linbox/field/Modular/modular-int64.h	2012-05-03 20:39:07.000000000 +0000
@@ -90,7 +90,7 @@ namespace LinBox
 	 */
 	template <>
 	class Modular<int64_t> : public FieldInterface,
-	      public FFPACK::Modular<int64_t>	{
+	      public ::FFPACK::Modular<int64_t>	{
 
 	public:
 		typedef int64_t Element;
@@ -100,6 +100,24 @@ namespace LinBox
 		friend class MVProductDomain<Modular<int64_t> >;
 
 		typedef ModularRandIter<int64_t> RandIter;
+		typedef NonzeroRandIter<Modular<int64_t>, ModularRandIter<int64_t> > NonZeroRandIter;
+
+		Modular (integer &p) :
+			FFPACK::Modular<int64_t>((unsigned long)p)
+		{}
+
+	       	Modular (int64_t value, int64_t exp=1) :
+			FFPACK::Modular<int64_t>(value,exp)
+		      {}
+#if (FFLAFLAS_VERSIONW>10400)
+		Modular (long value) :
+			FFPACK::Modular<int64_t>(value)
+		      {}
+#endif
+
+		Modular (unsigned long value) :
+			FFPACK::Modular<int64_t>(value)
+		      {}
 
 		inline integer &cardinality (integer &c) const
 		{
@@ -116,6 +134,9 @@ namespace LinBox
 			return modulus;
 		}
 
+		 template<class T>T&convert(T&x,const Element&y)const{return x=T(y);}
+		 template<class T>T&characteristic(T&x)const{return x=T(lmodulus);}
+
 		inline integer &convert (integer &x, const Element &y) const
 		{
 			return x = y;
