<commit_before>// Copyright (c) 2013-2017 SIL International
// This software is licensed under the MIT license (http://opensource.org/licenses/MIT)
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Icu.Collation;

namespace Icu
{
	internal static class NativeMethods
	{
		private const int MinIcuVersionDefault = 44;
		private const int MaxIcuVersionDefault = 60;
		private static int minIcuVersion = MinIcuVersionDefault;
		private static int maxIcuVersion = MaxIcuVersionDefault;

		public static void SetMinMaxIcuVersions(int minVersion = MinIcuVersionDefault,
			int maxVersion = MaxIcuVersionDefault)
		{
			if (minVersion < MinIcuVersionDefault || minVersion > MaxIcuVersionDefault)
			{
				throw new ArgumentOutOfRangeException("minVersion",
					$"supported ICU versions are between {MinIcuVersionDefault} and {MaxIcuVersionDefault}");
			}
			if (maxVersion < MinIcuVersionDefault || maxVersion > MaxIcuVersionDefault)
			{
				throw new ArgumentOutOfRangeException("maxVersion",
					$"supported ICU versions are between {MinIcuVersionDefault} and {MaxIcuVersionDefault}");
			}
			minIcuVersion = Math.Min(minVersion, maxVersion);
			maxIcuVersion = Math.Max(minVersion, maxVersion);
		}

		private static MethodsContainer Methods;

		static NativeMethods()
		{
			Methods = new MethodsContainer();
#if !NET40
			var icuInfo = NativeMethodsHelper.GetIcuVersionInfoForNetCoreOrWindows();
			if (icuInfo.Success)
			{
				_IcuPath = icuInfo.IcuPath.FullName;
				IcuVersion = icuInfo.IcuVersion;
			}
#endif
		}

		#region Dynamic method loading

		#region Native methods for Linux

		private const int RTLD_NOW = 2;

		[DllImport("libdl.so", SetLastError = true)]
		private static extern IntPtr dlopen([MarshalAs(UnmanagedType.LPTStr)] string file, int mode);

		[DllImport("libdl.so", SetLastError = true)]
		private static extern int dlclose(IntPtr handle);

		[DllImport("libdl.so", SetLastError = true)]
		private static extern IntPtr dlsym(IntPtr handle, [MarshalAs(UnmanagedType.LPTStr)] string name);

		#endregion

		#region Native methods for Windows

		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern IntPtr LoadLibraryEx(string dllToLoad, IntPtr hReservedNull, LoadLibraryFlags dwFlags);

		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern bool FreeLibrary(IntPtr hModule);

		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);<commit_msg>Remove [MarshalAs(UnmanagedType.LPTStr] from dlopen and dlsym because they result in errors when PInvoking on Linux<commit_after>// Copyright (c) 2013-2017 SIL International
// This software is licensed under the MIT license (http://opensource.org/licenses/MIT)
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Icu.Collation;

namespace Icu
{
	internal static class NativeMethods
	{
		private const int MinIcuVersionDefault = 44;
		private const int MaxIcuVersionDefault = 60;
		private static int minIcuVersion = MinIcuVersionDefault;
		private static int maxIcuVersion = MaxIcuVersionDefault;

		public static void SetMinMaxIcuVersions(int minVersion = MinIcuVersionDefault,
			int maxVersion = MaxIcuVersionDefault)
		{
			if (minVersion < MinIcuVersionDefault || minVersion > MaxIcuVersionDefault)
			{
				throw new ArgumentOutOfRangeException("minVersion",
					$"supported ICU versions are between {MinIcuVersionDefault} and {MaxIcuVersionDefault}");
			}
			if (maxVersion < MinIcuVersionDefault || maxVersion > MaxIcuVersionDefault)
			{
				throw new ArgumentOutOfRangeException("maxVersion",
					$"supported ICU versions are between {MinIcuVersionDefault} and {MaxIcuVersionDefault}");
			}
			minIcuVersion = Math.Min(minVersion, maxVersion);
			maxIcuVersion = Math.Max(minVersion, maxVersion);
		}

		private static MethodsContainer Methods;

		static NativeMethods()
		{
			Methods = new MethodsContainer();
#if !NET40
			var icuInfo = NativeMethodsHelper.GetIcuVersionInfoForNetCoreOrWindows();
			if (icuInfo.Success)
			{
				_IcuPath = icuInfo.IcuPath.FullName;
				IcuVersion = icuInfo.IcuVersion;
			}
#endif
		}

		#region Dynamic method loading

		#region Native methods for Linux

		private const int RTLD_NOW = 2;

		[DllImport("libdl.so", SetLastError = true)]
		private static extern IntPtr dlopen(string file, int mode);

		[DllImport("libdl.so", SetLastError = true)]
		private static extern int dlclose(IntPtr handle);

		[DllImport("libdl.so", SetLastError = true)]
		private static extern IntPtr dlsym(IntPtr handle, string name);

		#endregion

		#region Native methods for Windows

		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern IntPtr LoadLibraryEx(string dllToLoad, IntPtr hReservedNull, LoadLibraryFlags dwFlags);

		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern bool FreeLibrary(IntPtr hModule);

		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
{'fraction_non_alphanumeric': 0.0850900728248371, 'fraction_numerical': 0.008049060942889995, 'mean_word_length': 5.14, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7035554', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1529, 'n_words': 429}