Skip to content

Commit

Permalink
Work around macOS arm64 varargs issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ta264 committed Nov 26, 2021
1 parent e1a1830 commit bd88a4a
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 1 deletion.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ parameters:
- name: systemDataSqliteVersion
displayName: System.Data.Sqlite version number
type: string
default: 1.0.115.0
default: 1.0.115.5

variables:
minorVersion: $[counter('minorVersion', 1)]
Expand Down
5 changes: 5 additions & 0 deletions get_system_data_sqlite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ cd net
echo "$URL"
curl --output system.data.sqlite.zip "https://system.data.sqlite.org/blobs/$1/sqlite-netFx-source-$1.zip"
unzip system.data.sqlite.zip

dos2unix System.Data.SQLite/SQLite3.cs
dos2unix System.Data.SQLite/UnsafeNativeMethods.cs
cd ..
patch -p0 < patches/System.Data.SQLite/0001_osx-arm64_support.patch
199 changes: 199 additions & 0 deletions patches/System.Data.SQLite/0001_osx-arm64_support.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
diff -ur net/System.Data.SQLite/SQLite3.cs net_patched/System.Data.SQLite/SQLite3.cs
--- net/System.Data.SQLite/SQLite3.cs 2021-07-28 01:10:44.000000000 +0100
+++ net_patched/System.Data.SQLite/SQLite3.cs 2021-11-26 19:28:10.742042591 +0000
@@ -842,8 +842,24 @@

internal static SQLiteErrorCode StaticSetMemoryStatus(bool value)
{
- SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3_config_int(
- SQLiteConfigOpsEnum.SQLITE_CONFIG_MEMSTATUS, value ? 1 : 0);
+ SQLiteErrorCode rc;
+
+ bool isArm64 = RuntimeInformation.ProcessArchitecture == Architecture.Arm64 &&
+ RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
+
+ if (isArm64)
+ {
+ rc = UnsafeNativeMethods.sqlite3_config_int_arm64(
+ SQLiteConfigOpsEnum.SQLITE_CONFIG_MEMSTATUS,
+ IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero,
+ value ? 1 : 0);
+ }
+ else
+ {
+ rc = UnsafeNativeMethods.sqlite3_config_int(
+ SQLiteConfigOpsEnum.SQLITE_CONFIG_MEMSTATUS,
+ value ? 1 : 0);
+ }

return rc;
}
@@ -3102,6 +3118,9 @@
GetConfigDbOpsNames()));
}

+ bool isArm64 = RuntimeInformation.ProcessArchitecture == Architecture.Arm64 &&
+ RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
+
switch (option)
{
case SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_NONE: // nil
@@ -3139,8 +3158,19 @@
"cannot allocate database name");
}

- rc = UnsafeNativeMethods.sqlite3_db_config_charptr(
- _sql, option, pDbName);
+ if (isArm64)
+ {
+ rc = UnsafeNativeMethods.sqlite3_db_config_charptr_arm64(
+ _sql, option,
+ IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero,
+ pDbName);
+ }
+ else
+ {
+ rc = UnsafeNativeMethods.sqlite3_db_config_charptr(
+ _sql, option,
+ pDbName);
+ }

if (rc == SQLiteErrorCode.Ok)
{
@@ -3198,8 +3228,20 @@
typeof(int)));
}

- return UnsafeNativeMethods.sqlite3_db_config_intptr_two_ints(
- _sql, option, (IntPtr)array[0], (int)array[1], (int)array[2]);
+ if (isArm64)
+ {
+ return UnsafeNativeMethods.sqlite3_db_config_intptr_two_ints_arm64(
+ _sql, option,
+ IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero,
+ (IntPtr)array[0], (int)array[1], (int)array[2]);
+
+ }
+ else
+ {
+ return UnsafeNativeMethods.sqlite3_db_config_intptr_two_ints(
+ _sql, option,
+ (IntPtr)array[0], (int)array[1], (int)array[2]);
+ }
}
case SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_ENABLE_FKEY: // int int*
case SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_ENABLE_TRIGGER: // int int*
@@ -3228,8 +3270,20 @@

int result = 0; /* NOT USED */

