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,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
18 # distutils: language=c++
19 # cython: language_level = 3
22 from pyarrow.lib cimport *
23 from pyarrow.lib import frombytes, tobytes
25 # basic test to roundtrip through a BoundFunction
27 ctypedef CStatus visit_string_cb(const c_string&)
29 cdef extern from * namespace "arrow::py" nogil:
35 #include "arrow/status.h"
40 Status VisitStrings(const std::vector<std::string>& strs,
41 std::function<Status(const std::string&)> cb) {
42 for (const std::string& str : strs) {
43 RETURN_NOT_OK(cb(str));
51 cdef CStatus CVisitStrings" arrow::py::VisitStrings"(
52 vector[c_string], function[visit_string_cb])
55 cdef void _visit_strings_impl(py_cb, const c_string& s) except *:
59 def _visit_strings(strings, cb):
61 function[visit_string_cb] c_cb
62 vector[c_string] c_strings
64 c_cb = BindFunction[visit_string_cb](&_visit_strings_impl, cb)
66 c_strings.push_back(tobytes(s))
68 check_status(CVisitStrings(c_strings, c_cb))