kevingurney commented on code in PR #34563: URL: https://github.com/apache/arrow/pull/34563#discussion_r1166816899
########## matlab/tools/cmake/BuildMatlabArrowInterface.cmake: ########## @@ -0,0 +1,80 @@ +# 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. + +# ------- +# Config +# ------- + +# Build configuration for libmexclass. +set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy;${CMAKE_SOURCE_DIR}/src/cpp") +set(CUSTOM_PROXY_FACTORY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory.cc") +set(CUSTOM_PROXY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/float64_array.cc") +set(CUSTOM_PROXY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}") +set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB}) +# On Windows, arrow.dll must be installed regardless of +# whether Arrow_FOUND is true or false. Therefore, we explicitly +# copy ARROW_SHARED_LIB to the installation folder +libmexclass/+proxy. +set(CUSTOM_PROXY_RUNTIME_LIBRARIES ${ARROW_SHARED_LIB}) +set(CUSTOM_PROXY_FACTORY_HEADER_FILENAME "factory.h") +set(CUSTOM_PROXY_FACTORY_CLASS_NAME "arrow::matlab::proxy::Factory") Review Comment: Thank you for very much for sharing your thoughts, @kou! > How did you try it? std::cout << array->ToString() << std::endl; creates a temporary std::string. So I think that you can't touch the std::string in Float64Array::Print. (I think that you can't refer the std::string without specifying its address explicitly.) We actually did try modifying the code to copy the resulting `std::string` returned by `array->ToString()` before displaying it using `std::cout`. Unfortunately, the memory corruption still seems to occur even when the data is copied. > Could you share the log from AddressSanitizer? So far, we've only had access to a Linux machine with `AddressSanitizer`, and, for some reason, the memory corruption doesn't appear to be occurring on Linux (i.e. `AddressSanitizer` didn't display any output). Once we have a Windows build working with `AddressSanitizer` enabled, we will be happy to share the output! > I agree with you. Excellent! We will work on addressing the remaining feedback on this pull request to keep things moving forward. --- **Update**: We've made a bit more progress on simplifying the reproduction steps for this issue. This is reproducible by creating a [basic C++ MEX function](https://www.mathworks.com/help/matlab/matlab_external/c-mex-functions.html) which creates an `arrow::Array` and calls `ToString` on it, without using `libmexclass` or `CMake`/[`FindMatlab`](https://cmake.org/cmake/help/latest/module/FindMatlab.html) (i.e. compile the MEX gateway function using the [`mex`](https://www.mathworks.com/help/matlab/ref/mex.html) command in MATLAB): ```matlab >> mex -v -g COMPFLAGS='$COMPFLAGS /std:c++17' test.cpp -IC:\path\to\arrow\debug\install\include -larrow -LC:path\to\arrow\debug\install\lib ``` **Note**: when using the `mex` command above, we linked the MEX gateway against a `Debug` mode build of the Arrow C++ libraries built using Visual Studio 2019. Interestingly, this memory corruption is **not** reproducible with a simple standalone C++ program (i.e. no MATLAB or MEX). -- 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]
