Move the malloc() failure simulation out of malloc.c and into a separate sqlite3_mem_methods interface. Still some related changes to come. (CVS 5250)

FossilOrigin-Name: d22cd2a59f472f4eaf80aa9f55fbff2514ca428d
diff --git a/src/test_malloc.c b/src/test_malloc.c
index 4643f2e..59a2954 100644
--- a/src/test_malloc.c
+++ b/src/test_malloc.c
@@ -13,7 +13,7 @@
 ** This file contains code used to implement test interfaces to the
 ** memory allocation subsystem.
 **
-** $Id: test_malloc.c,v 1.25 2008/06/19 00:16:08 drh Exp $
+** $Id: test_malloc.c,v 1.26 2008/06/19 18:17:50 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "tcl.h"
@@ -21,6 +21,8 @@
 #include <string.h>
 #include <assert.h>
 
+const char *sqlite3TestErrorName(int);
+
 /*
 ** Transform pointers to text and back again
 */
@@ -781,6 +783,30 @@
 }
 
 /*
+** install_malloc_faultsim BOOLEAN
+*/
+static int test_install_malloc_faultsim(
+  void * clientData,
+  Tcl_Interp *interp,
+  int objc,
+  Tcl_Obj *CONST objv[]
+){
+  int rc;
+  int isInstall;
+
+  if( objc!=2 ){
+    Tcl_WrongNumArgs(interp, 1, objv, "BOOLEAN");
+    return TCL_ERROR;
+  }
+  if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[1], &isInstall) ){
+    return TCL_ERROR;
+  }
+  rc = sqlite3_test_control(SQLITE_TESTCTRL_FAULT_INSTALL, isInstall);
+  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
+  return TCL_OK;
+}
+
+/*
 ** Register commands with the TCL interpreter.
 */
 int Sqlitetest_malloc_Init(Tcl_Interp *interp){
@@ -805,6 +831,8 @@
      { "sqlite3_config_scratch",     test_config_scratch           },
      { "sqlite3_config_pagecache",   test_config_pagecache         },
      { "sqlite3_status",             test_status                   },
+
+     { "install_malloc_faultsim",    test_install_malloc_faultsim  },
   };
   int i;
   for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){