[PATCH 2/6] [DbgHelp]: now using the unicode regexp routines (instead of ANSI)

Eric Pouech eric.pouech at orange.fr
Mon Jan 2 14:05:54 CST 2012




A+
---

 dlls/dbghelp/symbol.c |  125 +++++++++++++++++++++++++------------------------
 1 files changed, 63 insertions(+), 62 deletions(-)


diff --git a/dlls/dbghelp/symbol.c b/dlls/dbghelp/symbol.c
index add3a1a..0960f86 100644
--- a/dlls/dbghelp/symbol.c
+++ b/dlls/dbghelp/symbol.c
@@ -30,10 +30,8 @@
 #include <limits.h>
 #include <sys/types.h>
 #include <assert.h>
-#ifdef HAVE_REGEX_H
-# include <regex.h>
-#endif
 
+#include "wine/regexw.h"
 #include "wine/debug.h"
 #include "dbghelp_private.h"
 #include "winnls.h"
@@ -136,8 +134,6 @@ static void symt_add_module_ht(struct module* module, struct symt_ht* ht)
     }
 }
 
-#ifdef HAVE_REGEX_H
-
 /* transforms a dbghelp's regular expression into a POSIX one
  * Here are the valid dbghelp reg ex characters:
  *      *       0 or more characters
@@ -147,15 +143,15 @@ static void symt_add_module_ht(struct module* module, struct symt_ht* ht)
  *      +       1 or more of preceding char
  *      escapes \ on #, ?, [, ], *, +. don't work on -
  */
-static void compile_regex(const char* str, int numchar, regex_t* re, BOOL _case)
+static void compile_regexW(const WCHAR* str, int numchar, regexw_t* re, BOOL _case)
 {
-    char *mask, *p;
+    WCHAR       *mask, *p;
     BOOL        in_escape = FALSE;
     unsigned    flags = REG_NOSUB;
 
-    if (numchar == -1) numchar = strlen( str );
+    if (numchar == -1) numchar = strlenW( str );
 
-    p = mask = HeapAlloc( GetProcessHeap(), 0, 2 * numchar + 3 );
+    p = mask = HeapAlloc( GetProcessHeap(), 0, (2 * numchar + 3) * sizeof(WCHAR) );
     *p++ = '^';
 
     while (*str && numchar--)
@@ -188,18 +184,32 @@ static void compile_regex(const char* str, int numchar, regex_t* re, BOOL _case)
     *p++ = '$';
     *p = 0;
     if (_case) flags |= REG_ICASE;
-    if (regcomp(re, mask, flags)) FIXME("Couldn't compile %s\n", mask);
+    if (regcompW(re, mask, flags)) FIXME("Couldn't compile %s\n", wine_dbgstr_w(mask));
     HeapFree(GetProcessHeap(), 0, mask);
 }
 
-static BOOL compile_file_regex(regex_t* re, const char* srcfile)
+static void compile_regex(const char* str, int numchar, regexw_t* re, BOOL _case)
 {
-    char *mask, *p;
+    DWORD       sz;
+    WCHAR*      strW;
+
+    sz = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
+    if ((strW = HeapAlloc(GetProcessHeap(), 0, sz * sizeof(WCHAR))))
+        MultiByteToWideChar(CP_ACP, 0, str, -1, strW, sz);
+
+    compile_regexW(strW, numchar, re, _case);
+    HeapFree(GetProcessHeap(), 0, strW);
+}
+
+static BOOL compile_file_regexW(regexw_t* re, const WCHAR* srcfile)
+{
+    WCHAR *mask, *p;
     BOOL ret;
+    static const WCHAR allW[] = {'.','*',0};
 
-    if (!srcfile || !*srcfile) return regcomp(re, ".*", REG_NOSUB);
+    if (!srcfile || !*srcfile) return regcompW(re, allW, REG_NOSUB);
 
-    p = mask = HeapAlloc(GetProcessHeap(), 0, 5 * strlen(srcfile) + 4);
+    p = mask = HeapAlloc(GetProcessHeap(), 0, (5 * strlenW(srcfile) + 4) * sizeof(WCHAR));
     *p++ = '^';
     while (*srcfile)
     {
@@ -229,61 +239,52 @@ static BOOL compile_file_regex(regex_t* re, const char* srcfile)
     }
     *p++ = '$';
     *p = 0;
-    ret = !regcomp(re, mask, REG_NOSUB);
+    ret = !regcompW(re, mask, REG_NOSUB);
     HeapFree(GetProcessHeap(), 0, mask);
     if (!ret)
     {
-        FIXME("Couldn't compile %s\n", mask);
+        FIXME("Couldn't compile %s\n", wine_dbgstr_w(mask));
         SetLastError(ERROR_INVALID_PARAMETER);
     }
     return ret;
 }
 
