You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "pitrou (via GitHub)" <gi...@apache.org> on 2023/06/08 07:56:25 UTC

[GitHub] [arrow] pitrou commented on a diff in pull request #35496: GH-33856: [C#] Implement C Data Interface for C#

pitrou commented on code in PR #35496:
URL: https://github.com/apache/arrow/pull/35496#discussion_r1222602105


##########
csharp/src/Apache.Arrow/C/CArrowArrayExporter.cs:
##########
@@ -0,0 +1,211 @@
+// 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.Runtime.InteropServices;
+using Apache.Arrow.Memory;
+
+namespace Apache.Arrow.C
+{
+    public static class CArrowArrayExporter
+    {
+        private unsafe delegate void ReleaseArrowArray(CArrowArray* cArray);
+        private static unsafe readonly NativeDelegate<ReleaseArrowArray> s_releaseArray = new NativeDelegate<ReleaseArrowArray>(ReleaseArray);
+
+        /// <summary>
+        /// Export an <see cref="IArrowArray"/> to a <see cref="CArrowArray"/>. Whether or not the
+        /// export succeeds, the original array becomes invalid. Clone an array to continue using it
+        /// after a copy has been exported.
+        /// </summary>
+        /// <param name="array">The array to export</param>
+        /// <param name="cArray">An allocated but uninitialized CArrowArray pointer.</param>
+        /// <example>
+        /// <code>
+        /// CArrowArray* exportPtr = CArrowArray.Create();
+        /// CArrowArrayExporter.ExportArray(array, exportPtr);
+        /// foreign_import_function(exportPtr);
+        /// </code>
+        /// </example>
+        public static unsafe void ExportArray(IArrowArray array, CArrowArray* cArray)
+        {
+            if (array == null)
+            {
+                throw new ArgumentNullException(nameof(array));
+            }
+            if (cArray == null)
+            {
+                throw new ArgumentNullException(nameof(cArray));
+            }
+            if (cArray->release != null)
+            {
+                throw new ArgumentException("Cannot export array to a struct that is already initialized.", nameof(cArray));
+            }

Review Comment:
   Then `CArrowSchemaExporter` should probably be modified as well.
   
   This is producer code, not consumer code. At this point, the structure is still uninitialized. "Uninitialized" in the C (or C++) sense, that is "may contain any arbitrary bytes", not "zero-initialized".
   
   Producer code therefore shouldn't care about what is already in the structure.
   
   cc @paleolimbot 



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org