<!DOCTYPE html>
<html data-lt-installed="true">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body style="padding-bottom: 1px;">
    <p>Hi, Sergey!</p>
    <p>thanks for the patch!</p>
    <p>LGTM after fix a comment below<br>
    </p>
    <div class="moz-cite-prefix">On 09.12.2024 13:16, Sergey Kaplun
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:616560a5fc0131d0f6c5358cebbc267025444334.1733739230.git.skaplun@tarantool.org">
      <pre class="moz-quote-pre" wrap="">The `strtod parsing` subtest in the <lib/base/tonumber_scan.lua> checks
the results yielded by the `strtod()` via FFI call. In GLibc versions
before 2.19 it returns an incorrect result for "0x1p-2075" [1]. This
patch skips this test for a smaller version of the libc installed.

[1]: <a class="moz-txt-link-freetext" href="https://sourceware.org/bugzilla/show_bug.cgi?id=16151">https://sourceware.org/bugzilla/show_bug.cgi?id=16151</a>
---
 test/CMakeLists.txt                          |  1 +
 test/LuaJIT-tests/CMakeLists.txt             |  9 +++++
 test/LuaJIT-tests/lib/base/tonumber_scan.lua |  4 +-
 test/cmake/GetLibCVersion.cmake              | 41 ++++++++++++++++++++
 4 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 test/cmake/GetLibCVersion.cmake

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 0db2dd8b..be02d2e4 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -73,6 +73,7 @@ separate_arguments(LUAJIT_TEST_COMMAND)
 
 set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
 include(AddTestLib)
+include(GetLibCVersion)
 include(LibRealPath)
 
 # CTEST_FLAGS is used by CMake targets in test suites.
diff --git a/test/LuaJIT-tests/CMakeLists.txt b/test/LuaJIT-tests/CMakeLists.txt
index 019762e0..d0771e14 100644
--- a/test/LuaJIT-tests/CMakeLists.txt
+++ b/test/LuaJIT-tests/CMakeLists.txt
@@ -62,6 +62,15 @@ if(CMAKE_C_FLAGS MATCHES "-march=skylake-avx512")
   list(APPEND LUAJIT_TEST_TAGS_EXTRA +avx512)
 endif()
 
+if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+  GetLibCVersion(LIBC_VERSION)
+  # XXX: <tonumber_scan.lua> uses `strtod()`, old versions of
+  # which have the bug [1] for "0x1p-2075" parsing. Add the skip
+  # check for it.
+  # [1]: <a class="moz-txt-link-freetext" href="https://sourceware.org/bugzilla/show_bug.cgi?id=16151">https://sourceware.org/bugzilla/show_bug.cgi?id=16151</a>
+  list(APPEND LUAJIT_TEST_TAGS_EXTRA +libc=${LIBC_VERSION})
+endif()
+
 set(TEST_SUITE_NAME "LuaJIT-tests")
 
 # XXX: The call produces both test and target <LuaJIT-tests-deps>
diff --git a/test/LuaJIT-tests/lib/base/tonumber_scan.lua b/test/LuaJIT-tests/lib/base/tonumber_scan.lua
index e2dcd4d0..ac7d68a4 100644
--- a/test/LuaJIT-tests/lib/base/tonumber_scan.lua
+++ b/test/LuaJIT-tests/lib/base/tonumber_scan.lua
@@ -186,7 +186,9 @@ do --- tonumber parsing
   test_conv(tonumber)
 end
 
