Repository navigation
Fix with_std_vector() element cast collision across types under Clang - #317
Merged
Merged
Conversation
sol2 names a pushed functor's metatable after a __PRETTY_FUNCTION__-derived type name, and Clang spells a lambda there as "(lambda at file:line:col)" without the enclosing template arguments. The captureless cast lambda inside with_std_vector<VecElement>() therefore got the same metatable name for every instantiation, so the second type to call with_std_vector() in one lua_State silently reused the first type's __call: B.as_vec(...) invoked A's cast, corrupting the heap with the unchecked getter or rejecting every argument with the checked one. GCC and MSVC produce distinct names, which is why only Emscripten and macOS builds ever showed it. Push a named function template (details::identity_cast<VecElement>) instead - a C closure, no functor metatable, and a name that carries its template argument on every compiler. Adds a regression test with two with_std_vector() types in one state, the shape none of the existing tests covered. Fixes #300 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
sol2 names a pushed functor's metatable after a PRETTY_FUNCTION-derived type name, and Clang spells a lambda there as "(lambda at file:line:col)" without the enclosing template arguments. The captureless cast lambda inside with_std_vector() therefore got the same metatable name for every instantiation, so the second type to call with_std_vector() in one lua_State silently reused the first type's __call: B.as_vec(...) invoked A's cast, corrupting the heap with the unchecked getter or rejecting every argument with the checked one. GCC and MSVC produce distinct names, which is why only Emscripten and macOS builds ever showed it.
Push a named function template (details::identity_cast) instead - a C closure, no functor metatable, and a name that carries its template argument on every compiler. Adds a regression test with two with_std_vector() types in one state, the shape none of the existing tests covered.
Fixes #300