System.Data.SQLite
Check-in [9e3b23cb78]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Update the Eagle core script library and test suite infrastructure to better support testing the native library pre-loading code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | refactorNativeLibraryPreLoader
Files: files | file ages | folders
SHA1: 9e3b23cb78270383fc64ca9c7a85fd60eab207b8
User & Date: mistachkin 2013-12-27 07:41:37
Context
2013-12-27
08:36
Adjustments to the native library pre-loading logic for the .NET Compact Framework. check-in: e90af0978f user: mistachkin tags: refactorNativeLibraryPreLoader
07:41
Update the Eagle core script library and test suite infrastructure to better support testing the native library pre-loading code. check-in: 9e3b23cb78 user: mistachkin tags: refactorNativeLibraryPreLoader
04:57
Merge updates from trunk. check-in: f2075b5036 user: mistachkin tags: refactorNativeLibraryPreLoader
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Externals/Eagle/lib/Eagle1.0/test.eagle.

  1952   1952   
  1953   1953     proc machineToPlatform { machine {architecture false} } {
  1954   1954       #
  1955   1955       # NOTE: Cannot use "-nocase" option here because Tcl 8.4 does not
  1956   1956       #       support it (i.e. because it is pre-TIP #241).
  1957   1957       #
  1958   1958       switch -exact -- [string tolower $machine] {
  1959         -      amd64 {
  1960         -        return x64
  1961         -      }
  1962   1959         intel {
  1963   1960           if {!$architecture && \
  1964   1961               [info exists ::tcl_platform(platform)] && \
  1965   1962               $::tcl_platform(platform) eq "windows"} then {
  1966   1963             return Win32
  1967   1964           } else {
  1968   1965             return x86
  1969   1966           }
  1970   1967         }
         1968  +      arm {
         1969  +        return arm
         1970  +      }
         1971  +      ia64 {
         1972  +        return itanium
         1973  +      }
         1974  +      msil {
         1975  +        return clr
         1976  +      }
         1977  +      amd64 {
         1978  +        return x64
         1979  +      }
         1980  +      ia32_on_win64 {
         1981  +        return wow64
         1982  +      }
         1983  +      default {
         1984  +        return unknown
         1985  +      }
         1986  +    }
         1987  +  }
         1988  +
         1989  +  proc architectureForPlatform { platform } {
         1990  +    #
         1991  +    # NOTE: Cannot use "-nocase" option here because Tcl 8.4 does not
         1992  +    #       support it (i.e. because it is pre-TIP #241).
         1993  +    #
         1994  +    switch -exact -- [string tolower $platform] {
         1995  +      intel -
         1996  +      win32 -
         1997  +      x86 {
         1998  +        return x86
         1999  +      }
         2000  +      arm {
         2001  +        return arm
         2002  +      }
         2003  +      ia64 -
         2004  +      itanium {
         2005  +        return ia64
         2006  +      }
         2007  +      msil -
         2008  +      clr {
         2009  +        return msil
         2010  +      }
         2011  +      amd64 -
         2012  +      x64 {
         2013  +        return x64
         2014  +      }
         2015  +      ia32_on_win64 -
         2016  +      wow64 {
         2017  +        return ia32_on_win64
         2018  +      }
  1971   2019         default {
  1972   2020           return unknown
  1973   2021         }
  1974   2022       }
  1975   2023     }
  1976   2024   
  1977   2025     if {[isEagle]} then {

Changes to Externals/Eagle/lib/Test1.0/prologue.eagle.

  1966   1966   
  1967   1967     #
  1968   1968     # NOTE: Has checking for the extra files needed by various tests been
  1969   1969     #       disabled?
  1970   1970     #
  1971   1971     if {![info exists no(checkForFile)]} then {
  1972   1972       #
  1973         -    # NOTE: For tests "benchmark-1.38" and "benchmark-1.39".
         1973  +    # NOTE: For tests "benchmark-1.3[89]" and "benchmark-1.40".
  1974   1974       #
  1975   1975       if {![info exists no(benchmark.txt)]} then {
  1976   1976         checkForFile $test_channel [file join $test_path benchmark.txt]
  1977   1977       }
  1978   1978   
  1979   1979       #
  1980   1980       # NOTE: For test "garuda-1.1".

Changes to System.Data.SQLite/UnsafeNativeMethods.cs.

   392    392         /// Stores the mappings between processor architecture names and platform
   393    393         /// names.
   394    394         /// </summary>
   395    395         private static Dictionary<string, string> processorArchitecturePlatforms;
   396    396   
   397    397         /////////////////////////////////////////////////////////////////////////
   398    398         /// <summary>
          399  +      /// The native module file name for the native SQLite library or null.
          400  +      /// </summary>
          401  +      private static string _SQLiteNativeModuleFileName = null;
          402  +
          403  +      /////////////////////////////////////////////////////////////////////////
          404  +      /// <summary>
   399    405         /// The native module handle for the native SQLite library or the value
   400    406         /// IntPtr.Zero.
   401    407         /// </summary>
   402         -      private static IntPtr _SQLiteModule = IntPtr.Zero;
          408  +      private static IntPtr _SQLiteNativeModuleHandle = IntPtr.Zero;
   403    409   
   404    410         /////////////////////////////////////////////////////////////////////////
   405    411         /// <summary>
   406    412         /// For now, this method simply calls the Initialize method.
   407    413         /// </summary>
   408    414         static UnsafeNativeMethods()
   409    415         {
................................................................................
   451    457                     processorArchitecturePlatforms.Add("IA64", "Itanium");
   452    458                     processorArchitecturePlatforms.Add("ARM", "WinCE");
   453    459                 }
   454    460   
   455    461                 //
   456    462                 // BUGBUG: What about other application domains?
   457    463                 //
   458         -              if (_SQLiteModule == IntPtr.Zero)
   459         -                  _SQLiteModule = PreLoadSQLiteDll(null, null);
          464  +              if (_SQLiteNativeModuleHandle == IntPtr.Zero)
          465  +              {
          466  +                  //
          467  +                  // NOTE: Attempt to pre-load the SQLite core library (or
          468  +                  //       interop assembly) and store both the file name
          469  +                  //       and native module handle for later usage.
          470  +                  //
          471  +                  /* IGNORED */
          472  +                  PreLoadSQLiteDll(
          473  +                      null, null, ref _SQLiteNativeModuleFileName,
          474  +                      ref _SQLiteNativeModuleHandle);
          475  +              }
   460    476             }
   461    477         }
   462    478   
   463    479         /////////////////////////////////////////////////////////////////////////
   464    480         /// <summary>
   465    481         /// Queries and returns the base directory of the current application
   466    482         /// domain.
