Make Unicode strings 'static const' (part 4)
Francois Gouget
fgouget at free.fr
Mon Apr 19 09:13:20 CDT 2004
This last part takes care of the more complex cases where we use the
now-const string in non-const contexts where we don't actually modify
it. In these cases it can be necessary to modify the code slightly, or
add casts when we know it's ok anyway.
Changelog:
* dlls/netapi32/tests/wksta.c
dlls/oleaut32/olefont.c
dlls/oleaut32/typelib2.c
dlls/shell32/shlfsbind.c
dlls/shlwapi/ordinal.c
dlls/urlmon/umon.c
dlls/wininet/http.c
dlls/wsock32/protocol.c
dlls/ole32/storage32.c
Make Unicode strings 'static const'.
wksta.c: There's no need for an empty string here, a NULL pointer
will do just as well.
olefont.c: Although not const, lpstrName is not modified in this
context.
typelib2.c: Our internal functions don't actually modify their string
parameter so constify their signature.
shlfsbind.c, ordinal.c, umon.c: *ObjectParam don't actually modify
their parameters so it's ok to pass a const string there.
http.c: Although not const, lpszPath is not modified in this context.
protocol.c: Make lpProtName const to avoid warnings.
storage32.c: Forgot it in a previous patch, just mak the Unicode
strings 'static const'.
Index: dlls/netapi32/tests/wksta.c
===================================================================
RCS file: /var/cvs/wine/dlls/netapi32/tests/wksta.c,v
retrieving revision 1.11
diff -u -r1.11 wksta.c
--- a/dlls/netapi32/tests/wksta.c 5 Apr 2004 20:17:45 -0000 1.11
+++ b/dlls/netapi32/tests/wksta.c 18 Apr 2004 16:57:32 -0000
@@ -62,8 +62,7 @@
static void run_get_comp_name_tests(void)
{
- WCHAR empty[] = {0};
- LPWSTR ws = empty;
+ LPWSTR ws = NULL;
if (!pNetpGetComputerName)
return;
Index: dlls/oleaut32/olefont.c
===================================================================
RCS file: /var/cvs/wine/dlls/oleaut32/olefont.c,v
retrieving revision 1.24
diff -u -r1.24 olefont.c
--- a/dlls/oleaut32/olefont.c 23 Jan 2004 01:51:34 -0000 1.24
+++ b/dlls/oleaut32/olefont.c 18 Apr 2004 16:41:08 -0000
@@ -311,10 +311,10 @@
if (!lpFontDesc) {
FONTDESC fd;
- WCHAR fname[] = { 'S','y','s','t','e','m',0 };
+ static const WCHAR fname[] = { 'S','y','s','t','e','m',0 };
fd.cbSizeofstruct = sizeof(fd);
- fd.lpstrName = fname;
+ fd.lpstrName = (WCHAR*)fname;
fd.cySize.s.Lo = 80000;
fd.cySize.s.Hi = 0;
fd.sWeight = 0;
Index: dlls/oleaut32/typelib2.c
===================================================================
RCS file: /var/cvs/wine/dlls/oleaut32/typelib2.c,v
retrieving revision 1.17
diff -u -r1.17 typelib2.c
--- a/dlls/oleaut32/typelib2.c 15 Mar 2004 20:05:19 -0000 1.17
+++ b/dlls/oleaut32/typelib2.c 18 Apr 2004 16:42:30 -0000
@@ -358,7 +358,7 @@
*/
static int ctl2_encode_name(
ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (used for LCID only). */
- WCHAR *name, /* [I] The name string to encode. */
+ const WCHAR *name, /* [I] The name string to encode. */
char **result) /* [O] A pointer to a pointer to receive the encoded name. */
{
int length;
@@ -402,7 +402,7 @@
*/
static int ctl2_encode_string(
ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (not used?). */
- WCHAR *string, /* [I] The string to encode. */
+ const WCHAR *string, /* [I] The string to encode. */
char **result) /* [O] A pointer to a pointer to receive the encoded string. */
{
int length;
@@ -581,7 +581,7 @@
*/
static int ctl2_alloc_name(
ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
- WCHAR *name) /* [I] The name to store. */
+ const WCHAR *name) /* [I] The name to store. */
{
int length;
int offset;
@@ -624,7 +624,7 @@
*/
static int ctl2_alloc_string(
ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
- WCHAR *string) /* [I] The string to store. */
+ const WCHAR *string) /* [I] The string to store. */
{
int length;
int offset;
@@ -698,7 +698,7 @@
int guidoffset, /* [I] The offset to the GUID for the imported library. */
int major_version, /* [I] The major version number of the imported library. */
int minor_version, /* [I] The minor version number of the imported library. */
- WCHAR *filename) /* [I] The filename of the imported library. */
+ const WCHAR *filename) /* [I] The filename of the imported library. */
{
int length;
int offset;
@@ -1220,7 +1220,7 @@
int guidoffset;
int fileoffset;
MSFT_ImpInfo impinfo;
- WCHAR stdole2tlb[] = { 's','t','d','o','l','e','2','.','t','l','b',0 };
+ static const WCHAR stdole2tlb[] = { 's','t','d','o','l','e','2','.','t','l','b',0 };
foo.guid = IID_StdOle;
foo.hreftype = 2;
Index: dlls/shell32/shlfsbind.c
===================================================================
RCS file: /var/cvs/wine/dlls/shell32/shlfsbind.c,v
retrieving revision 1.3
diff -u -r1.3 shlfsbind.c
--- a/dlls/shell32/shlfsbind.c 27 Jan 2004 00:01:43 -0000 1.3
+++ b/dlls/shell32/shlfsbind.c 18 Apr 2004 16:48:41 -0000
@@ -62,7 +62,7 @@
IFileSystemBindData_fnSetFindData,
};
-static WCHAR wFileSystemBindData[] = {'F','i','l','e',' ','S','y','s','t','e','m',' ','B','i','n','d','D','a','t','a',0};
+static const WCHAR wFileSystemBindData[] = {'F','i','l','e',' ','S','y','s','t','e','m',' ','B','i','n','d','D','a','t','a',0};
HRESULT WINAPI IFileSystemBindData_Constructor(const WIN32_FIND_DATAW *pfd, LPBC *ppV)
{
@@ -93,7 +93,7 @@
bindOpts.grfMode = STGM_CREATE;
bindOpts.dwTickCountDeadline = 0;
IBindCtx_SetBindOptions(*ppV, &bindOpts);
- IBindCtx_RegisterObjectParam(*ppV, wFileSystemBindData, (LPUNKNOWN)sb);
+ IBindCtx_RegisterObjectParam(*ppV, (LPOLESTR)wFileSystemBindData, (LPUNKNOWN)sb);
IFileSystemBindData_Release((IFileSystemBindData*)sb);
}
@@ -113,7 +113,7 @@
if (!pfd)
return E_INVALIDARG;
- ret = IBindCtx_GetObjectParam(pbc, wFileSystemBindData, &pUnk);
+ ret = IBindCtx_GetObjectParam(pbc, (LPOLESTR)wFileSystemBindData, &pUnk);
if (SUCCEEDED(ret))
{
ret = IUnknown_QueryInterface(pUnk, &IID_IFileSystemBindData, (LPVOID *)&pfsbd);
@@ -135,7 +135,7 @@
TRACE("%p, %p\n", pbc, pfd);
- ret = IBindCtx_GetObjectParam(pbc, wFileSystemBindData, &pUnk);
+ ret = IBindCtx_GetObjectParam(pbc, (LPOLESTR)wFileSystemBindData, &pUnk);
if (SUCCEEDED(ret))
{
ret = IUnknown_QueryInterface(pUnk, &IID_IFileSystemBindData, (LPVOID *)&pfsbd);
Index: dlls/shlwapi/ordinal.c
===================================================================
RCS file: /var/cvs/wine/dlls/shlwapi/ordinal.c,v
retrieving revision 1.84
diff -u -r1.84 ordinal.c
--- a/dlls/shlwapi/ordinal.c 12 Apr 2004 22:08:23 -0000 1.84
+++ b/dlls/shlwapi/ordinal.c 18 Apr 2004 17:00:49 -0000
@@ -2437,7 +2437,7 @@
#define SHELL_NO_POLICY 0xffffffff
/* default shell policy registry key */
-static WCHAR strRegistryPolicyW[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o',
+static const WCHAR strRegistryPolicyW[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o',
's','o','f','t','\\','W','i','n','d','o','w','s','\\',
'C','u','r','r','e','n','t','V','e','r','s','i','o','n',
'\\','P','o','l','i','c','i','e','s',0};
@@ -2461,7 +2461,7 @@
HKEY hKey;
if (!lpSubKey)
- lpSubKey = (LPCWSTR)strRegistryPolicyW;
+ lpSubKey = strRegistryPolicyW;
retval = RegOpenKeyW(HKEY_LOCAL_MACHINE, lpSubKey, &hKey);
if (retval != ERROR_SUCCESS)
@@ -3887,7 +3887,7 @@
*/
BOOL WINAPI SHSkipJunction(IBindCtx *pbc, const CLSID *pclsid)
{
- static WCHAR szSkipBinding[] = { 'S','k','i','p',' ',
+ static const WCHAR szSkipBinding[] = { 'S','k','i','p',' ',
'B','i','n','d','i','n','g',' ','C','L','S','I','D','\0' };
BOOL bRet = FALSE;
@@ -3895,7 +3895,7 @@
{
IUnknown* lpUnk;
- if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, szSkipBinding, &lpUnk)))
+ if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, (LPOLESTR)szSkipBinding, &lpUnk)))
{
CLSID clsid;
Index: dlls/urlmon/umon.c
===================================================================
RCS file: /var/cvs/wine/dlls/urlmon/umon.c,v
retrieving revision 1.29
diff -u -r1.29 umon.c
--- a/dlls/urlmon/umon.c 31 Mar 2004 19:58:09 -0000 1.29
+++ b/dlls/urlmon/umon.c 18 Apr 2004 15:11:29 -0000
@@ -41,7 +41,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
/* native urlmon.dll uses this key, too */
-static WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
+static const WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
/*static BOOL registered_wndclass = FALSE;*/
@@ -477,7 +477,7 @@
if(SUCCEEDED(hres)) {
TRACE("Created dummy stream...\n");
- hres = IBindCtx_GetObjectParam(pbc, BSCBHolder, (IUnknown**)&pbscb);
+ hres = IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown**)&pbscb);
if(SUCCEEDED(hres)) {
TRACE("Got IBindStatusCallback...\n");
@@ -1139,16 +1139,16 @@
if (pbc == NULL || pbsc == NULL)
return E_INVALIDARG;
- if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, BSCBHolder, (IUnknown **)&prev)))
+ if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown **)&prev)))
{
- IBindCtx_RevokeObjectParam(pbc, BSCBHolder);
+ IBindCtx_RevokeObjectParam(pbc, (LPOLESTR)BSCBHolder);
if (ppbscPrevious)
*ppbscPrevious = prev;
else
IBindStatusCallback_Release(prev);
}
- return IBindCtx_RegisterObjectParam(pbc, BSCBHolder, (IUnknown *)pbsc);
+ return IBindCtx_RegisterObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown *)pbsc);
}
/***********************************************************************
@@ -1176,11 +1176,11 @@
if (pbc == NULL || pbsc == NULL)
return E_INVALIDARG;
- if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, BSCBHolder, (IUnknown **)&callback)))
+ if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown **)&callback)))
{
if (callback == pbsc)
{
- IBindCtx_RevokeObjectParam(pbc, BSCBHolder);
+ IBindCtx_RevokeObjectParam(pbc, (LPOLESTR)BSCBHolder);
hr = S_OK;
}
IBindStatusCallback_Release(pbsc);
Index: dlls/wininet/http.c
===================================================================
RCS file: /var/cvs/wine/dlls/wininet/http.c,v
retrieving revision 1.58
diff -u -r1.58 http.c
--- a/dlls/wininet/http.c 13 Apr 2004 00:19:58 -0000 1.58
+++ b/dlls/wininet/http.c 18 Apr 2004 17:06:01 -0000
@@ -536,11 +536,12 @@
{
WCHAR buf[MAXHOSTNAME];
WCHAR proxy[MAXHOSTNAME + 15]; /* 15 == "http://" + sizeof(port#) + ":/\0" */
- WCHAR* url, szNul[] = { 0 };
+ WCHAR* url;
+ static const WCHAR szNul[] = { 0 };
URL_COMPONENTSW UrlComponents;
- const WCHAR szHttp[] = { 'h','t','t','p',':','/','/',0 }, szSlash[] = { '/',0 } ;
- const WCHAR szFormat1[] = { 'h','t','t','p',':','/','/','%','s',':','%','d',0 };
- const WCHAR szFormat2[] = { 'h','t','t','p',':','/','/','%','s',':','%','d',0 };
+ static const WCHAR szHttp[] = { 'h','t','t','p',':','/','/',0 }, szSlash[] = { '/',0 } ;
+ static const WCHAR szFormat1[] = { 'h','t','t','p',':','/','/','%','s',':','%','d',0 };
+ static const WCHAR szFormat2[] = { 'h','t','t','p',':','/','/','%','s',':','%','d',0 };
int len;
memset( &UrlComponents, 0, sizeof UrlComponents );
@@ -559,7 +560,7 @@
return FALSE;
if( !lpwhr->lpszPath )
- lpwhr->lpszPath = szNul;
+ lpwhr->lpszPath = (LPWSTR)szNul;
TRACE("server='%s' path='%s'\n",
debugstr_w(lpwhs->lpszServerName), debugstr_w(lpwhr->lpszPath));
/* for constant 15 see above */
Index: dlls/wsock32/protocol.c
===================================================================
RCS file: /var/cvs/wine/dlls/wsock32/protocol.c,v
retrieving revision 1.15
diff -u -r1.15 protocol.c
--- a/dlls/wsock32/protocol.c 22 Mar 2004 20:37:40 -0000 1.15
+++ b/dlls/wsock32/protocol.c 18 Apr 2004 17:07:00 -0000
@@ -53,11 +53,11 @@
/* name of the protocols
*/
-static WCHAR NameIpx[] = {'I', 'P', 'X', '\0'};
-static WCHAR NameSpx[] = {'S', 'P', 'X', '\0'};
-static WCHAR NameSpxII[] = {'S', 'P', 'X', ' ', 'I', 'I', '\0'};
-static WCHAR NameTcp[] = {'T', 'C', 'P', '/', 'I', 'P', '\0'};
-static WCHAR NameUdp[] = {'U', 'D', 'P', '/', 'I', 'P', '\0'};
+static const WCHAR NameIpx[] = {'I', 'P', 'X', '\0'};
+static const WCHAR NameSpx[] = {'S', 'P', 'X', '\0'};
+static const WCHAR NameSpxII[] = {'S', 'P', 'X', ' ', 'I', 'I', '\0'};
+static const WCHAR NameTcp[] = {'T', 'C', 'P', '/', 'I', 'P', '\0'};
+static const WCHAR NameUdp[] = {'U', 'D', 'P', '/', 'I', 'P', '\0'};
/*****************************************************************************
* WSOCK32_EnterSingleProtocol [internal]
@@ -79,7 +79,7 @@
LPDWORD lpSize, BOOL unicode)
{ DWORD dwLength = 0, dwOldSize = *lpSize;
INT iAnz = 1;
- WCHAR *lpProtName = NULL;
+ const WCHAR* lpProtName = NULL;
*lpSize = sizeof( PROTOCOL_INFOA);
switch (iProtocol) {
Index: dlls/ole32/storage32.c
===================================================================
RCS file: /var/cvs/wine/dlls/ole32/storage32.c,v
retrieving revision 1.47
diff -u -r1.47 storage32.c
--- a/dlls/ole32/storage32.c 23 Jan 2004 22:51:42 -0000 1.47
+++ b/dlls/ole32/storage32.c 18 Apr 2004 14:12:04 -0000
@@ -6663,7 +6663,7 @@
HKEY hkey, hkeyclsid;
LPWSTR buffer = NULL;
BOOL found = FALSE;
- const WCHAR szclsid[] = { 'C','L','S','I','D',0 };
+ static const WCHAR szclsid[] = { 'C','L','S','I','D',0 };
TRACE("Finding CLSID for %s\n", debugstr_w(lpszUserType));
@@ -6770,7 +6770,7 @@
{
HRESULT r;
IStream *stm = 0;
- const WCHAR szCompObj[] = { 1, 'C','o','m','p','O','b','j', 0 };
+ static const WCHAR szCompObj[] = { 1, 'C','o','m','p','O','b','j', 0 };
unsigned char unknown1[12];
unsigned char unknown2[16];
DWORD count;
--
Francois Gouget fgouget at free.fr http://fgouget.free.fr/
145 = 1! + 4! + 5!
More information about the wine-patches
mailing list