vyasr commented on code in PR #406:
URL: https://github.com/apache/arrow-nanoarrow/pull/406#discussion_r1534324652


##########
examples/cmake-scenarios/src/library.cpp:
##########
@@ -0,0 +1,39 @@
+// 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.
+
+#include "nanoarrow/nanoarrow.h"
+#include "nanoarrow/nanoarrow.hpp"
+
+#include "library.hpp"
+
+std::optional<std::pair<std::unique_ptr<ArrowArray>, 
std::unique_ptr<ArrowSchema>>>
+make_simple_array() {
+  nanoarrow::UniqueArray tmp_array;
+  nanoarrow::UniqueSchema tmp_schema;
+  auto result = make_simple_array(tmp_array.get(), tmp_schema.get());
+  if (result != 0) {
+    if (tmp_array.get()->release) tmp_array.get()->release(tmp_array.get());
+    if (tmp_schema.get()->release) tmp_schema.get()->release(tmp_schema.get());
+    return std::nullopt;
+  }
+  auto ret_array = std::make_unique<ArrowArray>();

Review Comment:
   I can simplify, but I have two questions (mostly for my edification):
   - Are you suggesting that you would make the API `make_simple_array` return 
a `UniqueArray` rather than an ArrowArray? I wrote this example with the 
mindset that you'd be writing C++ code internally but ultimately you'd still 
want to expose a C-like interface, so you'd end up needing to unpack the 
members of the pair and return the raw pointers via a C function.
   - Does the `tmp_array.move(...)` call not transfer the the release function 
pointer from `tmp_array` to `ret_array`? I assumed that it would transfer all 
the members of the underlying `ArrowArray`, not just the data buffer pointers.



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