pitrou commented on a change in pull request #11037:
URL: https://github.com/apache/arrow/pull/11037#discussion_r704593234



##########
File path: go/arrow/cdata/test/test_export_to_cgo.py
##########
@@ -0,0 +1,95 @@
+#!/usr/bin/env python3
+#
+# 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.
+
+import contextlib
+import gc
+import os
+import unittest
+
+import pyarrow as pa
+from pyarrow.cffi import ffi
+
+
+def load_cgotest():
+    # XXX what about Darwin?
+    libext = 'so'
+    if os.name == 'nt':
+        libext = 'dll'
+
+    ffi.cdef(
+        """
+        void importSchema(uintptr_t ptr);
+        void importRecordBatch(uintptr_t scptr, uintptr_t rbptr);
+        void runGC();
+        """)
+    return ffi.dlopen(f'./cgotest.{libext}')
+
+
+cgotest = load_cgotest()
+
+
+class TestPythonToGo(unittest.TestCase):
+
+    def setUp(self):
+        self.c_schema = ffi.new("struct ArrowSchema*")
+        self.ptr_schema = int(ffi.cast("uintptr_t", self.c_schema))
+        self.c_array = ffi.new("struct ArrowArray*")
+        self.ptr_array = int(ffi.cast("uintptr_t", self.c_array))
+
+    def make_schema(self):
+        return pa.schema([('ints', pa.list_(pa.int32()))],
+                         metadata={b'key1': b'value1'})
+
+    def make_batch(self):
+        return pa.record_batch([[[1], [], None, [2, 42]]],
+                               self.make_schema())
+
+    def run_gc(self):
+        # Several Go GC runs can be required to run all finalizers
+        for i in range(5):
+            cgotest.runGC()
+        gc.collect()

Review comment:
       For now this would be sufficient, but when we test the other way (export 
from Go to Python) we will need to invoke the Go GC from Python after the 
Python Schema or RecordBatch is garbage-collected.




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