-static int match_regexp( const regex_t *re, const char *str )
-{
-    return !regexec( re, str, 0, NULL, 0 );
-}
-
-#else /* HAVE_REGEX_H */
-
-/* if we don't have regexp support, fall back to a simple string comparison */
-
-typedef struct
+static BOOL compile_file_regex(regexw_t* re, const char* srcfile)
 {
-    char *str;
-    BOOL  icase;
-} regex_t;
+    DWORD       sz;
+    WCHAR*      srcfileW;
+    BOOL        ret;
 
-static void compile_regex(const char* str, int numchar, regex_t* re, BOOL _case)
-{
-    if (numchar == -1) numchar = strlen( str );
+    sz = MultiByteToWideChar(CP_ACP, 0, srcfile, -1, NULL, 0);
+    if ((srcfileW = HeapAlloc(GetProcessHeap(), 0, sz * sizeof(WCHAR))))
+        MultiByteToWideChar(CP_ACP, 0, srcfile, -1, srcfileW, sz);
+    ret = compile_file_regexW(re, srcfileW);
+    HeapFree(GetProcessHeap(), 0, srcfileW);
 
-    re->str = HeapAlloc( GetProcessHeap(), 0, numchar + 1 );
-    memcpy( re->str, str, numchar );
-    re->str[numchar] = 0;
-    re->icase = _case;
+    return ret;
 }
 
-static BOOL compile_file_regex(regex_t* re, const char* srcfile)
+static int match_regexpW( const regexw_t *re, const WCHAR *str )
 {
-    if (!srcfile || !*srcfile) re->str = NULL;
-    else compile_regex( srcfile, -1, re, FALSE );
-    return TRUE;
+    return !regexecW( re, str, 0, NULL, 0 );
 }
 
-static int match_regexp( const regex_t *re, const char *str )
+static int match_regexp( const regexw_t *re, const char *str )
 {
-    if (!re->str) return 1;
-    if (re->icase) return !lstrcmpiA( re->str, str );
-    return !strcmp( re->str, str );
-}
+    DWORD       sz;
+    WCHAR*      strW;
+    int         ret;
 
-static void regfree( regex_t *re )
-{
-    HeapFree( GetProcessHeap(), 0, re->str );
-}
+    sz = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
+    if ((strW = HeapAlloc(GetProcessHeap(), 0, sz * sizeof(WCHAR))))
+    {
+        MultiByteToWideChar(CP_ACP, 0, str, -1, strW, sz);
+        ret = match_regexpW(re, strW);
+    } else ret = FALSE;
+    HeapFree(GetProcessHeap(), 0, strW);
 
-#endif /* HAVE_REGEX_H */
+    return ret;
+}
 
 struct symt_compiland* symt_new_compiland(struct module* module, 
                                           unsigned long address, unsigned src_idx)
@@ -832,7 +833,7 @@ static BOOL send_symbol(const struct sym_enum* se, struct module_pair* pair,
     return !se->cb(se->sym_info, se->sym_info->Size, se->user);
 }
 
