System.Data.SQLite
Check-in [cedca9ac3f]
Not logged in

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

Overview
Comment:Another experimental change to the native library pre-loader for POSIX.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | netStandard20
Files: files | file ages | folders
SHA1:cedca9ac3f10cd69b478a1df22cd89997b4643c6
User & Date: mistachkin 2018-04-07 10:59:09
Context
2018-04-07
13:30
More work on the native library pre-loader for POSIX. check-in: c62df132f4 user: mistachkin tags: netStandard20
10:59
Another experimental change to the native library pre-loader for POSIX. check-in: cedca9ac3f user: mistachkin tags: netStandard20
10:42
Experimental enhancement to the native library pre-loader on POSIX. check-in: f04b575ad8 user: mistachkin tags: netStandard20
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

952
953
954
955
956
957
958




959
960
961
962
963
964
965
966
...
976
977
978
979
980
981
982

983
984


985
986
987
988
989
990
991
....
1000
1001
1002
1003
1004
1005
1006

1007





1008
1009
1010
1011
1012
1013
1014
....
1140
1141
1142
1143
1144
1145
1146





















1147
1148
1149
1150
1151
1152
1153
      /// Ensures that the directory containing the specified file is included
      /// in the POSIX shared library search path via the environment variable
      /// LD_LIBRARY_PATH.
      /// </summary>
      /// <param name="fileName">
      /// The file name of the native library that was successfully loaded.
      /// </param>




      private static void MaybeUpdateLdLibraryPath(
          string fileName
          )
      {
          string directory = Path.GetDirectoryName(fileName);

          if (!String.IsNullOrEmpty(directory))
          {
................................................................................
                  }
                  else
                  {
                      path = directory;
                  }

                  Environment.SetEnvironmentVariable(LdLibraryPath, path);

              }
          }


      }

      /////////////////////////////////////////////////////////////////////////

      /// <summary>
      /// Attempts to load the specified native library file using the POSIX
      /// API.
................................................................................
          string fileName
          )
      {
          IntPtr nativeModuleHandle = UnsafeNativeMethodsPosix.dlopen(
              fileName, UnsafeNativeMethodsPosix.RTLD_DEFAULT);

          if (nativeModuleHandle != IntPtr.Zero)

              MaybeUpdateLdLibraryPath(fileName);






          return nativeModuleHandle;
      }
#endif
      #endregion

      /////////////////////////////////////////////////////////////////////////
................................................................................
      [DllImport("__Internal",
#endif
          EntryPoint = "dlopen",
          CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi,
          BestFitMapping = false, ThrowOnUnmappableChar = true,
          SetLastError = true)]
      internal static extern IntPtr dlopen(string fileName, int mode);






















      /////////////////////////////////////////////////////////////////////////

      #region Private Constants
      /// <summary>
      /// For use with dlopen(), bind function calls lazily.
      /// </summary>







>
>
>
>
|







 







>


>
>







 







>
|
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
...
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
....
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
....
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
      /// Ensures that the directory containing the specified file is included
      /// in the POSIX shared library search path via the environment variable
      /// LD_LIBRARY_PATH.
      /// </summary>
      /// <param name="fileName">
      /// The file name of the native library that was successfully loaded.
      /// </param>
      /// <returns>
      /// Non-zero if the POSIX shared library path was updated; otherwise,
      /// zero.
      /// </returns>
      private static bool MaybeUpdateLdLibraryPath(
          string fileName
          )
      {
          string directory = Path.GetDirectoryName(fileName);

          if (!String.IsNullOrEmpty(directory))
          {
................................................................................
                  }
                  else
                  {
                      path = directory;
                  }

                  Environment.SetEnvironmentVariable(LdLibraryPath, path);
                  return true;
              }
          }

          return false;
      }

      /////////////////////////////////////////////////////////////////////////

      /// <summary>
      /// Attempts to load the specified native library file using the POSIX
      /// API.
................................................................................
          string fileName
          )
      {
          IntPtr nativeModuleHandle = UnsafeNativeMethodsPosix.dlopen(
              fileName, UnsafeNativeMethodsPosix.RTLD_DEFAULT);

          if (nativeModuleHandle != IntPtr.Zero)
          {
              if (MaybeUpdateLdLibraryPath(fileName))
              {
                  UnsafeNativeMethodsPosix.dlclose(nativeModuleHandle);
                  nativeModuleHandle = IntPtr.Zero;
              }
          }

          return nativeModuleHandle;
      }
#endif
      #endregion

      /////////////////////////////////////////////////////////////////////////
................................................................................
      [DllImport("__Internal",
#endif
          EntryPoint = "dlopen",
          CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi,
          BestFitMapping = false, ThrowOnUnmappableChar = true,
          SetLastError = true)]
      internal static extern IntPtr dlopen(string fileName, int mode);

      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// This is the P/Invoke method that wraps the native Unix dlclose
      /// function.  See the POSIX documentation for full details on what it
      /// does.
      /// </summary>
      /// <param name="module">
      /// The handle to the loaded native library.
      /// </param>
      /// <returns>
      /// Zero upon success -OR- non-zero on failure.
      /// </returns>
#if NET_STANDARD_20
      [DllImport("libdl",
#else
      [DllImport("__Internal",
#endif
          EntryPoint = "dlclose",
          CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
      internal static extern int dlclose(IntPtr module);

      /////////////////////////////////////////////////////////////////////////

      #region Private Constants
      /// <summary>
      /// For use with dlopen(), bind function calls lazily.
      /// </summary>