1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
25 "github.com/apache/arrow/go/v6/arrow/array"
28 // #include <stdlib.h>
29 // #include "arrow/c/helpers.h"
37 type dataHandle uintptr
39 func storeData(d *array.Data) dataHandle {
40 h := atomic.AddUintptr(&handleIdx, 1)
42 panic("cgo: ran out of space")
49 func (d dataHandle) releaseData() {
50 arrd, ok := handles.LoadAndDelete(uintptr(d))
52 panic("cgo: invalid datahandle")
54 arrd.(*array.Data).Release()
57 //export releaseExportedSchema
58 func releaseExportedSchema(schema *CArrowSchema) {
59 if C.ArrowSchemaIsReleased(schema) == 1 {
62 defer C.ArrowSchemaMarkReleased(schema)
64 C.free(unsafe.Pointer(schema.name))
65 C.free(unsafe.Pointer(schema.format))
66 C.free(unsafe.Pointer(schema.metadata))
68 if schema.n_children == 0 {
72 var children []*CArrowSchema
73 s := (*reflect.SliceHeader)(unsafe.Pointer(&children))
74 s.Data = uintptr(unsafe.Pointer(schema.children))
75 s.Len = int(schema.n_children)
76 s.Cap = int(schema.n_children)
78 for _, c := range children {
79 C.ArrowSchemaRelease(c)
82 C.free(unsafe.Pointer(children[0]))
83 C.free(unsafe.Pointer(schema.children))
86 //export releaseExportedArray
87 func releaseExportedArray(arr *CArrowArray) {
88 if C.ArrowArrayIsReleased(arr) == 1 {
91 defer C.ArrowArrayMarkReleased(arr)
93 if arr.n_buffers > 0 {
94 C.free(unsafe.Pointer(arr.buffers))
97 if arr.n_children > 0 {
98 var children []*CArrowArray
99 s := (*reflect.SliceHeader)(unsafe.Pointer(&children))
100 s.Data = uintptr(unsafe.Pointer(arr.children))
101 s.Len = int(arr.n_children)
102 s.Cap = int(arr.n_children)
104 for _, c := range children {
105 C.ArrowArrayRelease(c)
107 C.free(unsafe.Pointer(children[0]))
108 C.free(unsafe.Pointer(arr.children))
111 h := dataHandle(arr.private_data)