From c07c9d12ad44a79fd6d7a7cc9bec722624759927 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Mon, 30 Sep 2024 16:33:02 +0200 Subject: [PATCH] Introduce VISP_HAVE_WORKING_REGEX macro to ensure std::regex is working // was implemented and released in GCC 4.9.0. In older version of GCC, it is not implemented. // See https://stackoverflow.com/questions/12530406/is-gcc-4-8-or-earlier-buggy-about-regular-expressions // Calling std::regex lead to a segfault on centos 7.2 that has g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11) --- cmake/templates/vpConfig.h.in | 21 +++++++++++++++---- doc/config-doxygen.in | 1 + modules/core/src/tools/file/vpIoTools_npy.cpp | 17 ++++++++------- modules/core/test/tools/io/testNPZ.cpp | 5 ++--- tutorial/misc/npz/tutorial-npz.cpp | 2 +- .../tutorial-mb-generic-tracker-read.cpp | 2 +- .../tutorial-mb-generic-tracker-save.cpp | 2 +- 7 files changed, 32 insertions(+), 18 deletions(-) diff --git a/cmake/templates/vpConfig.h.in b/cmake/templates/vpConfig.h.in index efa274b9fc..06022b5d0e 100644 --- a/cmake/templates/vpConfig.h.in +++ b/cmake/templates/vpConfig.h.in @@ -1,5 +1,4 @@ -/**************************************************************************** - * +/* * ViSP, open source Visual Servoing Platform software. * Copyright (C) 2005 - 2023 by Inria. All rights reserved. * @@ -30,8 +29,7 @@ * * Description: * ViSP configuration. - * -*****************************************************************************/ + */ #ifndef VP_CONFIG_H #define VP_CONFIG_H @@ -610,6 +608,21 @@ namespace vp = VISP_NAMESPACE_NAME; #include #endif +#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) +// was implemented and released in GCC 4.9.0. In older version of GCC, it is not implemented. +// See https://stackoverflow.com/questions/12530406/is-gcc-4-8-or-earlier-buggy-about-regular-expressions +// Calling std::regex lead to a segfault on centos 7.2 that has g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11) +#include +#if __cplusplus >= 201103L && \ + (!defined(__GLIBCXX__) || (__cplusplus >= 201402L) || \ + (defined(_GLIBCXX_REGEX_DFS_QUANTIFIERS_LIMIT) || \ + defined(_GLIBCXX_REGEX_STATE_LIMIT) || \ + (defined(_GLIBCXX_RELEASE) && \ + _GLIBCXX_RELEASE > 4))) +#define VISP_HAVE_WORKING_REGEX +#endif +#endif + // Handle portable symbol export. // Defining manually which symbol should be exported is required // under Windows whether MinGW or MSVC is used. diff --git a/doc/config-doxygen.in b/doc/config-doxygen.in index 4b802524dc..8aa93cba61 100644 --- a/doc/config-doxygen.in +++ b/doc/config-doxygen.in @@ -2451,6 +2451,7 @@ PREDEFINED = @DOXYGEN_SHOULD_SKIP_THIS@ \ VISP_HAVE_VIPER850 \ VISP_HAVE_VIPER850_DATA \ VISP_HAVE_VIRTUOSE \ + VISP_HAVE_WORKING_REGEX VISP_HAVE_X11 \ VISP_HAVE_XML2 \ VISP_HAVE_YARP \ diff --git a/modules/core/src/tools/file/vpIoTools_npy.cpp b/modules/core/src/tools/file/vpIoTools_npy.cpp index f2d64cbac2..737711b83f 100644 --- a/modules/core/src/tools/file/vpIoTools_npy.cpp +++ b/modules/core/src/tools/file/vpIoTools_npy.cpp @@ -34,7 +34,7 @@ #include #include -#if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_98) && defined(VISP_HAVE_MINIZ) +#if defined(VISP_HAVE_MINIZ) && defined(VISP_HAVE_WORKING_REGEX) #define USE_ZLIB_API 0 #if !USE_ZLIB_API @@ -54,9 +54,6 @@ using namespace buminiz; // Released under MIT License // license available in LICENSE file, or at http://www.opensource.org/licenses/mit-license.php -#include - - char visp::cnpy::BigEndianTest() { int x = 1; @@ -289,7 +286,7 @@ visp::cnpy::npz_t visp::cnpy::npz_load(std::string fname) const unsigned int val_22 = 22; const unsigned int val_30 = 30; while (!quit) { - std::vector local_header(30); + std::vector local_header(val_30); size_t headerres = fread(&local_header[0], sizeof(char), val_30, fp); if (headerres != 30) { throw std::runtime_error("npz_load: failed fread"); @@ -325,8 +322,12 @@ visp::cnpy::npz_t visp::cnpy::npz_load(std::string fname) uint32_t compr_bytes = *reinterpret_cast(&local_header[0] + val_18); uint32_t uncompr_bytes = *reinterpret_cast(&local_header[0] + val_22); - if (compr_method == 0) { arrays[varname] = load_the_npy_file(fp); } - else { arrays[varname] = load_the_npz_array(fp, compr_bytes, uncompr_bytes); } + if (compr_method == 0) { + arrays[varname] = load_the_npy_file(fp); + } + else { + arrays[varname] = load_the_npz_array(fp, compr_bytes, uncompr_bytes); + } } } @@ -361,7 +362,7 @@ visp::cnpy::NpyArray visp::cnpy::npz_load(std::string fname, std::string varname const unsigned int val_22 = 22; const unsigned int val_30 = 30; while (!quit) { - std::vector local_header(30); + std::vector local_header(val_30); size_t header_res = fread(&local_header[0], sizeof(char), val_30, fp); if (header_res != 30) { throw std::runtime_error("npz_load: failed fread"); diff --git a/modules/core/test/tools/io/testNPZ.cpp b/modules/core/test/tools/io/testNPZ.cpp index 6d4f946385..fdc6339039 100644 --- a/modules/core/test/tools/io/testNPZ.cpp +++ b/modules/core/test/tools/io/testNPZ.cpp @@ -40,7 +40,7 @@ #if defined(VISP_HAVE_CATCH2) && \ (defined(_WIN32) || (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))) && \ - defined(VISP_LITTLE_ENDIAN) && defined(VISP_HAVE_MINIZ) + defined(VISP_LITTLE_ENDIAN) && defined(VISP_HAVE_MINIZ) && defined(VISP_HAVE_WORKING_REGEX) #define CATCH_CONFIG_RUNNER #include @@ -65,7 +65,7 @@ std::string createTmpDir() #elif (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) std::string tmp_dir = "/tmp/" + username; #endif - std::string directory_filename = tmp_dir + "/testNPZ/"; + std::string directory_filename = tmp_dir + "/testNPZ"; vpIoTools::makeDirectory(directory_filename); return directory_filename; @@ -290,7 +290,6 @@ TEST_CASE("Test visp::cnpy::npy_load/npz_save", "[visp::cnpy I/O]") } } } - REQUIRE(vpIoTools::remove(directory_filename)); REQUIRE(!vpIoTools::checkDirectory(directory_filename)); } diff --git a/tutorial/misc/npz/tutorial-npz.cpp b/tutorial/misc/npz/tutorial-npz.cpp index a8415cfa4d..32859f9d11 100644 --- a/tutorial/misc/npz/tutorial-npz.cpp +++ b/tutorial/misc/npz/tutorial-npz.cpp @@ -35,7 +35,7 @@ // Check if cxx14 or higher #if ((__cplusplus >= 201402L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L))) \ - && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)) && defined(VISP_HAVE_MINIZ) + && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)) && defined(VISP_HAVE_MINIZ) && defined(VISP_HAVE_WORKING_REGEX) #include #include diff --git a/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-read.cpp b/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-read.cpp index 0b301d3464..6b69fc67d3 100644 --- a/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-read.cpp +++ b/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-read.cpp @@ -24,7 +24,7 @@ std::string toString(const std::string &name, int val) int main(int argc, char *argv[]) { -#if defined(VISP_HAVE_DISPLAY) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) && defined(VISP_HAVE_MINIZ) +#if defined(VISP_HAVE_DISPLAY) && defined(VISP_HAVE_MINIZ) && defined(VISP_HAVE_WORKING_REGEX) #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif diff --git a/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-save.cpp b/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-save.cpp index a16f1cac19..5df4683ebb 100644 --- a/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-save.cpp +++ b/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-save.cpp @@ -5,7 +5,7 @@ #include -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) && defined(VISP_HAVE_MINIZ) +#if defined(VISP_HAVE_MINIZ) && defined(VISP_HAVE_WORKING_REGEX) #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif