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


##########
go/arrow/internal/cdata_integration/entrypoints.go:
##########
@@ -0,0 +1,193 @@
+// 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.
+
+//go:build cdata_integration
+// +build cdata_integration
+
+package main
+
+import (
+       "C"
+       "fmt"
+       "os"
+       "runtime"
+       "unsafe"
+
+       "github.com/apache/arrow/go/v14/arrow/array"
+       "github.com/apache/arrow/go/v14/arrow/cdata"
+       "github.com/apache/arrow/go/v14/arrow/internal/arrjson"
+       "github.com/apache/arrow/go/v14/arrow/memory"
+)
+
+// #include <stdint.h>
+// #include <stdlib.h>
+import "C"
+
+var alloc = memory.NewCheckedAllocator(memory.NewGoAllocator())
+
+//export ArrowGo_BytesAllocated
+func ArrowGo_BytesAllocated() int64 {
+       return int64(alloc.CurrentAlloc())
+}
+
+//export ArrowGo_RunGC
+func ArrowGo_RunGC() {
+       runtime.GC()
+}
+
+//export ArrowGo_FreeError
+func ArrowGo_FreeError(cError *C.char) {
+       C.free(unsafe.Pointer(cError))
+}
+
+// When used in a defer() statement, this functions catches an incoming
+// panic and converts it into a regular error. This avoids crashing the
+// archery integration process and lets other tests proceed.
+// Not all panics may be caught and some will still crash the process, though.
+func handlePanic(err *error) {
+       if e := recover(); e != nil {
+               // Add a prefix while wrapping the panic-error
+               *err = fmt.Errorf("panic: %w", e.(error))
+       }
+}
+
+func newJsonReader(cJsonPath *C.char) (*arrjson.Reader, error) {
+       jsonPath := C.GoString(cJsonPath)
+
+       f, err := os.Open(jsonPath)
+       if err != nil {
+               return nil, fmt.Errorf("could not open JSON file %q: %w", 
jsonPath, err)
+       }
+       defer f.Close()
+
+       jsonReader, err := arrjson.NewReader(f, arrjson.WithAllocator(alloc))
+       if err != nil {
+               return nil, fmt.Errorf("could not open JSON file reader from 
file %q: %w", jsonPath, err)
+       }
+       return jsonReader, nil
+}
+
+func exportSchemaFromJson(cJsonPath *C.char, out *cdata.CArrowSchema) (err 
error) {

Review Comment:
   Yeah, I think I got carried away when copy/pasting the panic-catching 
snippet from some place on the Internet :-)



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