This replaces TLB_MultiByteToBSTR and _SHStrDupAToBSTR.
-- v2: https://gitlab.winehq.org/wine/wine/-/merge_requests/3191
From: Alex Henrie alexhenrie24@gmail.com
--- include/Makefile.in | 1 + include/atlconv.h | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 include/atlconv.h
diff --git a/include/Makefile.in b/include/Makefile.in index e9f0aa8d5fb..a0058266e28 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -27,6 +27,7 @@ SOURCES = \ asysta.idl \ atlbase.h \ atlcom.h \ + atlconv.h \ atliface.idl \ atlthunk.h \ atlwin.h \ diff --git a/include/atlconv.h b/include/atlconv.h new file mode 100644 index 00000000000..bc57937425d --- /dev/null +++ b/include/atlconv.h @@ -0,0 +1,35 @@ +/* + * Copyright 2023 Alex Henrie + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __ATLCONV_H__ +#define __ATLCONV_H__ + +inline BSTR A2BSTR(const char *s) +{ + BSTR ret; + int len; + + len = MultiByteToWideChar(CP_ACP, 0, s, -1, NULL, 0); + ret = SysAllocStringLen(NULL, len - 1); + if (!ret) return NULL; + MultiByteToWideChar(CP_ACP, 0, s, -1, ret, len); + + return ret; +} + +#endif /* __ATLCONV_H__ */
From: Alex Henrie alexhenrie24@gmail.com
--- dlls/oleaut32/typelib.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-)
diff --git a/dlls/oleaut32/typelib.c b/dlls/oleaut32/typelib.c index d92d0234c6c..95a1ea00eda 100644 --- a/dlls/oleaut32/typelib.c +++ b/dlls/oleaut32/typelib.c @@ -69,6 +69,7 @@ #include "typelib.h" #include "wine/debug.h" #include "variant.h" +#include "atlconv.h" #include "wine/asm.h" #include "wine/heap.h" #include "wine/list.h" @@ -1644,18 +1645,6 @@ static inline void TLB_FreeCustData(struct list *custdata_list) } }
-static BSTR TLB_MultiByteToBSTR(const char *ptr) -{ - DWORD len; - BSTR ret; - - len = MultiByteToWideChar(CP_ACP, 0, ptr, -1, NULL, 0); - ret = SysAllocStringLen(NULL, len - 1); - if (!ret) return ret; - MultiByteToWideChar(CP_ACP, 0, ptr, -1, ret, len); - return ret; -} - static inline TLBFuncDesc *TLB_get_funcdesc_by_memberid(ITypeInfoImpl *typeinfo, MEMBERID memid) { int i; @@ -3610,7 +3599,7 @@ static ITypeLib2* ITypeLib2_Constructor_MSFT(LPVOID pLib, DWORD dwTLBLength) size >>= 2; name = heap_alloc_zero(size+1); MSFT_Read(name, size, &cx, DO_NOT_SEEK); - pImpLib->name = TLB_MultiByteToBSTR(name); + pImpLib->name = A2BSTR(name); heap_free(name);
pImpLib->guid = MSFT_ReadGuid(oGuid, &cx); @@ -3717,7 +3706,7 @@ static TLBString *SLTG_ReadName(const char *pNameTable, int offset, ITypeLibImpl return tlbstr; }
- tmp_str = TLB_MultiByteToBSTR(pNameTable + offset); + tmp_str = A2BSTR(pNameTable + offset); tlbstr = TLB_append_str(&lib->name_list, tmp_str); SysFreeString(tmp_str);
@@ -3939,7 +3928,7 @@ static sltg_ref_lookup_t *SLTG_DoRefs(SLTG_RefInfo *pRef, ITypeLibImpl *pTL, if(fname[len-1] != '#') FIXME("fname = %s\n", fname); fname[len-1] = '\0'; - import->name = TLB_MultiByteToBSTR(fname); + import->name = A2BSTR(fname); list_add_tail(&pTL->implib_list, &import->entry); } ref_type->pImpTLInfo = import;
From: Alex Henrie alexhenrie24@gmail.com
--- dlls/shlwapi/string.c | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-)
diff --git a/dlls/shlwapi/string.c b/dlls/shlwapi/string.c index 2c894198239..be2b55e9d02 100644 --- a/dlls/shlwapi/string.c +++ b/dlls/shlwapi/string.c @@ -36,6 +36,7 @@ #include "shlobj.h" #include "mlang.h" #include "ddeml.h" +#include "atlconv.h" #include "wine/debug.h"
#include "resource.h" @@ -370,29 +371,6 @@ HRESULT WINAPI StrRetToStrW(LPSTRRET lpStrRet, const ITEMIDLIST *pidl, LPWSTR *p return hRet; }
-/* Makes a Unicode copy of an ANSI string using SysAllocString() */ -static HRESULT _SHStrDupAToBSTR(LPCSTR src, BSTR *pBstrOut) -{ - *pBstrOut = NULL; - - if (src) - { - INT len = MultiByteToWideChar(CP_ACP, 0, src, -1, NULL, 0); - WCHAR* szTemp = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); - - if (szTemp) - { - MultiByteToWideChar(CP_ACP, 0, src, -1, szTemp, len); - *pBstrOut = SysAllocString(szTemp); - HeapFree(GetProcessHeap(), 0, szTemp); - - if (*pBstrOut) - return S_OK; - } - } - return E_OUTOFMEMORY; -} - /************************************************************************* * StrRetToBSTR [SHLWAPI.@] * @@ -421,11 +399,13 @@ HRESULT WINAPI StrRetToBSTR(STRRET *lpStrRet, LPCITEMIDLIST pidl, BSTR* pBstrOut break;
case STRRET_CSTR: - hRet = _SHStrDupAToBSTR(lpStrRet->u.cStr, pBstrOut); + *pBstrOut = A2BSTR(lpStrRet->u.cStr); + hRet = *pBstrOut ? S_OK : E_OUTOFMEMORY; break;
case STRRET_OFFSET: - hRet = _SHStrDupAToBSTR(((LPCSTR)&pidl->mkid) + lpStrRet->u.uOffset, pBstrOut); + *pBstrOut = A2BSTR(((const char*)&pidl->mkid) + lpStrRet->u.uOffset); + hRet = *pBstrOut ? S_OK : E_OUTOFMEMORY; break;
default:
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=134369
Your paranoid android.
=== debian11 (32 bit report) ===
quartz: dsoundrender: Timeout
On Fri Jun 30 17:30:07 2023 +0000, Nikolay Sivov wrote:
Yes, that makes sense. No reason to have this new helper in tests.
I have dropped the commits that touched tests from this MR. @mstefani do you see any better alternative than to replace the custom helpers in oleaut32 and shlwapi with the helper from the Windows API?