wjones127 commented on code in PR #34133:
URL: https://github.com/apache/arrow/pull/34133#discussion_r1140740742


##########
csharp/src/Apache.Arrow/C/CArrowSchemaExporter.cs:
##########
@@ -0,0 +1,265 @@
+// 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.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Runtime.InteropServices;
+using Apache.Arrow.Types;
+
+namespace Apache.Arrow.C
+{
+    public static class CArrowSchemaExporter
+    {
+        /// <summary>
+        /// Export a type to a <see cref="CArrowSchema"/>.
+        /// </summary>
+        /// <param name="datatype">The datatype to export</param>
+        /// <param name="schema">An allocated but uninitialized CArrowSchema 
pointer.</param>
+        /// <example>
+        /// <code>
+        /// CArrowSchema* exportPtr = CArrowSchema.Create();
+        /// CArrowSchemaExporter.ExportType(dataType, exportPtr);
+        /// foreign_import_function(exportPtr);
+        /// CArrowSchema.Free(exportPtr);

Review Comment:
   I think there are two hard rules:
   
    * `CArrowSchema` should only be free'd if `CArrowSchema.release` is null.
    * `CArrowSchema.release` should only be set to null when either the release 
callback is called or the data is moved. (So I think that line you added is not 
ideal)
   
   If the `foreign_import_function` doesn't set it null, then a different 
pattern should be used. For example, the foreign importer should be the one to 
allocate the CArrowSchema and be responsible for freeing it. I think this is 
the reason that it's intended that the consumers allocate and own 
`CArrowSchema`, rather than the producer. But when interacting with R and 
Python, it's sometimes convenient to have the C++/Rust/... producer make these 
structs, so the move pattern is nice.



-- 
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