Finalize exporting by setting C struct fields and allocating autonomous private data for each array node. This function can't fail, as properly reclaiming memory in case of error would be too fragile. After this function returns, memory is reclaimed by calling the release() pointer in the top level ArrowArray struct.
| 646 | // would be too fragile. After this function returns, memory is reclaimed |
| 647 | // by calling the release() pointer in the top level ArrowArray struct. |
| 648 | void Finish(struct ArrowArray* c_struct_) { |
| 649 | // First, create permanent ExportedArrayPrivateData, to make sure that |
| 650 | // child ArrayData pointers don't get invalidated. |
| 651 | auto pdata = new ExportedArrayPrivateData(std::move(export_)); |
| 652 | const ArrayData& data = *pdata->data_; |
| 653 | |
| 654 | // Second, finish dictionary and children. |
| 655 | if (dict_exporter_) { |
| 656 | dict_exporter_->Finish(&pdata->dictionary_); |
| 657 | } |
| 658 | pdata->child_pointers_.resize(data.child_data.size(), nullptr); |
| 659 | for (size_t i = 0; i < data.child_data.size(); ++i) { |
| 660 | auto ptr = &pdata->children_[i]; |
| 661 | pdata->child_pointers_[i] = ptr; |
| 662 | child_exporters_[i].Finish(ptr); |
| 663 | } |
| 664 | |
| 665 | // Third, fill C struct. |
| 666 | DCHECK_NE(c_struct_, nullptr); |
| 667 | memset(c_struct_, 0, sizeof(*c_struct_)); |
| 668 | |
| 669 | c_struct_->length = data.length; |
| 670 | c_struct_->null_count = data.null_count; |
| 671 | c_struct_->offset = data.offset; |
| 672 | c_struct_->n_buffers = static_cast<int64_t>(pdata->buffers_.size()); |
| 673 | c_struct_->n_children = static_cast<int64_t>(pdata->child_pointers_.size()); |
| 674 | c_struct_->buffers = pdata->buffers_.data(); |
| 675 | c_struct_->children = c_struct_->n_children ? pdata->child_pointers_.data() : nullptr; |
| 676 | c_struct_->dictionary = dict_exporter_ ? &pdata->dictionary_ : nullptr; |
| 677 | c_struct_->private_data = pdata; |
| 678 | c_struct_->release = ReleaseExportedArray; |
| 679 | } |
| 680 | |
| 681 | ExportedArrayPrivateData export_; |
| 682 | std::unique_ptr<ArrayExporter> dict_exporter_; |
no test coverage detected