# HG changeset patch # User Markus Mützel # Date 1701710689 -3600 # Mon Dec 04 18:24:49 2023 +0100 # Node ID 6e2b7339e5cdea03ad81b580853f8468f7dcd4e7 # Parent 2fbfc4490921b9aff1443418e1b120fb8a6c5b8a Use native function for symbol name matching on Windows (bug #64975). * sysdep.h, sysdep.cc (symbol_match): Add new class that can efficiently match symbol names cross-platform. * call-stack.cc (call_stack::clear_global_variable_pattern), symtab.cc (symbol_table::clear_function_pattern), * variables.cc (name_matches_any_pattern): Use new class to match symbol names. diff -r 2fbfc4490921 -r 6e2b7339e5cd libinterp/corefcn/call-stack.cc --- a/libinterp/corefcn/call-stack.cc Mon Dec 04 09:49:25 2023 +0100 +++ b/libinterp/corefcn/call-stack.cc Mon Dec 04 18:24:49 2023 +0100 @@ -46,6 +46,7 @@ #include "syminfo.h" #include "symrec.h" #include "symscope.h" +#include "sysdep.h" #include "variables.h" OCTAVE_BEGIN_NAMESPACE(octave) @@ -906,7 +907,7 @@ void call_stack::clear_global_variable_pattern (const std::string& pattern) { - glob_match pat (pattern); + symbol_match pat (pattern); for (auto& nm_ov : m_global_values) { @@ -1130,7 +1131,7 @@ } else { - glob_match pat (pattern); + symbol_match pat (pattern); for (auto& nm_ov : m_global_values) { diff -r 2fbfc4490921 -r 6e2b7339e5cd libinterp/corefcn/symtab.cc --- a/libinterp/corefcn/symtab.cc Mon Dec 04 09:49:25 2023 +0100 +++ b/libinterp/corefcn/symtab.cc Mon Dec 04 18:24:49 2023 +0100 @@ -47,6 +47,7 @@ #include "pt-pr-code.h" #include "symscope.h" #include "symtab.h" +#include "sysdep.h" OCTAVE_BEGIN_NAMESPACE(octave) @@ -438,7 +439,7 @@ void symbol_table::clear_function_pattern (const std::string& pat) { - glob_match pattern (pat); + symbol_match pattern (pat); auto p = m_fcn_table.begin (); diff -r 2fbfc4490921 -r 6e2b7339e5cd libinterp/corefcn/sysdep.cc --- a/libinterp/corefcn/sysdep.cc Mon Dec 04 09:49:25 2023 +0100 +++ b/libinterp/corefcn/sysdep.cc Mon Dec 04 18:24:49 2023 +0100 @@ -99,6 +99,7 @@ #include #include #include +#include #include #endif @@ -431,6 +432,37 @@ #endif } +symbol_match::symbol_match (const std::string pat) +{ + m_pat = pat; + +#if defined (OCTAVE_USE_WINDOWS_API) + m_glob = nullptr; +#else + m_glob = new glob_match (pat); +#endif +} + +symbol_match::~symbol_match () +{ +#if ! defined (OCTAVE_USE_WINDOWS_API) + delete m_glob; +#endif +} + +bool symbol_match::match (const std::string sym) +{ +#if defined (OCTAVE_USE_WINDOWS_API) + // We don't need full POSIX compatibility to match symbol patterns. + // MS DOS-compatible glob patterns should be good enough. + // We also do not need to convert for Unicode characters because symbols are + // ASCII-only. + return PathMatchSpecA (sym.c_str (), m_pat.c_str ()); +#else + return m_glob->match (sym); +#endif +} + void sysdep_init () { // Use a function from libgomp to force loading of OpenMP library. diff -r 2fbfc4490921 -r 6e2b7339e5cd libinterp/corefcn/sysdep.h --- a/libinterp/corefcn/sysdep.h Mon Dec 04 09:49:25 2023 +0100 +++ b/libinterp/corefcn/sysdep.h Mon Dec 04 18:24:49 2023 +0100 @@ -32,6 +32,8 @@ #include +#include "glob-match.h" + #include "lo-ieee.h" #include "lo-sysdep.h" @@ -55,6 +57,25 @@ extern OCTINTERP_API bool drive_or_unc_share (const std::string&); +class OCTINTERP_API symbol_match +{ +public: + + symbol_match (const std::string pattern); + + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (symbol_match) + + ~symbol_match (); + + bool match (const std::string sym); + +private: + + std::string m_pat; + + glob_match *m_glob; +}; + OCTAVE_END_NAMESPACE(octave) #endif diff -r 2fbfc4490921 -r 6e2b7339e5cd libinterp/corefcn/variables.cc --- a/libinterp/corefcn/variables.cc Mon Dec 04 09:49:25 2023 +0100 +++ b/libinterp/corefcn/variables.cc Mon Dec 04 18:24:49 2023 +0100 @@ -948,7 +948,7 @@ } else { - glob_match pattern (patstr); + symbol_match pattern (patstr); if (pattern.match (nm)) {