Huw Davies : riched20: Add the ability to create ME_Strings from constants.
Alexandre Julliard
julliard at winehq.org
Fri Oct 7 14:46:47 CDT 2016
Module: wine
Branch: master
Commit: 1abe4cc738699f72479e72712b8fdb36e3a91431
URL: http://source.winehq.org/git/wine.git/?a=commit;h=1abe4cc738699f72479e72712b8fdb36e3a91431
Author: Huw Davies <huw at codeweavers.com>
Date: Fri Oct 7 10:49:33 2016 +0100
riched20: Add the ability to create ME_Strings from constants.
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/riched20/editor.h | 1 +
dlls/riched20/editstr.h | 1 +
dlls/riched20/string.c | 37 ++++++++++++++++++++++++++++++++-----
3 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index b0a8a1a..24c856b 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -100,6 +100,7 @@ void ME_DumpDocument(ME_TextBuffer *buffer) DECLSPEC_HIDDEN;
/* string.c */
ME_String *ME_MakeStringN(LPCWSTR szText, int nMaxChars) DECLSPEC_HIDDEN;
ME_String *ME_MakeStringR(WCHAR cRepeat, int nMaxChars) DECLSPEC_HIDDEN;
+ME_String *ME_MakeStringConst(const WCHAR *str, int len) DECLSPEC_HIDDEN;
void ME_DestroyString(ME_String *s) DECLSPEC_HIDDEN;
BOOL ME_AppendString(ME_String *s, const WCHAR *append, int len) DECLSPEC_HIDDEN;
ME_String *ME_VSplitString(ME_String *orig, int nVPos) DECLSPEC_HIDDEN;
diff --git a/dlls/riched20/editstr.h b/dlls/riched20/editstr.h
index 35555a9..0e60a3d 100644
--- a/dlls/riched20/editstr.h
+++ b/dlls/riched20/editstr.h
@@ -58,6 +58,7 @@ typedef struct tagME_String
{
WCHAR *szData;
int nLen, nBuffer;
+ void (*free)(struct tagME_String *);
} ME_String;
typedef struct tagME_FontCacheItem
diff --git a/dlls/riched20/string.c b/dlls/riched20/string.c
index ef06bac..47aceca 100644
--- a/dlls/riched20/string.c
+++ b/dlls/riched20/string.c
@@ -27,10 +27,37 @@ static int ME_GetOptimalBuffer(int nLen)
return ((sizeof(WCHAR) * nLen) + 128) & ~63;
}
+static ME_String *make_string( void (*free)(ME_String *) )
+{
+ ME_String *s = heap_alloc( sizeof(*s) );
+
+ if (s) s->free = free;
+ return s;
+}
+
+/* Create a ME_String using the const string provided.
+ * str must exist for the lifetime of the returned ME_String.
+ */
+ME_String *ME_MakeStringConst(const WCHAR *str, int len)
+{
+ ME_String *s = make_string( NULL );
+ if (!s) return NULL;
+
+ s->szData = (WCHAR *)str;
+ s->nLen = len;
+ s->nBuffer = 0;
+ return s;
+}
+
+static void heap_string_free(ME_String *s)
+{
+ heap_free( s->szData );
+}
+
/* Create a buffer (uninitialized string) of size nMaxChars */
static ME_String *ME_MakeStringB(int nMaxChars)
{
- ME_String *s = heap_alloc( sizeof(*s) );
+ ME_String *s = make_string( heap_string_free );
if (!s) return NULL;
s->nLen = nMaxChars;
@@ -69,7 +96,7 @@ ME_String *ME_MakeStringR(WCHAR cRepeat, int nMaxChars)
void ME_DestroyString(ME_String *s)
{
if (!s) return;
- heap_free( s->szData );
+ if (s->free) s->free( s );
heap_free( s );
}
@@ -78,6 +105,7 @@ BOOL ME_InsertString(ME_String *s, int ofs, const WCHAR *insert, int len)
DWORD new_len = s->nLen + len + 1;
WCHAR *new;
+ assert( s->nBuffer ); /* Not a const string */
assert( ofs <= s->nLen );
if( new_len > s->nBuffer )
@@ -104,9 +132,7 @@ ME_String *ME_VSplitString(ME_String *orig, int charidx)
{
ME_String *s;
- /*if (charidx<0) charidx = 0;
- if (charidx>orig->nLen) charidx = orig->nLen;
- */
+ assert(orig->nBuffer); /* Not a const string */
assert(charidx>=0);
assert(charidx<=orig->nLen);
@@ -122,6 +148,7 @@ void ME_StrDeleteV(ME_String *s, int nVChar, int nChars)
{
int end_ofs = nVChar + nChars;
+ assert(s->nBuffer); /* Not a const string */
assert(nChars >= 0);
assert(nVChar >= 0);
assert(end_ofs <= s->nLen);
More information about the wine-cvs
mailing list