- return UnsafeNativeMethods.sqlite3_db_config_int_refint(
- _sql, option, ((bool)value ? 1 : 0), ref result);
+ if (isArm64)
+ {
+ return UnsafeNativeMethods.sqlite3_db_config_int_refint_arm64(
+ _sql, option,
+ IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero,
+ ((bool)value ? 1 : 0), ref result);
+ }
+ else
+ {
+ return UnsafeNativeMethods.sqlite3_db_config_int_refint(
+ _sql, option,
+ ((bool)value ? 1 : 0), ref result);
+ }
+
}
default:
{
@@ -3442,8 +3496,23 @@
/// <returns>Returns a result code</returns>
internal override SQLiteErrorCode SetLogCallback(SQLiteLogCallback func)
{
- SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3_config_log(
- SQLiteConfigOpsEnum.SQLITE_CONFIG_LOG, func, IntPtr.Zero);
+ SQLiteErrorCode rc;
+
+ bool isArm64 = RuntimeInformation.ProcessArchitecture == Architecture.Arm64 &&
+ RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
+
+ if (isArm64)
+ {
+ rc = UnsafeNativeMethods.sqlite3_config_log_arm64(
+ SQLiteConfigOpsEnum.SQLITE_CONFIG_LOG,
+ IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero,
+ func, IntPtr.Zero);
+ }
+ else
+ {
+ rc = UnsafeNativeMethods.sqlite3_config_log(
+ SQLiteConfigOpsEnum.SQLITE_CONFIG_LOG, func, IntPtr.Zero);
+ }

if (rc == SQLiteErrorCode.Ok)
{
diff -ur net/System.Data.SQLite/UnsafeNativeMethods.cs net_patched/System.Data.SQLite/UnsafeNativeMethods.cs
--- net/System.Data.SQLite/UnsafeNativeMethods.cs 2021-11-26 18:35:39.680053796 +0000
+++ net_patched/System.Data.SQLite/UnsafeNativeMethods.cs 2021-11-26 19:21:50.557282791 +0000
@@ -4464,9 +4464,23 @@
#else
[DllImport(SQLITE_DLL, EntryPoint = "sqlite3_config")]
#endif
+ internal static extern SQLiteErrorCode sqlite3_config_int_arm64(SQLiteConfigOpsEnum op, IntPtr nop1, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, int value);
+
+#if !PLATFORM_COMPACTFRAMEWORK
+ [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_config", CallingConvention = CallingConvention.Cdecl)]
+#else
+ [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_config")]
+#endif
internal static extern SQLiteErrorCode sqlite3_config_log(SQLiteConfigOpsEnum op, SQLiteLogCallback func, IntPtr pvUser);

#if !PLATFORM_COMPACTFRAMEWORK
+ [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_config", CallingConvention = CallingConvention.Cdecl)]
+#else
+ [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_config")]
+#endif
+ internal static extern SQLiteErrorCode sqlite3_config_log_arm64(SQLiteConfigOpsEnum op, IntPtr nop1, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, SQLiteLogCallback func, IntPtr pvUser);
+
+#if !PLATFORM_COMPACTFRAMEWORK
[DllImport(SQLITE_DLL, EntryPoint = "sqlite3_db_config", CallingConvention = CallingConvention.Cdecl)]
#else
[DllImport(SQLITE_DLL, EntryPoint = "sqlite3_db_config")]
@@ -4478,6 +4492,13 @@
#else
[DllImport(SQLITE_DLL, EntryPoint = "sqlite3_db_config")]
#endif
+ internal static extern SQLiteErrorCode sqlite3_db_config_charptr_arm64(IntPtr db, SQLiteConfigDbOpsEnum op, IntPtr nop1, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr charPtr);
+
+#if !PLATFORM_COMPACTFRAMEWORK
+ [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_db_config", CallingConvention = CallingConvention.Cdecl)]
+#else
+ [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_db_config")]
+#endif
internal static extern SQLiteErrorCode sqlite3_db_config_int_refint(IntPtr db, SQLiteConfigDbOpsEnum op, int value, ref int result);

#if !PLATFORM_COMPACTFRAMEWORK
@@ -4485,9 +4506,23 @@
#else
[DllImport(SQLITE_DLL, EntryPoint = "sqlite3_db_config")]
#endif
+ internal static extern SQLiteErrorCode sqlite3_db_config_int_refint_arm64(IntPtr db, SQLiteConfigDbOpsEnum op, IntPtr nop1, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, int value, ref int result);
+
+#if !PLATFORM_COMPACTFRAMEWORK
+ [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_db_config", CallingConvention = CallingConvention.Cdecl)]
+#else
+ [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_db_config")]
+#endif
internal static extern SQLiteErrorCode sqlite3_db_config_intptr_two_ints(IntPtr db, SQLiteConfigDbOpsEnum op, IntPtr ptr, int int0, int int1);

#if !PLATFORM_COMPACTFRAMEWORK
+ [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_db_config", CallingConvention = CallingConvention.Cdecl)]
+#else
+ [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_db_config")]
+#endif
+ internal static extern SQLiteErrorCode sqlite3_db_config_intptr_two_ints_arm64(IntPtr db, SQLiteConfigDbOpsEnum op, IntPtr nop1, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr ptr, int int0, int int1);
+
+#if !PLATFORM_COMPACTFRAMEWORK
[DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
#else
[DllImport(SQLITE_DLL)]

0 comments on commit bd88a4a

Please sign in to comment.