-do --- strtod parsing
+-- Skip for the old libc version with the bug in the `strtod()`.
+-- See also <a class="moz-txt-link-freetext" href="https://sourceware.org/bugzilla/show_bug.cgi?id=16151">https://sourceware.org/bugzilla/show_bug.cgi?id=16151</a>.
+do --- strtod parsing -libc<2.19
   test_conv(function(s)
     local d = ffi.C.strtod(s, e)
     return (e[0][0] == 0 and #s ~= 0) and d or nil
diff --git a/test/cmake/GetLibCVersion.cmake b/test/cmake/GetLibCVersion.cmake
new file mode 100644
index 00000000..d87e8b70
--- /dev/null
+++ b/test/cmake/GetLibCVersion.cmake
@@ -0,0 +1,41 @@
+# Get the libc version installed in the system.
+macro(GetLibCVersion output)
+  # Try to directly parse the version.
+  execute_process(
+    COMMAND echo "#include <gnu/libc-version.h>"</pre>
    </blockquote>
    <p>I propose to replace "echo" with a variable set by
      `find_program()`:</p>
    <p><br>
    </p>
    <p>diff --git a/test/cmake/GetLibCVersion.cmake
      b/test/cmake/GetLibCVersion.cmake<br>
      index d87e8b70..15a8b440 100644<br>
      --- a/test/cmake/GetLibCVersion.cmake<br>
      +++ b/test/cmake/GetLibCVersion.cmake<br>
      @@ -1,8 +1,14 @@<br>
       # Get the libc version installed in the system.<br>
       macro(GetLibCVersion output)<br>
      +  find_program(ECHO echo)<br>
      +  if(NOT ECHO)<br>
      +    message(FATAL_ERROR "`echo` is not found'")<br>
      +    return()<br>
      +  endif()<br>
      +<br>
         # Try to directly parse the version.<br>
         execute_process(<br>
      -    COMMAND echo "#include <gnu/libc-version.h>"<br>
      +    COMMAND ${ECHO} "#include <gnu/libc-version.h>"<br>
           COMMAND ${CMAKE_C_COMPILER} -E -dM -<br>
           OUTPUT_VARIABLE LIB_C_INFO<br>
           ERROR_VARIABLE ERROR_MSG<br>
      @@ -31,6 +37,7 @@ macro(GetLibCVersion output)<br>
       <br>
         set(${output} "${GLIBC_MAJOR}.${GLIBC_MINOR}")<br>
       <br>
      +  unset(ECHO)<br>
         unset(CMAKE_MATCH_1)<br>
         unset(GLIBC_MAJOR)<br>
         unset(GLIBC_MINOR)<br>
      <br>
    </p>
    <blockquote type="cite"
cite="mid:616560a5fc0131d0f6c5358cebbc267025444334.1733739230.git.skaplun@tarantool.org">
      <pre class="moz-quote-pre" wrap="">
+    COMMAND ${CMAKE_C_COMPILER} -E -dM -
+    OUTPUT_VARIABLE LIB_C_INFO
+    ERROR_VARIABLE ERROR_MSG
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+    RESULT_VARIABLE RES
+  )
+
+  if(NOT RES EQUAL 0)
+    message(FATAL_ERROR
+            "gnu/libc-version preprocessing has failed: '${ERROR_MSG}'")
+  endif()
+
+  string(REGEX MATCH "__GLIBC__ ([0-9]+)" MATCH ${LIB_C_INFO})
+  if(MATCH)
+    set(GLIBC_MAJOR ${CMAKE_MATCH_1})
+  else()
+    message(FATAL_ERROR "Can't determine GLIBC_MAJOR version.")
+  endif()
+
+  string(REGEX MATCH "__GLIBC_MINOR__ ([0-9]+)" MATCH ${LIB_C_INFO})
+  if(MATCH)
+    set(GLIBC_MINOR ${CMAKE_MATCH_1})
+  else()
+    message(FATAL_ERROR "Can't determine GLIBC_MINOR version.")
+  endif()
+
+  set(${output} "${GLIBC_MAJOR}.${GLIBC_MINOR}")
+
+  unset(CMAKE_MATCH_1)
+  unset(GLIBC_MAJOR)
+  unset(GLIBC_MINOR)
+  unset(MATCH)
+  unset(RES)
+  unset(ERROR_MSG)
+  unset(LIB_C_INFO)
+endmacro()
</pre>
    </blockquote>
  </body>
  <lt-container></lt-container>
</html>