Exemplo n.º 1
0
        /*
        ** This routine is the only routine in this file with external linkage.
        **
        ** Populate the low-level memory allocation function pointers in
        ** sqlite3GlobalConfig.m with pointers to the routines in this file.
        */
        static void sqlite3MemSetDefault()
        {
            sqlite3_mem_methods defaultMethods = new sqlite3_mem_methods(
                sqlite3MemMalloc,
                sqlite3MemFree,
                sqlite3MemRealloc,
                sqlite3MemSize,
                sqlite3MemRoundup,
                (dxMemInit)sqlite3MemInit,
                (dxMemShutdown)sqlite3MemShutdown,
                0
                );

            sqlite3_config(SQLITE_CONFIG_MALLOC, defaultMethods);
        }
Exemplo n.º 2
0
        /*
        ** This routine is the only routine in this file with external linkage.
        **
        ** Populate the low-level memory allocation function pointers in
        ** sqlite3GlobalConfig.m with pointers to the routines in this file.
        */
        private static void sqlite3MemSetDefault()
        {
            var defaultMethods = new sqlite3_mem_methods(
                sqlite3MemMalloc,
                sqlite3MemMallocInt,
                sqlite3MemMallocMem,
                sqlite3MemFree,
                sqlite3MemFreeInt,
                sqlite3MemFreeMem,
                sqlite3MemRealloc,
                sqlite3MemSize,
                sqlite3MemRoundup,
                sqlite3MemInit,
                sqlite3MemShutdown,
                0
                );

            sqlite3_config(SQLITE_CONFIG_MALLOC, defaultMethods);
        }
Exemplo n.º 3
0
 static sqlite3_mem_methods va_arg(object[] ap, sqlite3_mem_methods sysType)
 {
     return((sqlite3_mem_methods)ap[vaNEXT++]);
 }
Exemplo n.º 4
0
 static int sqlite3_config( int op, ref sqlite3_mem_methods ap )
 {      //  va_list ap;
   int rc = SQLITE_OK;
   switch ( op )
   {
     case SQLITE_CONFIG_GETMALLOC:
       {
         /* Retrieve the current malloc() implementation */
         //if ( sqlite3GlobalConfig.m.xMalloc == null ) sqlite3MemSetDefault();
         ap = sqlite3GlobalConfig.m;//va_arg(ap, sqlite3_mem_methods) =  sqlite3GlobalConfig.m;
         break;
       }
   }
   return rc;
 }
Exemplo n.º 5
0
 static int sqlite3_config( int op, sqlite3_mem_methods ap )
 {      //  va_list ap;
   int rc = SQLITE_OK;
   switch ( op )
   {
     case SQLITE_CONFIG_MALLOC:
       {
         /* Specify an alternative malloc implementation */
         sqlite3GlobalConfig.m = ap;// (sqlite3_mem_methods)va_arg( ap, "sqlite3_mem_methods" );
         break;
       }
   }
   return rc;
 }
Exemplo n.º 6
0
    /*
    ** Add or remove the fault-simulation layer using sqlite3_config(). If
    ** the argument is non-zero, the
    */
    static int faultsimInstall( int install )
    {
      sqlite3_mem_methods m = new sqlite3_mem_methods(
      (dxMalloc)faultsimMalloc,                 /* xMalloc */
      (dxMallocInt)faultsimMallocInt,           /* xMalloc */
      (dxMallocMem)faultsimMallocMem,           /* xMalloc */
      (dxFree)faultsimFree,                     /* xFree */
      (dxFreeInt)faultsimFreeInt,               /* xFree */
      (dxFreeMem)faultsimFreeMem,
      (dxRealloc)faultsimRealloc,               /* xRealloc */
      (dxSize)faultsimSize,                     /* xSize */
      (dxRoundup)faultsimRoundup,               /* xRoundup */
      (dxMemInit)faultsimInit,                  /* xInit */
      (dxMemShutdown)faultsimShutdown,          /* xShutdown */
      null                                      /* pAppData */
      );
      int rc;

      //install = ( install != 0 ? 1 : 0 );
      Debug.Assert( memfault.isInstalled == 1 || memfault.isInstalled == 0 );

      if ( install == memfault.isInstalled )
      {
        return SQLITE_ERROR;
      }

      if ( install != 0 )
      {
        rc = sqlite3_config( SQLITE_CONFIG_GETMALLOC, ref  memfault.m );
        Debug.Assert( memfault.m.xMalloc != null );
        if ( rc == SQLITE_OK )
        {
          rc = sqlite3_config( SQLITE_CONFIG_MALLOC, m );
        }
        sqlite3_test_control( SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,
        (void_function)faultsimBeginBenign, (void_function)faultsimEndBenign
        );
      }
      else
      {
        //sqlite3_mem_methods m;
        Debug.Assert( memfault.m.xMalloc != null );

        /* One should be able to reset the default memory allocator by storing
        ** a zeroed allocator then calling GETMALLOC. */
        m = new sqlite3_mem_methods();// memset( &m, 0, sizeof( m ) );
        sqlite3_config( SQLITE_CONFIG_MALLOC, m );
        sqlite3_config( SQLITE_CONFIG_GETMALLOC, ref m );
        Debug.Assert( m.GetHashCode() == memfault.m.GetHashCode() );//memcmp(&m, &memfault.m, sizeof(m))==0 );

        rc = sqlite3_config( SQLITE_CONFIG_MALLOC, ref memfault.m );
        sqlite3_test_control( SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS, 0, 0 );
      }

      if ( rc == SQLITE_OK )
      {
        memfault.isInstalled = 1;
      }
      return rc;
    }