Skip to content

Commit

Permalink
apacheGH-33936: [Go] C Data Interface: export dummy buffer for nil bu…
Browse files Browse the repository at this point in the history
…ffers
  • Loading branch information
lidavidm committed Jan 31, 2023
1 parent 61f3cdf commit 245f751
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
11 changes: 10 additions & 1 deletion go/arrow/cdata/cdata_exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
package cdata

// #include <errno.h>
// #include <stdint.h>
// #include <stdlib.h>
// #include "arrow/c/abi.h"
// #include "arrow/c/helpers.h"
//
// extern void releaseExportedSchema(struct ArrowSchema* schema);
// extern void releaseExportedArray(struct ArrowArray* array);
//
// const uint8_t kGoCdataZeroRegion[8] = {0};
//
// void goReleaseArray(struct ArrowArray* array) {
// releaseExportedArray(array);
// }
Expand Down Expand Up @@ -385,7 +388,13 @@ func exportArray(arr arrow.Array, out *CArrowArray, outSchema *CArrowSchema) {
for i := range bufs {
buf := bufs[i]
if buf == nil || buf.Len() == 0 {
buffers[i] = nil
if i > 0 {
// apache/arrow#33936: export a dummy buffer to be friendly to
// implementations that don't import NULL properly
buffers[i] = (*C.void)(unsafe.Pointer(&C.kGoCdataZeroRegion))
} else {
buffers[i] = nil
}
continue
}

Expand Down
23 changes: 23 additions & 0 deletions go/arrow/cdata/cdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,29 @@ func TestEmptyDictExport(t *testing.T) {
assert.Nil(t, out.dictionary.dictionary)
}

func TestEmptyStringExport(t *testing.T) {
// apache/arrow#33936: regression test
bldr := array.NewBuilder(memory.DefaultAllocator, &arrow.StringType{})
defer bldr.Release()

arr := bldr.NewArray()
defer arr.Release()

var out CArrowArray
var sc CArrowSchema
ExportArrowArray(arr, &out, &sc)

assert.EqualValues(t, 'u', *sc.format)
assert.Zero(t, sc.n_children)
assert.Nil(t, sc.dictionary)

assert.EqualValues(t, 3, out.n_buffers)
buffers := (*[3]unsafe.Pointer)(unsafe.Pointer(out.buffers))
assert.EqualValues(t, unsafe.Pointer(nil), buffers[0])
assert.NotEqualValues(t, unsafe.Pointer(nil), buffers[1])
assert.NotEqualValues(t, unsafe.Pointer(nil), buffers[2])
}

func TestRecordReaderExport(t *testing.T) {
// Regression test for apache/arrow#33767
reclist := arrdata.Records["primitives"]
Expand Down

0 comments on commit 245f751

Please sign in to comment.