davidhcoe commented on code in PR #697:
URL: https://github.com/apache/arrow-adbc/pull/697#discussion_r1218462987


##########
csharp/src/Apache.Arrow.Adbc/Core/Interop.cs:
##########
@@ -0,0 +1,694 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Buffers;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+using Apache.Arrow.Adbc.Interop;
+using Apache.Arrow.C;
+using static System.Net.Mime.MediaTypeNames;
+
+#if NETSTANDARD
+using Apache.Arrow.Adbc.Extensions;
+#endif
+
+namespace Apache.Arrow.Adbc.Core
+{
+    internal static class AdbcInterop
+    {
+        private unsafe static readonly NativeDelegate<ErrorRelease> 
releaseError = new NativeDelegate<ErrorRelease>(ReleaseError);
+        private unsafe static readonly NativeDelegate<DriverRelease> 
releaseDriver = new NativeDelegate<DriverRelease>(ReleaseDriver);
+
+        private unsafe static readonly NativeDelegate<DatabaseFn> databaseInit 
= new NativeDelegate<DatabaseFn>(InitDatabase);
+        private unsafe static readonly NativeDelegate<DatabaseFn> 
databaseRelease = new NativeDelegate<DatabaseFn>(ReleaseDatabase);
+        private unsafe static readonly NativeDelegate<DatabaseSetOption> 
databaseSetOption = new NativeDelegate<DatabaseSetOption>(SetDatabaseOption);
+
+        private unsafe static readonly NativeDelegate<ConnectionInit> 
connectionInit = new NativeDelegate<ConnectionInit>(InitConnection);
+        private unsafe static readonly NativeDelegate<ConnectionFn> 
connectionRelease = new NativeDelegate<ConnectionFn>(ReleaseConnection);
+        private unsafe static readonly NativeDelegate<ConnectionGetInfo> 
connectionGetInfo = new NativeDelegate<ConnectionGetInfo>(GetConnectionInfo);
+        private unsafe static readonly NativeDelegate<ConnectionSetOption> 
connectionSetOption = new 
NativeDelegate<ConnectionSetOption>(SetConnectionOption);
+        
+        private unsafe static readonly NativeDelegate<StatementExecuteQuery> 
statementExecuteQuery = new 
NativeDelegate<StatementExecuteQuery>(ExecuteStatementQuery);
+        private unsafe static readonly NativeDelegate<StatementNew> 
statementNew = new NativeDelegate<StatementNew>(NewStatement);
+        private unsafe static readonly NativeDelegate<StatementFn> 
statementRelease = new NativeDelegate<StatementFn>(ReleaseStatement);
+        private unsafe static readonly NativeDelegate<StatementSetSqlQuery> 
statementSetSqlQuery = new 
NativeDelegate<StatementSetSqlQuery>(SetStatementSqlQuery);
+
+        public unsafe static AdbcStatusCode AdbcDriverInit(int version, 
NativeAdbcDriver* nativeDriver, NativeAdbcError* error, AdbcDriver driver)
+        {
+            DriverStub stub = new DriverStub(driver);
+            GCHandle handle = GCHandle.Alloc(stub);
+            nativeDriver->private_data = (void*)GCHandle.ToIntPtr(handle);
+            nativeDriver->release = (delegate* 
unmanaged[Stdcall]<NativeAdbcDriver*, NativeAdbcError*, 
AdbcStatusCode>)releaseDriver.Pointer;
+
+            nativeDriver->DatabaseInit = (delegate* 
unmanaged[Stdcall]<NativeAdbcDatabase*, NativeAdbcError*, 
AdbcStatusCode>)databaseInit.Pointer;
+            nativeDriver->DatabaseNew = (delegate* 
unmanaged[Stdcall]<NativeAdbcDatabase*, NativeAdbcError*, 
AdbcStatusCode>)stub.newDatabase.Pointer;
+            nativeDriver->DatabaseSetOption = (delegate* 
unmanaged[Stdcall]<NativeAdbcDatabase*, byte*, byte*, NativeAdbcError*, 
AdbcStatusCode>) databaseSetOption.Pointer;
+            nativeDriver->DatabaseRelease = (delegate* 
unmanaged[Stdcall]<NativeAdbcDatabase*, NativeAdbcError*, 
AdbcStatusCode>)databaseRelease.Pointer;
+
+            nativeDriver->ConnectionCommit = (delegate* 
unmanaged[Stdcall]<NativeAdbcConnection*, NativeAdbcError*, 
AdbcStatusCode>)connectionRelease.Pointer;
+            //nativeDriver->ConnectionGetInfo = (delegate* 
unmanaged[Stdcall]<NativeAdbcConnection *, int*, int, CArrowArrayStream*, 
NativeAdbcError*, AdbcStatusCode>)connectionGetInfo.Pointer;
+            //nativeDriver->ConnectionGetTableSchema = null;
+            //nativeDriver->ConnectionGetTableTypes = null;
+            nativeDriver->ConnectionInit = (delegate* 
unmanaged[Stdcall]<NativeAdbcConnection*, NativeAdbcDatabase*, 
NativeAdbcError*, AdbcStatusCode>)connectionInit.Pointer;
+            nativeDriver->ConnectionNew = (delegate* 
unmanaged[Stdcall]<NativeAdbcConnection*, NativeAdbcError*, 
AdbcStatusCode>)stub.newConnection.Pointer;
+            nativeDriver->ConnectionSetOption = (delegate* 
unmanaged[Stdcall]<NativeAdbcConnection*, byte*, byte*, NativeAdbcError*, 
AdbcStatusCode>)connectionSetOption.Pointer;
+            //nativeDriver->ConnectionReadPartition = null;
+            nativeDriver->ConnectionRelease = (delegate* 
unmanaged[Stdcall]<NativeAdbcConnection*, NativeAdbcError*, 
AdbcStatusCode>)connectionRelease.Pointer;
+            //nativeDriver->ConnectionRollback = null;
+
+           // nativeDriver->StatementBind = (delegate* 
unmanaged[Stdcall]<NativeAdbcStatement*, CArrowArray*, CArrowSchema*, 
NativeAdbcError*, AdbcStatusCode>)
+            nativeDriver->StatementNew = (delegate* 
unmanaged[Stdcall]<NativeAdbcConnection*, NativeAdbcStatement*, 
NativeAdbcError*, AdbcStatusCode>)statementNew.Pointer;
+            nativeDriver->StatementSetSqlQuery = (delegate* 
unmanaged[Stdcall]<NativeAdbcStatement*, byte*, NativeAdbcError *, 
AdbcStatusCode >)statementSetSqlQuery.Pointer;
+            nativeDriver->StatementExecuteQuery = (delegate* 
unmanaged[Stdcall]<NativeAdbcStatement*, CArrowArrayStream*, long*, 
NativeAdbcError*, AdbcStatusCode>)statementExecuteQuery.Pointer;
+            nativeDriver->StatementPrepare = (delegate* 
unmanaged[Stdcall]<NativeAdbcStatement*, NativeAdbcError*, 
AdbcStatusCode>)statementRelease.Pointer;
+            nativeDriver->StatementRelease = (delegate* 
unmanaged[Stdcall]<NativeAdbcStatement*, NativeAdbcError*, 
AdbcStatusCode>)statementRelease.Pointer;
+            
+            return 0;
+        }
+
+        private unsafe static void ReleaseError(NativeAdbcError* error)
+        {
+            if (error != null && ((IntPtr)error->message) != IntPtr.Zero)
+            {
+                Marshal.FreeCoTaskMem((IntPtr)error->message);

Review Comment:
   switched to FreeHGlobal



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to