Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Simplify/improve error reporting from ft2font. #30102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2025

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented May 24, 2025

Provide a simple macro to call a FreeType function and throw an exception if an error is returned, while also including the source file and line location for the error. For example, trying FT2Font(open("pyproject.toml", "rb")) now raises "FT_Open_Face (ft2font.cpp line 220) failed with error 0x02: unknown file format" instead of "Can not load face (unknown file format; error code 0x2)".

cf. discussion starting at #30059 (comment).

PR summary

PR checklist

Provide a simple macro to call a FreeType function and throw
an exception if an error is returned, while also including the
source file and line location for the error.  For example, trying
`FT2Font(open("pyproject.toml", "rb"))` now raises "FT_Open_Face
(ft2font.cpp line 220) failed with error 0x2: unknown file format"
instead of "Can not load face (unknown file format; error code 0x2)"
@QuLogic QuLogic added this to the v3.11.0 milestone May 29, 2025
@QuLogic QuLogic merged commit 71e119b into matplotlib:main May 29, 2025
40 of 41 checks passed
@QuLogic
Copy link
Member

QuLogic commented May 29, 2025

I probably should have checked cibuildwheel due to old macOS compat; this broke builds there:

        ../src/ft2font.cpp:220:5: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations]
            FT_CHECK(FT_Open_Face, _ft2Library, &open_args, 0, &face);
            ^
        ../src/ft2font.h:56:9: note: expanded from macro 'FT_CHECK'
                THROW_FT_ERROR(#func, error_); \
                ^
        ../src/ft2font.h:46:5: note: expanded from macro 'THROW_FT_ERROR'
            sprintf(buf, "%#04x", err); \
            ^
        /Applications/Xcode_15.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdio.h:180:1: note: 'sprintf' has been explicitly marked deprecated here
        __deprecated_msg("This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.")
        ^
        /Applications/Xcode_15.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:215:48: note: expanded from macro '__deprecated_msg'
                #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
                                                              ^
        ../src/ft2font.cpp:220:5: error: 'path' is unavailable: introduced in macOS 10.15
            FT_CHECK(FT_Open_Face, _ft2Library, &open_args, 0, &face);
            ^
        ../src/ft2font.h:56:9: note: expanded from macro 'FT_CHECK'
                THROW_FT_ERROR(#func, error_); \
                ^
        ../src/ft2font.h:49:28: note: expanded from macro 'THROW_FT_ERROR'
        /Applications/Xcode_15.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__filesystem/path.h:505:3: note: '~path' has been explicitly marked unavailable here
          ~path() = default;
          ^
        ../src/ft2font.cpp:282:5: error: 'filename' is unavailable: introduced in macOS 10.15
            FT_CHECK(FT_Set_Charmap, face, face->charmaps[i]);
            ^
        ../src/ft2font.h:56:9: note: expanded from macro 'FT_CHECK'
                THROW_FT_ERROR(#func, error_); \
                ^
        ../src/ft2font.h:49:43: note: expanded from macro 'THROW_FT_ERROR'
                + std::filesystem::path(__FILE__).filename().string() \
                                                  ^
        /Applications/Xcode_15.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__filesystem/path.h:957:30: note: 'filename' has been explicitly marked unavailable here
          _LIBCPP_HIDE_FROM_ABI path filename() const {
                                     ^
        ../src/ft2font.cpp:282:5: error: '~path' is unavailable: introduced in macOS 10.15
            FT_CHECK(FT_Set_Charmap, face, face->charmaps[i]);
            ^
        ../src/ft2font.h:56:9: note: expanded from macro 'FT_CHECK'
                THROW_FT_ERROR(#func, error_); \
                ^
        ../src/ft2font.h:49:43: note: expanded from macro 'THROW_FT_ERROR'
                + std::filesystem::path(__FILE__).filename().string() \
                                                  ^
        /Applications/Xcode_15.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__filesystem/path.h:505:3: note: '~path' has been explicitly marked unavailable here
          ~path() = default;
          ^
        ../src/ft2font.cpp:282:5: error: 'string' is unavailable: introduced in macOS 10.15
            FT_CHECK(FT_Set_Charmap, face, face->charmaps[i]);
            ^
        ../src/ft2font.h:56:9: note: expanded from macro 'FT_CHECK'
                THROW_FT_ERROR(#func, error_); \
                ^
        ../src/ft2font.h:49:54: note: expanded from macro 'THROW_FT_ERROR'
                + std::filesystem::path(__FILE__).filename().string() \
                                                             ^
        /Applications/Xcode_15.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__filesystem/path.h:852:39: note: 'string' has been explicitly marked unavailable here
          _LIBCPP_HIDE_FROM_ABI _VSTD::string string() const { return __pn_; }
                                              ^
        ../src/ft2font.cpp:287:5: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations]
            FT_CHECK(FT_Select_Charmap, face, (FT_Encoding)i);
            ^
        ../src/ft2font.h:56:9: note: expanded from macro 'FT_CHECK'
                THROW_FT_ERROR(#func, error_); \
                ^
        ../src/ft2font.h:46:5: note: expanded from macro 'THROW_FT_ERROR'
            sprintf(buf, "%#04x", err); \
            ^
        /Applications/Xcode_15.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdio.h:180:1: note: 'sprintf' has been explicitly marked deprecated here
        __deprecated_msg("This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.")
        ^
        /Applications/Xcode_15.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:215:48: note: expanded from macro '__deprecated_msg'
                #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
                                                              ^
        ../src/ft2font.cpp:287:5: error: 'path' is unavailable: introduced in macOS 10.15
            FT_CHECK(FT_Select_Charmap, face, (FT_Encoding)i);
            ^
        ../src/ft2font.h:56:9: note: expanded from macro 'FT_CHECK'
                THROW_FT_ERROR(#func, error_); \
                ^
        ../src/ft2font.h:49:28: note: expanded from macro 'THROW_FT_ERROR'
                + std::filesystem::path(__FILE__).filename().string() \
                                   ^
        /Applications/Xcode_15.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__filesystem/path.h:442:24: note: 'path' has been explicitly marked unavailable here
        class _LIBCPP_TYPE_VIS path {
                               ^
        fatal error: too many errors emitted, stopping now [-ferror-limit=]

@anntzer anntzer deleted the fterror branch May 30, 2025 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants