Add const raw pointer model getters, deprecate the UB shared_ptr ones - #6820
Merged
Conversation
… the shared_ptr getters ObjectMeshHolder::mesh(), ObjectLinesHolder::polyline() and ObjectPointsHolder::pointCloud() return a reference to the stored std::shared_ptr<T> reinterpret_cast to std::shared_ptr<const T>, which is undefined behaviour and needs a -Wstrict-aliasing suppression on GCC. Almost every caller only dereferences the result, so add a plain const raw pointer getter next to each of them, switch all callers to it, and mark the three casting functions [[deprecated]]. The single caller that really needs shared ownership (SaveSelectedMenuItem filling MeshSave::NamedXfMesh) now takes it from varMesh().
…d C bindings" This reverts commit b6e52b8.
… C4996 MR_BIND_IGNORE keeps the deprecation diagnostic live in the generated C bindings; the price is that mesh()/polyline()/pointCloud() disappear from the Python, C and C# APIs right away.
pythonGetSelectedModels took the getter as a member pointer, so the earlier call-site sweep missed it; the template now unwraps a raw pointer as well as a shared_ptr.
extractMesh/extractLines/extractPoints are resolved by name at import time, so hiding mesh()/polyline()/pointCloud() from the bindings broke 'import meshlib.mrmeshpy'.
Grantim
approved these changes
Sep 10, 2026
…generated C bindings"" This reverts commit 9553ff8.
Their Python/C/C# spelling stays available; MeshLibC2 mutes C4996 again for the generated code that calls them.
… in the generated C bindings""" This reverts commit 84bce22.
…ames Each of the three holders now offers both a const and a mutable raw pointer to its model, following the varMesh()/mesh() naming already used for the shared_ptr accessors.
adalisk-emikhaylov
approved these changes
Sep 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ObjectMeshHolder::mesh(),ObjectLinesHolder::polyline()andObjectPointsHolder::pointCloud()returnstd::shared_ptr<T>andstd::shared_ptr<const T>are unrelated types, so this is a strict-aliasing violation - undefined behaviour that every implementation happens to get away with only because the two have identical layout. GCC sees through it and each of the three functions needs its own#pragma GCC diagnostic ignored "-Wstrict-aliasing"block, commented "Fingers crossed."Almost every caller only dereferences the result, so this PR:
varMesh()/mesh()pair:meshPtr()/varMeshPtr(),polylinePtr()/varPolylinePtr(),pointCloudPtr()/varPointCloudPtr();[[deprecated]], so nothing new starts using them and they can be removed later.The only caller that really needs shared ownership is
SaveSelectedMenuItem::action(), which fillsMeshSave::NamedXfMeshand captures it in aProgressBarlambda; it now takes theshared_ptrfromvarMesh()instead.Two knock-on changes outside the call sites:
MRBINDC_IGNORE_DEPRECATION, so the generated bindings need nothing from us.scripts/mrbind/aliases.cppresolvesextractMesh/extractLines/extractPointsby name at import time, and those now point at the new getters so they keep working once the deprecated ones are removed.pythonGetSelectedModelsinmrviewerpytakes the getter as a member pointer, so it decided whether to dereference fromMR::Meta::SharedPtrTraits; it now unwraps a raw pointer as well as ashared_ptr.Verified locally with MSVC
cl /Zsand/we4996, i.e. any remaining use of a deprecated getter is a compile error: MRMesh (305 TUs), MRViewer (153), MRVoxels (37), mrviewerpy (3) and the remaining 166 TUs undersource/are clean apart from the sweep's own known artifacts (MRSparsePolynomial's missing<iterator>without the project PCH, the win32 TUs that need/FI windows.h, and dllimport errors from not passing each library's<Lib>_EXPORTS).