From c60f7655010c55baed47be9e1d27d470abe1ab74 Mon Sep 17 00:00:00 2001 From: Jan Orend <56254096+3dJan@users.noreply.github.com> Date: Fri, 3 Nov 2023 10:13:25 +0100 Subject: [PATCH 1/4] [build.yml] Using latest runner for macos and linux --- .github/workflows/build.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5d0f96eba..6a1a3af5e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,7 @@ on: [push, pull_request] name: Build jobs: build-linux: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest steps: - run: sudo apt install -y valgrind uuid-dev - uses: actions/checkout@v2 @@ -25,7 +25,7 @@ jobs: name: bindings.zip path: build/bindings.zip build-macos: - runs-on: macos-10.15 + runs-on: macos-latest steps: - uses: actions/checkout@v2 with: @@ -42,7 +42,7 @@ jobs: path: build/lib3mf.dylib codecoverage-macos: - runs-on: macos-10.15 + runs-on: macos-latest steps: - uses: actions/checkout@v2 with: @@ -139,7 +139,7 @@ jobs: - run: ctest -V working-directory: ./build assemble-sdk: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest needs: [build-windows-release, build-linux, build-macos] steps: - run: sudo apt install -y zip unzip @@ -161,7 +161,7 @@ jobs: name: lib3mf_sdk.zip path: build/lib3mf_sdk.zip deploy-linux: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest needs: [assemble-sdk] steps: - run: sudo apt install -y zip unzip @@ -213,7 +213,7 @@ jobs: cmake --build . --config Release ./Release/Example_ExtractInfo.exe ../../Files/Helix.3mf deploy-macos: - runs-on: macos-10.15 + runs-on: macos-latest needs: [assemble-sdk] steps: - name: Download lib3mf_sdk artifact From 0cf258f5cb89fb98bafca21079a4db5f736452d2 Mon Sep 17 00:00:00 2001 From: Jan Orend <56254096+3dJan@users.noreply.github.com> Date: Fri, 3 Nov 2023 10:16:38 +0100 Subject: [PATCH 2/4] [build.yml] Don't fail cli if codecoverage fails --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6a1a3af5e..6d6c68d30 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -65,7 +65,7 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} files: ./build/Test_CPP_Bindings_filtered.info - fail_ci_if_error: true # optional (default = false) + fail_ci_if_error: false # optional (default = false) verbose: true # optional (default = false) build-windows-release: From 00a205011be5ff0f629f3048fec22d14a5a6ed8d Mon Sep 17 00:00:00 2001 From: Jan Orend <56254096+3dJan@users.noreply.github.com> Date: Fri, 3 Nov 2023 14:00:14 +0100 Subject: [PATCH 3/4] Adding fast_float as submodule --- .gitmodules | 3 +++ submodules/fast_float | 1 + 2 files changed, 4 insertions(+) create mode 160000 submodules/fast_float diff --git a/.gitmodules b/.gitmodules index b230a93cf..ce92af3a7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "submodules/AutomaticComponentToolkit"] path = submodules/AutomaticComponentToolkit url = https://github.com/Autodesk/AutomaticComponentToolkit.git +[submodule "submodules/fast_float"] + path = submodules/fast_float + url = https://github.com/fastfloat/fast_float.git diff --git a/submodules/fast_float b/submodules/fast_float new file mode 160000 index 000000000..1dfad243e --- /dev/null +++ b/submodules/fast_float @@ -0,0 +1 @@ +Subproject commit 1dfad243ec42a0459a786a621be0b1f8c8a8287e From f33ac2a4912a7a8948f30151c156cda6b803aabe Mon Sep 17 00:00:00 2001 From: Jan Orend <56254096+3dJan@users.noreply.github.com> Date: Fri, 3 Nov 2023 14:00:55 +0100 Subject: [PATCH 4/4] Using fast_float for string parsing --- CMakeLists.txt | 3 +++ Include/Common/NMR_StringUtils.h | 3 +++ Source/Common/NMR_StringUtils.cpp | 13 +++++-------- .../v093/NMR_ModelReaderNode093_TextureVertex.cpp | 4 ++-- .../Reader/v093/NMR_ModelReaderNode093_Vertex.cpp | 6 +++--- .../Reader/v100/NMR_ModelReaderNode100_Vertex.cpp | 6 +++--- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a20f84eb8..dd19e0a60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,6 +144,9 @@ else() endif() +target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/submodules/fast_float/include) + + set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" IMPORT_PREFIX "" ) # This makes sure symbols are exported target_compile_options(${PROJECT_NAME} PRIVATE "-D__LIB3MF_EXPORTS") diff --git a/Include/Common/NMR_StringUtils.h b/Include/Common/NMR_StringUtils.h index 99eb31644..b32bc76a1 100644 --- a/Include/Common/NMR_StringUtils.h +++ b/Include/Common/NMR_StringUtils.h @@ -36,6 +36,9 @@ and Exception-safe #include "Common/NMR_Types.h" #include "Common/NMR_Local.h" + +#include + #include #include #include diff --git a/Source/Common/NMR_StringUtils.cpp b/Source/Common/NMR_StringUtils.cpp index a6d37ddca..63166d6e8 100644 --- a/Source/Common/NMR_StringUtils.cpp +++ b/Source/Common/NMR_StringUtils.cpp @@ -154,17 +154,14 @@ namespace NMR { nfDouble dResult = 0.0; // Convert to double and make a input and range check! - nfChar * pEndPtr; - - dResult = strtod(pszValue, &pEndPtr); + auto answer = fast_float::from_chars(pszValue, pszValue + strlen(pszValue), dResult); // Check if any conversion happened - if ((pEndPtr == pszValue) || (!pEndPtr)) + if (answer.ec != std::errc()) + { throw CNMRException(NMR_ERROR_EMPTYSTRINGTODOUBLECONVERSION); - - if ((*pEndPtr != '\0') && (*pEndPtr != ' ')) - throw CNMRException(NMR_ERROR_INVALIDSTRINGTODOUBLECONVERSION); - + } + if ((dResult == HUGE_VAL) || (dResult == -HUGE_VAL)) throw CNMRException(NMR_ERROR_STRINGTODOUBLECONVERSIONOUTOFRANGE); diff --git a/Source/Model/Reader/v093/NMR_ModelReaderNode093_TextureVertex.cpp b/Source/Model/Reader/v093/NMR_ModelReaderNode093_TextureVertex.cpp index 3f79b9729..96c4e32d0 100644 --- a/Source/Model/Reader/v093/NMR_ModelReaderNode093_TextureVertex.cpp +++ b/Source/Model/Reader/v093/NMR_ModelReaderNode093_TextureVertex.cpp @@ -86,7 +86,7 @@ namespace NMR { __NMRASSERT(pAttributeValue); if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_TEXTURE_U) == 0) { - m_fU = strtof(pAttributeValue, nullptr); + m_fU = fnStringToFloat(pAttributeValue); if (std::isnan (m_fU)) throw CNMRException(NMR_ERROR_INVALIDMODELTEXTURECOORDINATES); if (fabs (m_fU) > XML_3MF_MAXIMUMCOORDINATEVALUE) @@ -95,7 +95,7 @@ namespace NMR { } if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_TEXTURE_V) == 0) { - m_fV = strtof(pAttributeValue, nullptr); + m_fV = fnStringToFloat(pAttributeValue); if (std::isnan (m_fV)) throw CNMRException(NMR_ERROR_INVALIDMODELTEXTURECOORDINATES); if (fabs(m_fV) > XML_3MF_MAXIMUMCOORDINATEVALUE) diff --git a/Source/Model/Reader/v093/NMR_ModelReaderNode093_Vertex.cpp b/Source/Model/Reader/v093/NMR_ModelReaderNode093_Vertex.cpp index a7502b5c2..5c8d7aeee 100644 --- a/Source/Model/Reader/v093/NMR_ModelReaderNode093_Vertex.cpp +++ b/Source/Model/Reader/v093/NMR_ModelReaderNode093_Vertex.cpp @@ -82,7 +82,7 @@ namespace NMR { __NMRASSERT(pAttributeValue); if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_X) == 0) { - m_fX = strtof(pAttributeValue, nullptr); + m_fX = fnStringToFloat(pAttributeValue); if (std::isnan (m_fX)) throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES); if (fabs (m_fX) > XML_3MF_MAXIMUMCOORDINATEVALUE) @@ -91,7 +91,7 @@ namespace NMR { } if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_Y) == 0) { - m_fY = strtof(pAttributeValue, nullptr); + m_fY = fnStringToFloat(pAttributeValue); if (std::isnan (m_fY)) throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES); if (fabs(m_fY) > XML_3MF_MAXIMUMCOORDINATEVALUE) @@ -100,7 +100,7 @@ namespace NMR { } if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_Z) == 0) { - m_fZ = strtof(pAttributeValue, nullptr); + m_fZ = fnStringToFloat(pAttributeValue); if (std::isnan (m_fZ)) throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES); if (fabs(m_fZ) > XML_3MF_MAXIMUMCOORDINATEVALUE) diff --git a/Source/Model/Reader/v100/NMR_ModelReaderNode100_Vertex.cpp b/Source/Model/Reader/v100/NMR_ModelReaderNode100_Vertex.cpp index 797e782e6..a2cc72984 100644 --- a/Source/Model/Reader/v100/NMR_ModelReaderNode100_Vertex.cpp +++ b/Source/Model/Reader/v100/NMR_ModelReaderNode100_Vertex.cpp @@ -82,7 +82,7 @@ namespace NMR { __NMRASSERT(pAttributeValue); if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_X) == 0) { - m_fX = strtof(pAttributeValue, nullptr); + m_fX = fnStringToFloat(pAttributeValue); if (std::isnan (m_fX)) throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES); if (fabs (m_fX) > XML_3MF_MAXIMUMCOORDINATEVALUE) @@ -90,7 +90,7 @@ namespace NMR { m_bHasX = true; } else if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_Y) == 0) { - m_fY = strtof(pAttributeValue, nullptr); + m_fY = fnStringToFloat(pAttributeValue); if (std::isnan (m_fY)) throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES); if (fabs(m_fY) > XML_3MF_MAXIMUMCOORDINATEVALUE) @@ -98,7 +98,7 @@ namespace NMR { m_bHasY = true; } else if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_Z) == 0) { - m_fZ = strtof(pAttributeValue, nullptr); + m_fZ = fnStringToFloat(pAttributeValue); if (std::isnan (m_fZ)) throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES); if (fabs(m_fZ) > XML_3MF_MAXIMUMCOORDINATEVALUE)