Skip to content

Commit

Permalink
Introduce VISP_HAVE_WORKING_REGEX macro to ensure std::regex is working
Browse files Browse the repository at this point in the history
// <regex> 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)
  • Loading branch information
fspindle committed Sep 30, 2024
1 parent e6a1eff commit c07c9d1
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
21 changes: 17 additions & 4 deletions cmake/templates/vpConfig.h.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/****************************************************************************
*
/*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2023 by Inria. All rights reserved.
*
Expand Down Expand Up @@ -30,8 +29,7 @@
*
* Description:
* ViSP configuration.
*
*****************************************************************************/
*/

#ifndef VP_CONFIG_H
#define VP_CONFIG_H
Expand Down Expand Up @@ -610,6 +608,21 @@ namespace vp = VISP_NAMESPACE_NAME;
#include <visp3/core/vpNullptrEmulated.h>
#endif

#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
// <regex> 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 <regex>
#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.
Expand Down
1 change: 1 addition & 0 deletions doc/config-doxygen.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
17 changes: 9 additions & 8 deletions modules/core/src/tools/file/vpIoTools_npy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpIoTools.h>

#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
Expand All @@ -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 <regex>


char visp::cnpy::BigEndianTest()
{
int x = 1;
Expand Down Expand Up @@ -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<char> local_header(30);
std::vector<char> 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");
Expand Down Expand Up @@ -325,8 +322,12 @@ visp::cnpy::npz_t visp::cnpy::npz_load(std::string fname)
uint32_t compr_bytes = *reinterpret_cast<uint32_t *>(&local_header[0] + val_18);
uint32_t uncompr_bytes = *reinterpret_cast<uint32_t *>(&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);

Check warning on line 329 in modules/core/src/tools/file/vpIoTools_npy.cpp

View check run for this annotation

Codecov / codecov/patch

modules/core/src/tools/file/vpIoTools_npy.cpp#L329

Added line #L329 was not covered by tests
}
}
}

Expand Down Expand Up @@ -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<char> local_header(30);
std::vector<char> local_header(val_30);

Check warning on line 365 in modules/core/src/tools/file/vpIoTools_npy.cpp

View check run for this annotation

Codecov / codecov/patch

modules/core/src/tools/file/vpIoTools_npy.cpp#L365

Added line #L365 was not covered by tests
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");
Expand Down
5 changes: 2 additions & 3 deletions modules/core/test/tools/io/testNPZ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <catch.hpp>

Expand All @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion tutorial/misc/npz/tutorial-npz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>
#include <complex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <visp3/io/vpVideoReader.h>


#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
Expand Down

0 comments on commit c07c9d1

Please sign in to comment.