Title: [MNT]: c++11 narrowing error when building for 32 bit targets · Issue #30413 · matplotlib/matplotlib · GitHub
Open Graph Title: [MNT]: c++11 narrowing error when building for 32 bit targets · Issue #30413 · matplotlib/matplotlib
X Title: [MNT]: c++11 narrowing error when building for 32 bit targets · Issue #30413 · matplotlib/matplotlib
Description: Summary this happens because get_height() and get_width() return an unsigned int, which can be losslessly narrowed into a ssize_t in 64 bit targets but not in 32 bit targets FAILED: [code=1] src/_backend_agg.cpython-313-powerpc-linux-mus...
Open Graph Description: Summary this happens because get_height() and get_width() return an unsigned int, which can be losslessly narrowed into a ssize_t in 64 bit targets but not in 32 bit targets FAILED: [code=1] src/_b...
X Description: Summary this happens because get_height() and get_width() return an unsigned int, which can be losslessly narrowed into a ssize_t in 64 bit targets but not in 32 bit targets FAILED: [code=1] src/_b...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/30413
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[MNT]: c++11 narrowing error when building for 32 bit targets","articleBody":"### Summary\n\nthis happens because `get_height()` and `get_width()` return an unsigned int, which can be losslessly narrowed into a `ssize_t` in 64 bit targets but not in 32 bit targets\n\n```\nFAILED: [code=1] src/_backend_agg.cpython-313-powerpc-linux-musl.so.p/_backend_agg_wrapper.cpp.o\nclang++ -Isrc/_backend_agg.cpython-313-powerpc-linux-musl.so.p -Isrc -I../src -I../extern/agg24-svn/include -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/sysprof-6 -I/usr/share/pkgconfig/../../lib/python3.13/site-packages/pybind11/share/pkgconfig/../../include -I/usr/include/python3.13 -fvisibility=hidden -fvisibility-inlines-hidden -flto -fdiagnostics-color=always -DNDEBUG -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c++17 -O3 -ffile-prefix-map=/builddir/python-matplotlib-3.10.5=. -Wformat -Werror=format-security -ftrivial-auto-var-init=zero -fno-omit-frame-pointer -mtune=G4 -O2 -g1 -fPIC -DWITH_GZFILEOP -pthread -MD -MQ src/_backend_agg.cpython-313-powerpc-linux-musl.so.p/_backend_agg_wrapper.cpp.o -MF src/_backend_agg.cpython-313-powerpc-linux-musl.so.p/_backend_agg_wrapper.cpp.o.d -o src/_backend_agg.cpython-313-powerpc-linux-musl.so.p/_backend_agg_wrapper.cpp.o -c ../src/_backend_agg_wrapper.cpp\n../src/_backend_agg_wrapper.cpp:253:17: error: non-constant-expression cannot be narrowed from type 'unsigned int' to 'int' in initializer list [-Wc++11-narrowing]\n253 | renderer-\u003eget_height(),\n| ^~~~~~~~~~~~~~~~~~~~~~\n../src/_backend_agg_wrapper.cpp:253:17: note: insert an explicit cast to silence this issue\n253 | renderer-\u003eget_height(),\n| ^~~~~~~~~~~~~~~~~~~~~~\n| static_cast\u003cint\u003e( )\n../src/_backend_agg_wrapper.cpp:254:17: error: non-constant-expression cannot be narrowed from type 'unsigned int' to 'int' in initializer list [-Wc++11-narrowing]\n254 | renderer-\u003eget_width(),\n| ^~~~~~~~~~~~~~~~~~~~~\n../src/_backend_agg_wrapper.cpp:254:17: note: insert an explicit cast to silence this issue\n254 | renderer-\u003eget_width(),\n| ^~~~~~~~~~~~~~~~~~~~~\n| static_cast\u003cint\u003e( )\n../src/_backend_agg_wrapper.cpp:258:17: error: non-constant-expression cannot be narrowed from type 'unsigned int' to 'int' in initializer list [-Wc++11-narrowing]\n258 | renderer-\u003eget_width() * 4,\n| ^~~~~~~~~~~~~~~~~~~~~~~~~\n../src/_backend_agg_wrapper.cpp:258:17: note: insert an explicit cast to silence this issue\n258 | renderer-\u003eget_width() * 4,\n| ^~~~~~~~~~~~~~~~~~~~~~~~~\n| static_cast\u003cint\u003e( )\n3 errors generated.\n```\n\nfull build log at https://build.chimera-linux.org/#/builders/7/builds/1457/steps/4/logs/pkg_user_python-matplotlib_3_10_5-r0\n\n### Proposed fix\n\npotentially just adding the static casts as the compiler note says\n```diff\ndiff -ruN a/src/_backend_agg_wrapper.cpp b/src/_backend_agg_wrapper.cpp\n--- a/src/_backend_agg_wrapper.cpp\t2025-07-31 19:00:28.000000000 +0200\n+++ b/src/_backend_agg_wrapper.cpp\t2025-08-10 21:50:30.146295804 +0200\n@@ -250,12 +250,12 @@\n \n .def_buffer([](RendererAgg *renderer) -\u003e py::buffer_info {\n std::vector\u003cpy::ssize_t\u003e shape {\n- renderer-\u003eget_height(),\n- renderer-\u003eget_width(),\n+ static_cast\u003cpy::ssize_t\u003e(renderer-\u003eget_height()),\n+ static_cast\u003cpy::ssize_t\u003e(renderer-\u003eget_width()),\n 4\n };\n std::vector\u003cpy::ssize_t\u003e strides {\n- renderer-\u003eget_width() * 4,\n+ static_cast\u003cpy::ssize_t\u003e(renderer-\u003eget_width() * 4),\n 4,\n 1\n };\n```","author":{"url":"https://github.com/z-erica","@type":"Person","name":"z-erica"},"datePublished":"2025-08-10T20:02:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/30413/matplotlib/issues/30413"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9956f3f5-eb36-122f-6a01-c89db040ca60 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A3C4:2AB90B:1C5E8F2:263AF18:6A536D12 |
| html-safe-nonce | 0542e6e7d554bcfe0bc09ad046c529977f22db6faa915560e2213d8fdcae45fa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBM0M0OjJBQjkwQjoxQzVFOEYyOjI2M0FGMTg6NkE1MzZEMTIiLCJ2aXNpdG9yX2lkIjoiNzIyMzY0ODQyMTEwNTg1NTc2MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 631ecc2d9448fe569ba765a6ab8ebb8b0c28edf46eadcc8e4d38cdac91d8390e |
| hovercard-subject-tag | issue:3307923327 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/30413/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fd7b0130a2e5462eb9d663a49078667cbe1a0fb227615c2392783f3f94dfcbfe/matplotlib/matplotlib/issues/30413 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fd7b0130a2e5462eb9d663a49078667cbe1a0fb227615c2392783f3f94dfcbfe/matplotlib/matplotlib/issues/30413 |
| og:image:alt | Summary this happens because get_height() and get_width() return an unsigned int, which can be losslessly narrowed into a ssize_t in 64 bit targets but not in 32 bit targets FAILED: [code=1] src/_b... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | z-erica |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width