................................................................................
   717    733         /// processor architecture specific sub-directories.
   718    734         /// </param>
   719    735         /// <param name="processorArchitecture">
   720    736         /// The requested processor architecture, null for default (the
   721    737         /// processor architecture of the current process).  This caller should
   722    738         /// almost always specify null for this parameter.
   723    739         /// </param>
          740  +      /// <param name="nativeModuleFileName">
          741  +      /// The candidate native module file name to load will be stored here,
          742  +      /// if necessary.
          743  +      /// </param>
          744  +      /// <param name="nativeModuleHandle">
          745  +      /// The native module handle as returned by LoadLibrary will be stored
          746  +      /// here, if necessary.  This value will be IntPtr.Zero if the call to
          747  +      /// LoadLibrary fails.
          748  +      /// </param>
   724    749         /// <returns>
   725         -      /// The native module handle as returned by LoadLibrary -OR- IntPtr.Zero
   726         -      /// if the loading fails for any reason.
          750  +      /// Non-zero if the native module was loaded successfully; otherwise,
          751  +      /// zero.
   727    752         /// </returns>
   728         -      private static IntPtr PreLoadSQLiteDll(
          753  +      private static bool PreLoadSQLiteDll(
   729    754             string directory,
   730         -          string processorArchitecture
          755  +          string processorArchitecture,
          756  +          ref string nativeModuleFileName,
          757  +          ref IntPtr nativeModuleHandle
   731    758             )
   732    759         {
   733    760             //
   734    761             // NOTE: If the specified base directory is null, use the default
   735    762             //       (i.e. attempt to automatically detect it).
   736    763             //
   737    764             if (directory == null)
   738    765                 directory = GetBaseDirectory();
   739    766   
   740    767             //
   741    768             // NOTE: If we failed to query the base directory, stop now.
   742    769             //
   743    770             if (directory == null)
   744         -              return IntPtr.Zero;
          771  +              return false;
   745    772   
   746    773             //
   747    774             // NOTE: If the native SQLite library exists in the base directory
   748    775             //       itself, stop now.
   749    776             //
   750    777             string fileName = FixUpDllFileName(Path.Combine(directory,
   751    778                 SQLITE_DLL));
   752    779   
   753    780             if (File.Exists(fileName))
   754         -              return IntPtr.Zero;
          781  +              return false;
   755    782   
   756    783             //
   757    784             // NOTE: If the specified processor architecture is null, use the
   758    785             //       default.
   759    786             //
   760    787             if (processorArchitecture == null)
   761    788                 processorArchitecture = GetProcessorArchitecture();
   762    789   
   763    790             //
   764    791             // NOTE: If we failed to query the processor architecture, stop now.
   765    792             //
   766    793             if (processorArchitecture == null)
   767         -              return IntPtr.Zero;
          794  +              return false;
   768    795   
   769    796             //
   770    797             // NOTE: Build the full path and file name for the native SQLite
   771    798             //       library using the processor architecture name.
   772    799             //
   773    800             fileName = FixUpDllFileName(Path.Combine(Path.Combine(directory,
   774    801                 processorArchitecture), SQLITE_DLL));
................................................................................
   785    812                 //
   786    813                 string platformName = GetPlatformName(processorArchitecture);
   787    814   
   788    815                 //
   789    816                 // NOTE: If we failed to translate the platform name, stop now.
   790    817                 //
   791    818                 if (platformName == null)
   792         -                  return IntPtr.Zero;
          819  +                  return false;
   793    820   
   794    821                 //
   795    822                 // NOTE: Build the full path and file name for the native SQLite
   796    823                 //       library using the platform name.
   797    824                 //
   798    825                 fileName = FixUpDllFileName(Path.Combine(Path.Combine(directory,
   799    826                     platformName), SQLITE_DLL));
   800    827   
   801    828                 //
   802    829                 // NOTE: If the file does not exist, skip trying to load it.
   803    830                 //
   804    831                 if (!File.Exists(fileName))
   805         -                  return IntPtr.Zero;
          832  +                  return false;
   806    833             }
   807    834   
   808    835             try
   809    836             {
   810    837   #if !NET_COMPACT_20 && TRACE_PRELOAD
   811    838                 try
   812    839                 {
................................................................................
   826    853   #endif
   827    854   
   828    855                 //
   829    856                 // NOTE: Attempt to load the native library.  This will either
   830    857                 //       return a valid native module handle, return IntPtr.Zero,
   831    858                 //       or throw an exception.
   832    859                 //
   833         -              return LoadLibrary(fileName);
          860  +              nativeModuleFileName = fileName;
          861  +              nativeModuleHandle = LoadLibrary(fileName);
          862  +
          863  +              return (nativeModuleHandle != IntPtr.Zero);
   834    864             }
   835    865   #if !NET_COMPACT_20 && TRACE_PRELOAD
   836    866             catch (Exception e)
   837    867   #else
   838    868             catch (Exception)
   839    869   #endif
   840    870             {
................................................................................
   860    890                 catch
   861    891                 {
   862    892                     // do nothing.
   863    893                 }
   864    894   #endif
   865    895             }
   866    896   
   867         -          return IntPtr.Zero;
          897  +          return false;
   868    898         }
   869    899   #endif
   870    900   #endif
   871    901         #endregion
   872    902   
   873    903         /////////////////////////////////////////////////////////////////////////
   874    904   

Changes to Tests/common.eagle.

   539    539         #
   540    540         return [file nativename \
   541    541             [file join [getBinaryDirectory] $platform [file tail $fileName]]]
   542    542       }
   543    543   
   544    544       proc getCoreBinaryFileName { {platform ""} {standard false} } {
   545    545         #
   546         -      # NOTE: Returns the full path for the file containing the core SQLite
   547         -      #       library code for this platform.
          546  +      # NOTE: Returns the full path for the file containing the SQLite core
          547  +      #       native library code for this platform.  First, check and see if
          548  +      #       the SQLite core native library has already been loaded.  Next,
          549  +      #       fallback to what the full path should be, based on whether the
          550  +      #       mixed-mode assembly is being used and the name of the current
          551  +      #       platform.
   548    552         #
          553  +      if {[catch {object invoke -flags +NonPublic \
          554  +              System.Data.SQLite.UnsafeNativeMethods \
          555  +              _SQLiteNativeModuleFileName} fileName] == 0 && \
          556  +          [string length $fileName] > 0} then {
          557  +        #
          558  +        # NOTE: The SQLite core native library has already been loaded via
          559  +        #       the native library pre-loader.  Return that file name now.
          560  +        #
          561  +        return $fileName
          562  +      }
          563  +
   549    564         if {[hasRuntimeOption native]} then {
   550    565           #
   551    566           # NOTE: Return the mixed-mode assembly file name.
   552    567           #
   553    568           return [file nativename \
   554    569               [file join [getBinaryDirectory] $platform System.Data.SQLite.dll]]
   555    570         } elseif {$standard} then {
................................................................................
  2193   2208           # NOTE: Skip all System.Data.SQLite related file handling (deleting,
  2194   2209           #       copying, and loading) if we are so instructed.
  2195   2210           #
  2196   2211           if {![info exists ::no(sqliteFiles)]} then {
  2197   2212             #
  2198   2213             # NOTE: Determine the name for the current native platform.
  2199   2214             #
  2200         -          set platform [getBuildPlatform true]
         2215  +          set platform [architectureForPlatform [getBuildPlatform true]]
         2216  +
         2217  +          #
         2218  +          # NOTE: Show the platform that will be used to help locate native
         2219  +          #       build files.
         2220  +          #
         2221  +          tputs $::test_channel [appendArgs \
         2222  +              "---- platform for locating native build files is \"" \
         2223  +              $platform \"\n]
  2201   2224   
  2202   2225             #
  2203   2226             # NOTE: Skip trying to delete any files if we are so instructed.
  2204   2227             #
  2205   2228             if {![info exists ::no(deleteSqliteFiles)]} then {
  2206   2229               tryDeleteAssembly sqlite3.dll
  2207   2230               tryDeleteAssembly SQLite.Interop.dll
................................................................................
  2320   2343               #       file for the Eagle shell to the build output directory,
  2321   2344               #       while using each of the names of the various legacy test
  2322   2345               #       executables.  This will help to make sure that all the
  2323   2346               #       legacy tests run with exactly the same set of Managed
  2324   2347               #       Debugging Assistants configured.
  2325   2348               #
  2326   2349               foreach mdaConfigFileName $mdaConfigFileNames {
  2327         -              tryCopyBinaryFile \
  2328         -                  EagleShell.exe.mda.config "" $mdaConfigFileName
         2350  +              tryCopyBinaryFile EagleShell.exe.mda.config "" $mdaConfigFileName
  2329   2351               }
  2330   2352             }
  2331   2353           }
  2332   2354   
  2333   2355           catch {
  2334   2356             tputs $::test_channel [appendArgs \
  2335   2357                 "---- file version of \"sqlite3.dll\"... " \