combase: Move length from hstring_private to hstring_header.
Signed-off-by: Bernhard Kölbl <besentv@gmail.com> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
059795be42
commit
f7609ac2e6
|
@ -31,13 +31,13 @@ WINE_DEFAULT_DEBUG_CHANNEL(winstring);
|
|||
struct hstring_header
|
||||
{
|
||||
UINT32 flags;
|
||||
UINT32 length;
|
||||
};
|
||||
|
||||
struct hstring_private
|
||||
{
|
||||
struct hstring_header header;
|
||||
LPWSTR buffer;
|
||||
UINT32 length;
|
||||
LONG refcount;
|
||||
};
|
||||
|
||||
|
@ -69,7 +69,7 @@ static BOOL alloc_string(UINT32 len, HSTRING *out)
|
|||
|
||||
priv->header.flags = 0;
|
||||
priv->buffer = (LPWSTR)(priv + 1);
|
||||
priv->length = len;
|
||||
priv->header.length = len;
|
||||
priv->refcount = 1;
|
||||
priv->buffer[len] = '\0';
|
||||
|
||||
|
@ -126,7 +126,7 @@ HRESULT WINAPI WindowsCreateStringReference(LPCWSTR ptr, UINT32 len,
|
|||
return E_POINTER;
|
||||
|
||||
priv->buffer = (LPWSTR)ptr;
|
||||
priv->length = len;
|
||||
priv->header.length = len;
|
||||
priv->header.flags = HSTRING_REFERENCE_FLAG;
|
||||
|
||||
*out = (HSTRING)priv;
|
||||
|
@ -168,7 +168,7 @@ HRESULT WINAPI WindowsDuplicateString(HSTRING str, HSTRING *out)
|
|||
return S_OK;
|
||||
}
|
||||
if (priv->header.flags & HSTRING_REFERENCE_FLAG)
|
||||
return WindowsCreateString(priv->buffer, priv->length, out);
|
||||
return WindowsCreateString(priv->buffer, priv->header.length, out);
|
||||
InterlockedIncrement(&priv->refcount);
|
||||
*out = str;
|
||||
return S_OK;
|
||||
|
@ -233,7 +233,7 @@ HRESULT WINAPI WindowsPromoteStringBuffer(HSTRING_BUFFER buf, HSTRING *out)
|
|||
*out = NULL;
|
||||
return S_OK;
|
||||
}
|
||||
if (priv->buffer[priv->length] != 0 || priv->header.flags & HSTRING_REFERENCE_FLAG || priv->refcount != 1)
|
||||
if (priv->buffer[priv->header.length] != 0 || priv->header.flags & HSTRING_REFERENCE_FLAG || priv->refcount != 1)
|
||||
return E_INVALIDARG;
|
||||
*out = (HSTRING)priv;
|
||||
return S_OK;
|
||||
|
@ -250,7 +250,7 @@ UINT32 WINAPI WindowsGetStringLen(HSTRING str)
|
|||
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
return priv->length;
|
||||
return priv->header.length;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
|
@ -269,7 +269,7 @@ LPCWSTR WINAPI WindowsGetStringRawBuffer(HSTRING str, UINT32 *len)
|
|||
return empty;
|
||||
}
|
||||
if (len)
|
||||
*len = priv->length;
|
||||
*len = priv->header.length;
|
||||
return priv->buffer;
|
||||
}
|
||||
|
||||
|
@ -290,7 +290,7 @@ HRESULT WINAPI WindowsStringHasEmbeddedNull(HSTRING str, BOOL *out)
|
|||
*out = FALSE;
|
||||
return S_OK;
|
||||
}
|
||||
for (i = 0; i < priv->length; i++)
|
||||
for (i = 0; i < priv->header.length; i++)
|
||||
{
|
||||
if (priv->buffer[i] == '\0')
|
||||
{
|
||||
|
@ -363,16 +363,16 @@ HRESULT WINAPI WindowsConcatString(HSTRING str1, HSTRING str2, HSTRING *out)
|
|||
return WindowsDuplicateString(str2, out);
|
||||
if (str2 == NULL)
|
||||
return WindowsDuplicateString(str1, out);
|
||||
if (!priv1->length && !priv2->length)
|
||||
if (!priv1->header.length && !priv2->header.length)
|
||||
{
|
||||
*out = NULL;
|
||||
return S_OK;
|
||||
}
|
||||
if (!alloc_string(priv1->length + priv2->length, out))
|
||||
if (!alloc_string(priv1->header.length + priv2->header.length, out))
|
||||
return E_OUTOFMEMORY;
|
||||
priv = impl_from_HSTRING(*out);
|
||||
memcpy(priv->buffer, priv1->buffer, priv1->length * sizeof(*priv1->buffer));
|
||||
memcpy(priv->buffer + priv1->length, priv2->buffer, priv2->length * sizeof(*priv2->buffer));
|
||||
memcpy(priv->buffer, priv1->buffer, priv1->header.length * sizeof(*priv1->buffer));
|
||||
memcpy(priv->buffer + priv1->header.length, priv2->buffer, priv2->header.length * sizeof(*priv2->buffer));
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
@ -387,7 +387,7 @@ BOOL WINAPI WindowsIsStringEmpty(HSTRING str)
|
|||
|
||||
if (str == NULL)
|
||||
return TRUE;
|
||||
return priv->length == 0;
|
||||
return priv->header.length == 0;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
|
@ -412,12 +412,12 @@ HRESULT WINAPI WindowsCompareStringOrdinal(HSTRING str1, HSTRING str2, INT32 *re
|
|||
if (str1)
|
||||
{
|
||||
buf1 = priv1->buffer;
|
||||
len1 = priv1->length;
|
||||
len1 = priv1->header.length;
|
||||
}
|
||||
if (str2)
|
||||
{
|
||||
buf2 = priv2->buffer;
|
||||
len2 = priv2->length;
|
||||
len2 = priv2->header.length;
|
||||
}
|
||||
*res = CompareStringOrdinal(buf1, len1, buf2, len2, FALSE) - CSTR_EQUAL;
|
||||
return S_OK;
|
||||
|
@ -434,19 +434,19 @@ HRESULT WINAPI WindowsTrimStringStart(HSTRING str1, HSTRING str2, HSTRING *out)
|
|||
|
||||
TRACE("(%p, %p, %p)\n", str1, str2, out);
|
||||
|
||||
if (!out || !str2 || !priv2->length)
|
||||
if (!out || !str2 || !priv2->header.length)
|
||||
return E_INVALIDARG;
|
||||
if (!str1)
|
||||
{
|
||||
*out = NULL;
|
||||
return S_OK;
|
||||
}
|
||||
for (start = 0; start < priv1->length; start++)
|
||||
for (start = 0; start < priv1->header.length; start++)
|
||||
{
|
||||
if (!wmemchr(priv2->buffer, priv1->buffer[start], priv2->length))
|
||||
if (!wmemchr(priv2->buffer, priv1->buffer[start], priv2->header.length))
|
||||
break;
|
||||
}
|
||||
return start ? WindowsCreateString(&priv1->buffer[start], priv1->length - start, out) :
|
||||
return start ? WindowsCreateString(&priv1->buffer[start], priv1->header.length - start, out) :
|
||||
WindowsDuplicateString(str1, out);
|
||||
}
|
||||
|
||||
|
@ -461,18 +461,18 @@ HRESULT WINAPI WindowsTrimStringEnd(HSTRING str1, HSTRING str2, HSTRING *out)
|
|||
|
||||
TRACE("(%p, %p, %p)\n", str1, str2, out);
|
||||
|
||||
if (!out || !str2 || !priv2->length)
|
||||
if (!out || !str2 || !priv2->header.length)
|
||||
return E_INVALIDARG;
|
||||
if (!str1)
|
||||
{
|
||||
*out = NULL;
|
||||
return S_OK;
|
||||
}
|
||||
for (len = priv1->length; len > 0; len--)
|
||||
for (len = priv1->header.length; len > 0; len--)
|
||||
{
|
||||
if (!wmemchr(priv2->buffer, priv1->buffer[len - 1], priv2->length))
|
||||
if (!wmemchr(priv2->buffer, priv1->buffer[len - 1], priv2->header.length))
|
||||
break;
|
||||
}
|
||||
return (len < priv1->length) ? WindowsCreateString(priv1->buffer, len, out) :
|
||||
return (len < priv1->header.length) ? WindowsCreateString(priv1->buffer, len, out) :
|
||||
WindowsDuplicateString(str1, out);
|
||||
}
|
||||
|
|
|
@ -512,6 +512,7 @@ static void test_hstring_struct(void)
|
|||
prv = CONTAINING_RECORD(str, struct hstring_private, header);
|
||||
|
||||
ok(prv->header.flags == 0, "Expected 0 in flags field, got %#x.\n", prv->header.flags);
|
||||
ok(prv->header.length == 6, "Expected 6 in length field, got %u.\n", prv->header.length);
|
||||
todo_wine
|
||||
ok(prv->header.str == prv->buffer, "Expected str to point at buffer, instead pointing at %p.\n", prv->header.str);
|
||||
todo_wine
|
||||
|
@ -546,6 +547,7 @@ static void test_hstring_struct(void)
|
|||
|
||||
ok(prv == prv2, "Pointers not identical.\n");
|
||||
ok(prv2->header.flags == 1, "Expected HSTRING_REFERENCE_FLAG to be set, got %#x.\n", prv2->header.flags);
|
||||
ok(prv2->header.length == 6, "Expected 6 in length field, got %u.\n", prv2->header.length);
|
||||
todo_wine
|
||||
ok(prv2->header.str == input_string, "Expected str to point at input_string, instead pointing at %p.\n", prv2->header.str);
|
||||
|
||||
|
|
Loading…
Reference in New Issue