diff --git a/scipy/sparse/linalg/dsolve/SuperLU/SRC/cpanel_bmod.c b/scipy/sparse/linalg/dsolve/SuperLU/SRC/cpanel_bmod.c
index f8f859d..4a73091 100644
--- a/scipy/sparse/linalg/dsolve/SuperLU/SRC/cpanel_bmod.c
+++ b/scipy/sparse/linalg/dsolve/SuperLU/SRC/cpanel_bmod.c
@@ -425,6 +425,12 @@ cpanel_bmod (
 		    CTRSV( ftcs1, ftcs2, ftcs3, &segsze, &lusup[luptr], 
 			   &nsupr, tempv, &incx );
 #else
+#if SCIPY_FIX
+		    if (nsupr < segsze) {
+			/* Fail early rather than passing in invalid parameters to TRSV. */
+			ABORT("failed to factorize matrix");
+		    }
+#endif
 		    ctrsv_( "L", "N", "U", &segsze, &lusup[luptr], 
 			   &nsupr, tempv, &incx );
 #endif
diff --git a/scipy/sparse/linalg/dsolve/SuperLU/SRC/cpivotL.c b/scipy/sparse/linalg/dsolve/SuperLU/SRC/cpivotL.c
index a71d87a..41e5f8e 100644
--- a/scipy/sparse/linalg/dsolve/SuperLU/SRC/cpivotL.c
+++ b/scipy/sparse/linalg/dsolve/SuperLU/SRC/cpivotL.c
@@ -125,7 +125,16 @@ if ( jcol == MIN_COL ) {
     /* Test for singularity */
     if ( pivmax == 0.0 ) {
 #if 1
+#if SCIPY_FIX
+	if (pivptr < nsupr) {
+	    *pivrow = lsub_ptr[pivptr];
+	}
+	else {
+	    *pivrow = diagind;
+	}
+#else
 	*pivrow = lsub_ptr[pivptr];
+#endif
 	perm_r[*pivrow] = jcol;
 #else
 	perm_r[diagind] = jcol;
diff --git a/scipy/sparse/linalg/dsolve/SuperLU/SRC/csnode_bmod.c b/scipy/sparse/linalg/dsolve/SuperLU/SRC/csnode_bmod.c
index fa357c1..b2ea2f4 100644
--- a/scipy/sparse/linalg/dsolve/SuperLU/SRC/csnode_bmod.c
+++ b/scipy/sparse/linalg/dsolve/SuperLU/SRC/csnode_bmod.c
@@ -95,6 +95,12 @@ csnode_bmod (
 	CGEMV( ftcs2, &nrow, &nsupc, &alpha, &lusup[luptr+nsupc], &nsupr, 
 		&lusup[ufirst], &incx, &beta, &lusup[ufirst+nsupc], &incy );
 #else
+#if SCIPY_FIX
+       if (nsupr < nsupc) {
+           /* Fail early rather than passing in invalid parameters to TRSV. */
+           ABORT("failed to factorize matrix");
+       }
+#endif
 	ctrsv_( "L", "N", "U", &nsupc, &lusup[luptr], &nsupr, 
 	      &lusup[ufirst], &incx );
 	cgemv_( "N", &nrow, &nsupc, &alpha, &lusup[luptr+nsupc], &nsupr, 
diff --git a/scipy/sparse/linalg/dsolve/SuperLU/SRC/dpanel_bmod.c b/scipy/sparse/linalg/dsolve/SuperLU/SRC/dpanel_bmod.c
index 6f44b47..b1f868b 100644
--- a/scipy/sparse/linalg/dsolve/SuperLU/SRC/dpanel_bmod.c
+++ b/scipy/sparse/linalg/dsolve/SuperLU/SRC/dpanel_bmod.c
@@ -218,7 +218,7 @@ dpanel_bmod (
 		    STRSV( ftcs1, ftcs2, ftcs3, &segsze, &lusup[luptr], 
 			   &nsupr, TriTmp, &incx );
 #else
-		    dtrsv_( "L", "N", "U", &segsze, &lusup[luptr], 
+ 		    dtrsv_( "L", "N", "U", &segsze, &lusup[luptr], 
 			   &nsupr, TriTmp, &incx );
 #endif
 #else		
@@ -397,6 +397,12 @@ dpanel_bmod (
 		    STRSV( ftcs1, ftcs2, ftcs3, &segsze, &lusup[luptr], 
 			   &nsupr, tempv, &incx );
 #else
+#if SCIPY_FIX
+		    if (nsupr < segsze) {
+			/* Fail early rather than passing in invalid parameters to TRSV. */
+			ABORT("failed to factorize matrix");
+		    }
+#endif
 		    dtrsv_( "L", "N", "U", &segsze, &lusup[luptr], 
 			   &nsupr, tempv, &incx );
 #endif
diff --git a/scipy/sparse/linalg/dsolve/SuperLU/SRC/dpivotL.c b/scipy/sparse/linalg/dsolve/SuperLU/SRC/dpivotL.c
index b306b02..6b078e9 100644
--- a/scipy/sparse/linalg/dsolve/SuperLU/SRC/dpivotL.c
+++ b/scipy/sparse/linalg/dsolve/SuperLU/SRC/dpivotL.c
@@ -124,7 +124,16 @@ if ( jcol == MIN_COL ) {
     /* Test for singularity */
     if ( pivmax == 0.0 ) {
 #if 1
+#if SCIPY_FIX
+	if (pivptr < nsupr) {
+	    *pivrow = lsub_ptr[pivptr];
+	}
+	else {
+	    *pivrow = diagind;
+	}
+#else
 	*pivrow = lsub_ptr[pivptr];
+#endif
 	perm_r[*pivrow] = jcol;
 #else
 	perm_r[diagind] = jcol;
diff --git a/scipy/sparse/linalg/dsolve/SuperLU/SRC/dsnode_bmod.c b/scipy/sparse/linalg/dsolve/SuperLU/SRC/dsnode_bmod.c
index 1557675..f3116a9 100644
--- a/scipy/sparse/linalg/dsolve/SuperLU/SRC/dsnode_bmod.c
+++ b/scipy/sparse/linalg/dsolve/SuperLU/SRC/dsnode_bmod.c
@@ -94,6 +94,12 @@ dsnode_bmod (
 	SGEMV( ftcs2, &nrow, &nsupc, &alpha, &lusup[luptr+nsupc], &nsupr, 
 		&lusup[ufirst], &incx, &beta, &lusup[ufirst+nsupc], &incy );
 #else
+#if SCIPY_FIX
+	if (nsupr < nsupc) {
+	    /* Fail early rather than passing in invalid parameters to DTRSV. */
+	    ABORT("failed to factorize matrix");
+	}
+#endif
 	dtrsv_( "L", "N", "U", &nsupc, &lusup[luptr], &nsupr, 
 	      &lusup[ufirst], &incx );
 	dgemv_( "N", &nrow, &nsupc, &alpha, &lusup[luptr+nsupc], &nsupr, 
diff --git a/scipy/sparse/linalg/dsolve/SuperLU/SRC/ilu_cpivotL.c b/scipy/sparse/linalg/dsolve/SuperLU/SRC/ilu_cpivotL.c
index 4d1202c..e7efad9 100644
--- a/scipy/sparse/linalg/dsolve/SuperLU/SRC/ilu_cpivotL.c
+++ b/scipy/sparse/linalg/dsolve/SuperLU/SRC/ilu_cpivotL.c
@@ -136,9 +136,13 @@ ilu_cpivotL(
 
     /* Test for singularity */
     if (pivmax < 0.0) {
+#if SCIPY_FIX
+	ABORT("[0]: matrix is singular");
+#else
 	fprintf(stderr, "[0]: jcol=%d, SINGULAR!!!\n", jcol);
 	fflush(stderr);
 	exit(1);
+#endif
     }
     if ( pivmax == 0.0 ) {
 	if (diag != EMPTY)
@@ -151,9 +155,13 @@ ilu_cpivotL(
 	    for (icol = jcol; icol < n; icol++)
 		if (marker[swap[icol]] <= jcol) break;
 	    if (icol >= n) {
+#if SCIPY_FIX
+		ABORT("[1]: matrix is singular");
+#else
 		fprintf(stderr, "[1]: jcol=%d, SINGULAR!!!\n", jcol);
 		fflush(stderr);
 		exit(1);
+#endif
 	    }
 
 	    *pivrow = swap[icol];
diff --git a/scipy/sparse/linalg/dsolve/SuperLU/SRC/ilu_dpivotL.c b/scipy/sparse/linalg/dsolve/SuperLU/SRC/ilu_dpivotL.c
index 5edee72..410ec00 100644
--- a/scipy/sparse/linalg/dsolve/SuperLU/SRC/ilu_dpivotL.c
+++ b/scipy/sparse/linalg/dsolve/SuperLU/SRC/ilu_dpivotL.c
@@ -134,9 +134,13 @@ ilu_dpivotL(
 
     /* Test for singularity */
     if (pivmax < 0.0) {
+#if SCIPY_FIX
+	ABORT("[0]: matrix is singular");
+#else
 	fprintf(stderr, "[0]: jcol=%d, SINGULAR!!!\n", jcol);
 	fflush(stderr);
 	exit(1);
+#endif
     }
     if ( pivmax == 0.0 ) {
 	if (diag != EMPTY)
@@ -149,9 +153,13 @@ ilu_dpivotL(
 	    for (icol = jcol; icol < n; icol++)
 		if (marker[swap[icol]] <= jcol) break;
 	    if (icol >= n) {
+#if SCIPY_FIX
+		ABORT("[1]: matrix is singular");
+#else
 		fprintf(stderr, "[1]: jcol=%d, SINGULAR!!!\n", jcol);
 		fflush(stderr);
 		exit(1);
+#endif
 	    }
 
 	    *pivrow = swap[icol];
diff --git a/scipy/sparse/linalg/dsolve/SuperLU/SRC/ilu_spivotL.c b/scipy/sparse/linalg/dsolve/SuperLU/SRC/ilu_spivotL.c
index ad689f0..7cf038d 100644
--- a/scipy/sparse/linalg/dsolve/SuperLU/SRC/ilu_spivotL.c
+++ b/scipy/sparse/linalg/dsolve/SuperLU/SRC/ilu_spivotL.c
@@ -134,9 +134,13 @@ ilu_spivotL(
 
     /* Test for singularity */
     if (pivmax < 0.0) {
+#if SCIPY_FIX
+	ABORT("[0]: matrix is singular");
+#else
 	fprintf(stderr, "[0]: jcol=%d, SINGULAR!!!\n", jcol);
 	fflush(stderr);
 	exit(1);
+#endif
     }
     if ( pivmax == 0.0 ) {
 	if (diag != EMPTY)
@@ -149,9 +153,13 @@ ilu_spivotL(
 	    for (icol = jcol; icol < n; icol++)
 		if (marker[swap[icol]] <= jcol) break;
 	    if (icol >= n) {
+#if SCIPY_FIX
+		ABORT("[1]: matrix is singular");
+#else
 		fprintf(stderr, "[1]: jcol=%d, SINGULAR!!!\n", jcol);
 		fflush(stderr);
 		exit(1);
+#endif
 	    }
 
 	    *pivrow = swap[icol];
diff --git a/scipy/sparse/linalg/dsolve/SuperLU/SRC/ilu_zpivotL.c b/scipy/sparse/linalg/dsolve/SuperLU/SRC/ilu_zpivotL.c
index 9ed7c99..4a93280 100644
--- a/scipy/sparse/linalg/dsolve/SuperLU/SRC/ilu_zpivotL.c
+++ b/scipy/sparse/linalg/dsolve/SuperLU/SRC/ilu_zpivotL.c
@@ -136,9 +136,13 @@ ilu_zpivotL(
 
     /* Test for singularity */
     if (pivmax < 0.0) {
+#if SCIPY_FIX
+	ABORT("[0]: matrix is singular");
+#else
 	fprintf(stderr, "[0]: jcol=%d, SINGULAR!!!\n", jcol);
 	fflush(stderr);
 	exit(1);
+#endif
     }
     if ( pivmax == 0.0 ) {
 	if (diag != EMPTY)
@@ -151,9 +155,13 @@ ilu_zpivotL(
 	    for (icol = jcol; icol < n; icol++)
 		if (marker[swap[icol]] <= jcol) break;
 	    if (icol >= n) {
+#if SCIPY_FIX
+		ABORT("[1]: matrix is singular");
+#else
 		fprintf(stderr, "[1]: jcol=%d, SINGULAR!!!\n", jcol);
 		fflush(stderr);
 		exit(1);
+#endif
 	    }
 
 	    *pivrow = swap[icol];
diff --git a/scipy/sparse/linalg/dsolve/SuperLU/SRC/scipy_slu_config.h b/scipy/sparse/linalg/dsolve/SuperLU/SRC/scipy_slu_config.h
new file mode 100644
index 0000000..5afc93b
--- /dev/null
+++ b/scipy/sparse/linalg/dsolve/SuperLU/SRC/scipy_slu_config.h
@@ -0,0 +1,36 @@
+#ifndef SCIPY_SLU_CONFIG_H
+#define SCIPY_SLU_CONFIG_H
+
+#include <stdlib.h>
+
+/*
+ * Support routines
+ */
+void superlu_python_module_abort(char *msg);
+void *superlu_python_module_malloc(size_t size);
+void superlu_python_module_free(void *ptr);
+
+#define USER_ABORT  superlu_python_module_abort
+#define USER_MALLOC superlu_python_module_malloc
+#define USER_FREE   superlu_python_module_free
+
+#define SCIPY_FIX 1
+
+/*
+ * Fortran configuration
+ */
+#if defined(NO_APPEND_FORTRAN)
+#if defined(UPPERCASE_FORTRAN)
+#define UpCase 1
+#else
+#define NoChange 1
+#endif
+#else
+#if defined(UPPERCASE_FORTRAN)
+#error Uppercase and trailing slash in Fortran names not supported
+#else
+#define Add_ 1
+#endif
+#endif
+
+#endif
diff --git a/scipy/sparse/linalg/dsolve/SuperLU/SRC/slu_Cnames.h b/scipy/sparse/linalg/dsolve/SuperLU/SRC/slu_Cnames.h
index 9f42608..7e51638 100644
--- a/scipy/sparse/linalg/dsolve/SuperLU/SRC/slu_Cnames.h
+++ b/scipy/sparse/linalg/dsolve/SuperLU/SRC/slu_Cnames.h
@@ -19,6 +19,7 @@
 #ifndef __SUPERLU_CNAMES /* allow multiple inclusions */
 #define __SUPERLU_CNAMES
 
+#include "scipy_slu_config.h"
 
 #define ADD_       0
 #define ADD__      1
diff --git a/scipy/sparse/linalg/dsolve/SuperLU/SRC/slu_util.h b/scipy/sparse/linalg/dsolve/SuperLU/SRC/slu_util.h
index 4fa9537..d54c2cf 100644
--- a/scipy/sparse/linalg/dsolve/SuperLU/SRC/slu_util.h
+++ b/scipy/sparse/linalg/dsolve/SuperLU/SRC/slu_util.h
@@ -22,6 +22,8 @@
 #include <assert.h>
 #include "superlu_enum_consts.h"
 
+#include "scipy_slu_config.h"
+
 /***********************************************************************
  * Macros
  ***********************************************************************/
diff --git a/scipy/sparse/linalg/dsolve/SuperLU/SRC/spanel_bmod.c b/scipy/sparse/linalg/dsolve/SuperLU/SRC/spanel_bmod.c
index 847c569..dbec42d 100644
--- a/scipy/sparse/linalg/dsolve/SuperLU/SRC/spanel_bmod.c
+++ b/scipy/sparse/linalg/dsolve/SuperLU/SRC/spanel_bmod.c
@@ -397,6 +397,12 @@ spanel_bmod (
 		    STRSV( ftcs1, ftcs2, ftcs3, &segsze, &lusup[luptr], 
 			   &nsupr, tempv, &incx );
 #else
+#if SCIPY_FIX
+		    if (nsupr < segsze) {
+			/* Fail early rather than passing in invalid parameters to TRSV. */
+			ABORT("failed to factorize matrix");
+		    }
+#endif
 		    strsv_( "L", "N", "U", &segsze, &lusup[luptr], 
 			   &nsupr, tempv, &incx );
 #endif
diff --git a/scipy/sparse/linalg/dsolve/SuperLU/SRC/spivotL.c b/scipy/sparse/linalg/dsolve/SuperLU/SRC/spivotL.c
index 6bd8d74..0da781a 100644
--- a/scipy/sparse/linalg/dsolve/SuperLU/SRC/spivotL.c
+++ b/scipy/sparse/linalg/dsolve/SuperLU/SRC/spivotL.c
@@ -124,7 +124,16 @@ if ( jcol == MIN_COL ) {
     /* Test for singularity */
     if ( pivmax == 0.0 ) {
 #if 1
+#if SCIPY_FIX
+	if (pivptr < nsupr) {
+	    *pivrow = lsub_ptr[pivptr];
+	}
+	else {
+	    *pivrow = diagind;
+	}
+#else
 	*pivrow = lsub_ptr[pivptr];
+#endif
 	perm_r[*pivrow] = jcol;
 #else
 	perm_r[diagind] = jcol;
diff --git a/scipy/sparse/linalg/dsolve/SuperLU/SRC/ssnode_bmod.c b/scipy/sparse/linalg/dsolve/SuperLU/SRC/ssnode_bmod.c
index 153459c..9de8c0b 100644
--- a/scipy/sparse/linalg/dsolve/SuperLU/SRC/ssnode_bmod.c
+++ b/scipy/sparse/linalg/dsolve/SuperLU/SRC/ssnode_bmod.c
@@ -94,6 +94,12 @@ ssnode_bmod (
 	SGEMV( ftcs2, &nrow, &nsupc, &alpha, &lusup[luptr+nsupc], &nsupr, 
 		&lusup[ufirst], &incx, &beta, &lusup[ufirst+nsupc], &incy );
 #else
+#if SCIPY_FIX
+       if (nsupr < nsupc) {
+           /* Fail early rather than passing in invalid parameters to TRSV. */
+           ABORT("failed to factorize matrix");
+       }
+#endif
 	strsv_( "L", "N", "U", &nsupc, &lusup[luptr], &nsupr, 
 	      &lusup[ufirst], &incx );
 	sgemv_( "N", &nrow, &nsupc, &alpha, &lusup[luptr+nsupc], &nsupr, 
diff --git a/scipy/sparse/linalg/dsolve/SuperLU/SRC/zpanel_bmod.c b/scipy/sparse/linalg/dsolve/SuperLU/SRC/zpanel_bmod.c
index 7fcdb7c..d06ab07 100644
--- a/scipy/sparse/linalg/dsolve/SuperLU/SRC/zpanel_bmod.c
+++ b/scipy/sparse/linalg/dsolve/SuperLU/SRC/zpanel_bmod.c
@@ -425,6 +425,12 @@ zpanel_bmod (
 		    CTRSV( ftcs1, ftcs2, ftcs3, &segsze, &lusup[luptr], 
 			   &nsupr, tempv, &incx );
 #else
+#if SCIPY_FIX
+		    if (nsupr < segsze) {
+			/* Fail early rather than passing in invalid parameters to TRSV. */
+			ABORT("failed to factorize matrix");
+		    }
+#endif
 		    ztrsv_( "L", "N", "U", &segsze, &lusup[luptr], 
 			   &nsupr, tempv, &incx );
 #endif
diff --git a/scipy/sparse/linalg/dsolve/SuperLU/SRC/zpivotL.c b/scipy/sparse/linalg/dsolve/SuperLU/SRC/zpivotL.c
index e8996bc..a42aa3c 100644
--- a/scipy/sparse/linalg/dsolve/SuperLU/SRC/zpivotL.c
+++ b/scipy/sparse/linalg/dsolve/SuperLU/SRC/zpivotL.c
@@ -125,7 +125,16 @@ if ( jcol == MIN_COL ) {
     /* Test for singularity */
     if ( pivmax == 0.0 ) {
 #if 1
+#if SCIPY_FIX
+	if (pivptr < nsupr) {
+	    *pivrow = lsub_ptr[pivptr];
+	}
+	else {
+	    *pivrow = diagind;
+	}
+#else
 	*pivrow = lsub_ptr[pivptr];
+#endif
 	perm_r[*pivrow] = jcol;
 #else
 	perm_r[diagind] = jcol;
diff --git a/scipy/sparse/linalg/dsolve/SuperLU/SRC/zsnode_bmod.c b/scipy/sparse/linalg/dsolve/SuperLU/SRC/zsnode_bmod.c
index 0a107c9..17dc271 100644
--- a/scipy/sparse/linalg/dsolve/SuperLU/SRC/zsnode_bmod.c
+++ b/scipy/sparse/linalg/dsolve/SuperLU/SRC/zsnode_bmod.c
@@ -95,6 +95,12 @@ zsnode_bmod (
 	CGEMV( ftcs2, &nrow, &nsupc, &alpha, &lusup[luptr+nsupc], &nsupr, 
 		&lusup[ufirst], &incx, &beta, &lusup[ufirst+nsupc], &incy );
 #else
+#if SCIPY_FIX
+       if (nsupr < nsupc) {
+           /* Fail early rather than passing in invalid parameters to TRSV. */
+           ABORT("failed to factorize matrix");
+       }
+#endif
 	ztrsv_( "L", "N", "U", &nsupc, &lusup[luptr], &nsupr, 
 	      &lusup[ufirst], &incx );
 	zgemv_( "N", &nrow, &nsupc, &alpha, &lusup[luptr+nsupc], &nsupr, 
