This is an automated email from the ASF dual-hosted git repository.

kevingurney pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 43c05c56b3 GH-37228: [MATLAB] Add C++ `ARROW_MATLAB_EXPORT` symbol 
export macro (#37233)
43c05c56b3 is described below

commit 43c05c56b37daa93e76b94bc3e6952d56d1ea3f2
Author: sgilmore10 <[email protected]>
AuthorDate: Thu Aug 17 16:27:24 2023 -0400

    GH-37228: [MATLAB] Add C++ `ARROW_MATLAB_EXPORT` symbol export macro 
(#37233)
    
    
    
    ### Rationale for this change
    
    Currently, the main shared library used by the MATLAB interface - 
`libarrowproxy` - does not explicitly export any symbols.
    
    This hasn't been a major issue so far based on our usage of these symbols - 
except for in one case - which was being able to define a template 
specialization of the static make function for `NumericArray<T>` in a C++ 
source file. To work around this, we decided to inline these template 
specializations.
    
    However, this isn't an ideal solution because these functions shouldn't 
need to be inlined (and, in fact, this could have undesirable performance 
implications).
    
    In addition, to enable the ability to write C++ unit tests for code in the 
"Proxy layer", we would need to export symbols from `libarrowproxy`.
    
    This is the first in a series of pull requests in which we will export 
symbols from `libarrowproxy` so we can write C++ unit tests via the GoogleTest 
framework.
    
    ### What changes are included in this PR?
    
    1. Added a C++ `ARROW_MATLAB_EXPORT` macro for exporting symbols in 
`visibility.h`
    2. Added a new header `timestamp_array.h` which declares the template 
method specialization of the static `make` function for 
`NumericArray<arrow::TimestampType>`
    3. Moved the definition of `NumericArray<arrow::TimestampType>::make` to 
`timestamp_array.cc`
    
    ### Are these changes tested?
    
    New tests points are not needed. These changes are covered by our existing  
test suite.
    
    ### Are there any user-facing changes?
    
    No.
    
    ### Future Directions
    
    1. As mentioned above, this is the first in a series of pull requests. In 
future PRs we will export more symbols to enable C++ unit testing.
    * Closes: #37228
    
    Lead-authored-by: Sarah Gilmore <[email protected]>
    Co-authored-by: Kevin Gurney <[email protected]>
    Signed-off-by: Kevin Gurney <[email protected]>
---
 matlab/src/cpp/arrow/matlab/api/visibility.h       | 28 +++++++++
 .../cpp/arrow/matlab/array/proxy/numeric_array.h   | 49 ---------------
 .../arrow/matlab/array/proxy/timestamp_array.cc    | 69 ++++++++++++++++++++++
 .../cpp/arrow/matlab/array/proxy/timestamp_array.h | 31 ++++++++++
 matlab/src/cpp/arrow/matlab/proxy/factory.cc       |  1 +
 matlab/tools/cmake/BuildMatlabArrowInterface.cmake |  2 +
 6 files changed, 131 insertions(+), 49 deletions(-)

diff --git a/matlab/src/cpp/arrow/matlab/api/visibility.h 
b/matlab/src/cpp/arrow/matlab/api/visibility.h
new file mode 100644
index 0000000000..51efac972e
--- /dev/null
+++ b/matlab/src/cpp/arrow/matlab/api/visibility.h
@@ -0,0 +1,28 @@
+// 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.
+
+#pragma once
+
+#if defined(_WIN32) || defined(__CYGWIN__)
+#ifdef ARROW_MATLAB_EXPORTING
+#define ARROW_MATLAB_EXPORT __declspec(dllexport)
+#else
+#define ARROW_MATLAB_EXPORT __declspec(dllimport)
+#endif
+#else // Not Windows
+#define ARROW_MATLAB_EXPORT __attribute__((visibility("default")))
+#endif
diff --git a/matlab/src/cpp/arrow/matlab/array/proxy/numeric_array.h 
b/matlab/src/cpp/arrow/matlab/array/proxy/numeric_array.h
index 6bfdad1f5d..9c81d5ff62 100644
--- a/matlab/src/cpp/arrow/matlab/array/proxy/numeric_array.h
+++ b/matlab/src/cpp/arrow/matlab/array/proxy/numeric_array.h
@@ -33,9 +33,6 @@
 
 #include "libmexclass/proxy/Proxy.h"
 
-#include "arrow/matlab/type/time_unit.h"
-#include "arrow/util/utf8.h"
-
 namespace arrow::matlab::array::proxy {
 
 template<typename ArrowType>
@@ -86,50 +83,4 @@ class NumericArray : public 
arrow::matlab::array::proxy::Array {
             context.outputs[0] = result;
         }
 };
-
-     // Specialization of NumericArray::Make for arrow::TimestampType.
-    template <>
-    inline libmexclass::proxy::MakeResult 
NumericArray<arrow::TimestampType>::make(const 
libmexclass::proxy::FunctionArguments& constructor_arguments) {
-        namespace mda = ::matlab::data;
-        using MatlabBuffer = arrow::matlab::buffer::MatlabBuffer;
-        using TimestampArray = arrow::TimestampArray;
-        using TimestampArrayProxy = 
arrow::matlab::array::proxy::NumericArray<arrow::TimestampType>;
-
-        mda::StructArray opts = constructor_arguments[0];
-
-        // Get the mxArray from constructor arguments
-        const mda::TypedArray<int64_t> timestamp_mda = opts[0]["MatlabArray"];
-        const mda::TypedArray<bool> validity_bitmap_mda = opts[0]["Valid"];
-        
-        const mda::TypedArray<mda::MATLABString> timezone_mda = 
opts[0]["TimeZone"];
-        const mda::TypedArray<mda::MATLABString> units_mda = 
opts[0]["TimeUnit"];
-
-        // extract the time zone string
-        const std::u16string& u16_timezone = timezone_mda[0];
-        MATLAB_ASSIGN_OR_ERROR(const auto timezone, 
-                               arrow::util::UTF16StringToUTF8(u16_timezone),
-                               error::UNICODE_CONVERSION_ERROR_ID);
-
-        // extract the time unit
-        const std::u16string& u16_timeunit = units_mda[0];
-        MATLAB_ASSIGN_OR_ERROR(const auto time_unit, 
-                               
arrow::matlab::type::timeUnitFromString(u16_timeunit),
-                               error::UKNOWN_TIME_UNIT_ERROR_ID)
-
-        // create the timestamp_type
-        auto data_type = arrow::timestamp(time_unit, timezone);
-        auto array_length = 
static_cast<int64_t>(timestamp_mda.getNumberOfElements()); // cast size_t to 
int64_t
-
-        auto data_buffer = std::make_shared<MatlabBuffer>(timestamp_mda);
-
-        // Pack the validity bitmap values.
-        MATLAB_ASSIGN_OR_ERROR(auto packed_validity_bitmap, 
-                               bit::packValid(validity_bitmap_mda), 
-                               error::BITPACK_VALIDITY_BITMAP_ERROR_ID);
-
-        auto array_data = arrow::ArrayData::Make(data_type, array_length, 
{packed_validity_bitmap, data_buffer});
-        auto timestamp_array = 
std::static_pointer_cast<TimestampArray>(arrow::MakeArray(array_data));
-        return 
std::make_shared<TimestampArrayProxy>(std::move(timestamp_array));
-    }
-
 }
diff --git a/matlab/src/cpp/arrow/matlab/array/proxy/timestamp_array.cc 
b/matlab/src/cpp/arrow/matlab/array/proxy/timestamp_array.cc
new file mode 100644
index 0000000000..45a5b6ab92
--- /dev/null
+++ b/matlab/src/cpp/arrow/matlab/array/proxy/timestamp_array.cc
@@ -0,0 +1,69 @@
+// 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 "arrow/matlab/array/proxy/timestamp_array.h"
+
+#include "arrow/matlab/type/time_unit.h"
+#include "arrow/util/utf8.h"
+
+namespace arrow::matlab::array::proxy {
+
+    // Specialization of NumericArray::Make for arrow::TimestampType.
+    template <>
+    libmexclass::proxy::MakeResult TimestampArray::make(const 
libmexclass::proxy::FunctionArguments& constructor_arguments) {
+       namespace mda = ::matlab::data;
+       using MatlabBuffer = arrow::matlab::buffer::MatlabBuffer;
+       using TimestampArray = arrow::TimestampArray;
+       using TimestampArrayProxy = 
arrow::matlab::array::proxy::NumericArray<arrow::TimestampType>;
+
+       mda::StructArray opts = constructor_arguments[0];
+
+       // Get the mxArray from constructor arguments
+       const mda::TypedArray<int64_t> timestamp_mda = opts[0]["MatlabArray"];
+       const mda::TypedArray<bool> validity_bitmap_mda = opts[0]["Valid"];
+       
+       const mda::TypedArray<mda::MATLABString> timezone_mda = 
opts[0]["TimeZone"];
+       const mda::TypedArray<mda::MATLABString> units_mda = 
opts[0]["TimeUnit"];
+
+       // extract the time zone string
+       const std::u16string& u16_timezone = timezone_mda[0];
+       MATLAB_ASSIGN_OR_ERROR(const auto timezone,
+                              arrow::util::UTF16StringToUTF8(u16_timezone),
+                              error::UNICODE_CONVERSION_ERROR_ID);
+
+       // extract the time unit
+       const std::u16string& u16_timeunit = units_mda[0];
+       MATLAB_ASSIGN_OR_ERROR(const auto time_unit,
+                              
arrow::matlab::type::timeUnitFromString(u16_timeunit),
+                              error::UKNOWN_TIME_UNIT_ERROR_ID)
+
+       // create the timestamp_type
+       auto data_type = arrow::timestamp(time_unit, timezone);
+       auto array_length = 
static_cast<int64_t>(timestamp_mda.getNumberOfElements()); // cast size_t to 
int64_t
+
+       auto data_buffer = std::make_shared<MatlabBuffer>(timestamp_mda);
+
+       // Pack the validity bitmap values.
+       MATLAB_ASSIGN_OR_ERROR(auto packed_validity_bitmap,
+                              bit::packValid(validity_bitmap_mda),
+                              error::BITPACK_VALIDITY_BITMAP_ERROR_ID);
+
+       auto array_data = arrow::ArrayData::Make(data_type, array_length, 
{packed_validity_bitmap, data_buffer});
+       auto timestamp_array = 
std::static_pointer_cast<TimestampArray>(arrow::MakeArray(array_data));
+       return 
std::make_shared<TimestampArrayProxy>(std::move(timestamp_array));
+    }
+}
diff --git a/matlab/src/cpp/arrow/matlab/array/proxy/timestamp_array.h 
b/matlab/src/cpp/arrow/matlab/array/proxy/timestamp_array.h
new file mode 100644
index 0000000000..0667917f36
--- /dev/null
+++ b/matlab/src/cpp/arrow/matlab/array/proxy/timestamp_array.h
@@ -0,0 +1,31 @@
+// 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.
+
+#pragma once
+
+#include "arrow/matlab/array/proxy/numeric_array.h"
+
+#include "arrow/matlab/api/visibility.h"
+
+namespace arrow::matlab::array::proxy {
+
+    using TimestampArray = NumericArray<arrow::TimestampType>;
+
+    // Specialization of NumericArray::Make for arrow::TimestampType
+    template<>
+    ARROW_MATLAB_EXPORT libmexclass::proxy::MakeResult 
TimestampArray::make(const libmexclass::proxy::FunctionArguments& 
constructor_arguments);
+}
diff --git a/matlab/src/cpp/arrow/matlab/proxy/factory.cc 
b/matlab/src/cpp/arrow/matlab/proxy/factory.cc
index bce875bb9f..1420cd527c 100644
--- a/matlab/src/cpp/arrow/matlab/proxy/factory.cc
+++ b/matlab/src/cpp/arrow/matlab/proxy/factory.cc
@@ -18,6 +18,7 @@
 #include "arrow/matlab/array/proxy/boolean_array.h"
 #include "arrow/matlab/array/proxy/numeric_array.h"
 #include "arrow/matlab/array/proxy/string_array.h"
+#include "arrow/matlab/array/proxy/timestamp_array.h"
 #include "arrow/matlab/tabular/proxy/record_batch.h"
 #include "arrow/matlab/tabular/proxy/schema.h"
 #include "arrow/matlab/error/error.h"
diff --git a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake 
b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake
index c19740f181..052f6b5ff2 100644
--- a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake
+++ b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake
@@ -44,6 +44,7 @@ set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_INCLUDE_DIR 
"${CMAKE_SOURCE_DIR}/src/c
 set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_SOURCES 
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/array.cc"
                                                   
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/boolean_array.cc"
                                                   
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/string_array.cc"
+                                                  
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/timestamp_array.cc"
                                                   
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/wrap.cc"
                                                   
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/tabular/proxy/record_batch.cc"
                                                   
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/tabular/proxy/schema.cc"
@@ -106,6 +107,7 @@ libmexclass_client_add_proxy_library(
 )
 # Use C++17
 target_compile_features(${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_LIBRARY_NAME} 
PRIVATE cxx_std_17)
+target_compile_definitions(${MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_LIBRARY_NAME}
 PRIVATE ARROW_MATLAB_EXPORTING)
 
 # When building Arrow from source, Arrow must be built before building the 
client Proxy library.
 if(TARGET arrow_ep)

Reply via email to