From 63ea58a2889cd54f32749abf2d10f9a5ea5640ad Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 11 Jan 2024 08:05:31 +0200 Subject: Fix name recomposition bug in $name.filter*() functions --- libbuild2/functions-name.cxx | 13 +++++++++++-- libbuild2/scope.cxx | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'libbuild2') diff --git a/libbuild2/functions-name.cxx b/libbuild2/functions-name.cxx index 17a8adb..fcb492f 100644 --- a/libbuild2/functions-name.cxx +++ b/libbuild2/functions-name.cxx @@ -131,7 +131,16 @@ namespace build2 name& n (*i); bool p (n.pair); - const target_type* ntt (to_target_type (s, n, p ? *++i : name ()).first); + // to_target_type() splits the name into the target name and extension. + // While we could try to reconstitute it with combine_name(), there are + // murky corner cases (see the default_extension argument) which won't + // be easy to handle. So let's just make a copy. Looking at the + // implementation of scope::find_target_type(), we can optimize for the + // (common) typed case by only copying the type. + // + name c (n.typed () ? name (n.type, "") : n); + + const target_type* ntt (to_target_type (s, c, p ? *++i : name ()).first); if (ntt == nullptr) fail << "unknown target type " << n.type << " in " << n; @@ -376,7 +385,7 @@ namespace build2 sort (ns.begin (), ns.end ()); if (functions_sort_flags (move (fs))) - ns.erase (unique (ns.begin(), ns.end()), ns.end ()); + ns.erase (unique (ns.begin (), ns.end ()), ns.end ()); return ns; }; diff --git a/libbuild2/scope.cxx b/libbuild2/scope.cxx index be2669d..c1c5ed7 100644 --- a/libbuild2/scope.cxx +++ b/libbuild2/scope.cxx @@ -685,6 +685,8 @@ namespace build2 pair> scope:: find_target_type (name& n, const location& loc, const target_type* tt) const { + // NOTE: see also functions-name.cxx:filter() if changing anything here. + optional ext; string& v (n.value); -- cgit v1.1