-static BOOL symt_enum_module(struct module_pair* pair, const regex_t* regex,
+static BOOL symt_enum_module(struct module_pair* pair, const regexw_t* regex,
                              const struct sym_enum* se)
 {
     void*                       ptr;
@@ -1004,7 +1005,7 @@ struct symt_ht* symt_find_nearest(struct module* module, DWORD_PTR addr)
 }
 
 static BOOL symt_enum_locals_helper(struct module_pair* pair,
-                                    regex_t* preg, const struct sym_enum* se,
+                                    regexw_t* preg, const struct sym_enum* se,
                                     struct symt_function* func, const struct vector* v)
 {
     struct symt*        lsym = NULL;
@@ -1062,13 +1063,13 @@ static BOOL symt_enum_locals(struct process* pcs, const char* mask,
     if (sym->symt.tag == SymTagFunction)
     {
         BOOL            ret;
-        regex_t         preg;
+        regexw_t        preg;
 
         compile_regex(mask ? mask : "*", -1, &preg,
                       dbghelp_options & SYMOPT_CASE_INSENSITIVE);
         ret = symt_enum_locals_helper(&pair, &preg, se, (struct symt_function*)sym,
                                       &((struct symt_function*)sym)->vchildren);
-        regfree(&preg);
+        regfreeW(&preg);
         return ret;
     }
     return FALSE;
@@ -1110,7 +1111,7 @@ static BOOL sym_enum(HANDLE hProcess, ULONG64 BaseOfDll, PCSTR Mask,
 {
     struct module_pair  pair;
     const char*         bang;
-    regex_t             mod_regex, sym_regex;
+    regexw_t            mod_regex, sym_regex;
 
     pair.pcs = process_find_by_handle(hProcess);
     if (!pair.pcs) return FALSE;
@@ -1151,8 +1152,8 @@ static BOOL sym_enum(HANDLE hProcess, ULONG64 BaseOfDll, PCSTR Mask,
                 }
             }
         }
-        regfree(&mod_regex);
-        regfree(&sym_regex);
+        regfreeW(&mod_regex);
+        regfreeW(&sym_regex);
         return TRUE;
     }
     pair.requested = module_find_by_addr(pair.pcs, BaseOfDll, DMT_UNKNOWN);
@@ -1169,7 +1170,7 @@ static BOOL sym_enum(HANDLE hProcess, ULONG64 BaseOfDll, PCSTR Mask,
     compile_regex(Mask ? Mask : "*", -1, &sym_regex, 
                   dbghelp_options & SYMOPT_CASE_INSENSITIVE);
     symt_enum_module(&pair, &sym_regex, se);
-    regfree(&sym_regex);
+    regfreeW(&sym_regex);
 
     return TRUE;
 }
@@ -1879,14 +1880,14 @@ DWORD WINAPI UnDecorateSymbolName(PCSTR DecoratedName, PSTR UnDecoratedName,
  */
 BOOL WINAPI SymMatchStringA(PCSTR string, PCSTR re, BOOL _case)
 {
-    regex_t     preg;
+    regexw_t    preg;
     BOOL        ret;
 
     TRACE("%s %s %c\n", string, re, _case ? 'Y' : 'N');
 
     compile_regex(re, -1, &preg, _case);
     ret = match_regexp(&preg, string);
-    regfree(&preg);
+    regfreeW(&preg);
     return ret;
 }
 
@@ -2042,7 +2043,7 @@ BOOL WINAPI SymEnumLines(HANDLE hProcess, ULONG64 base, PCSTR compiland,
     struct module_pair          pair;
     struct hash_table_iter      hti;
     struct symt_ht*             sym;
-    regex_t                     re;
+    regexw_t                    re;
     struct line_info*           dli;
     void*                       ptr;
     SRCCODEINFO                 sci;
@@ -2089,7 +2090,7 @@ BOOL WINAPI SymEnumLines(HANDLE hProcess, ULONG64 base, PCSTR compiland,
             }
         }
     }
-    regfree(&re);
+    regfreeW(&re);
     return TRUE;
 }
 




More information about the wine-patches mailing list