It'll be easier to convert this code to use CRT allocation functions if we don't have to worry about the function pointer.
From: Alex Henrie alexhenrie24@gmail.com
--- dlls/riched20/editstr.h | 2 +- dlls/riched20/string.c | 21 +++++---------------- 2 files changed, 6 insertions(+), 17 deletions(-)
diff --git a/dlls/riched20/editstr.h b/dlls/riched20/editstr.h index cc577de14db..58ed380fc1b 100644 --- a/dlls/riched20/editstr.h +++ b/dlls/riched20/editstr.h @@ -54,7 +54,7 @@ typedef struct tagME_String { WCHAR *szData; int nLen, nBuffer; - void (*free)(struct tagME_String *); + BOOL on_heap; } ME_String;
typedef struct tagME_FontCacheItem diff --git a/dlls/riched20/string.c b/dlls/riched20/string.c index cfb149a93e2..6b93b0d6c30 100644 --- a/dlls/riched20/string.c +++ b/dlls/riched20/string.c @@ -27,37 +27,25 @@ 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 ); + ME_String *s = heap_alloc( sizeof(*s) ); if (!s) return NULL;
s->szData = (WCHAR *)str; s->nLen = len; s->nBuffer = 0; + s->on_heap = FALSE; return s; }
-static void heap_string_free(ME_String *s) -{ - heap_free( s->szData ); -} - /* Create a buffer (uninitialized string) of size nMaxChars */ ME_String *ME_MakeStringEmpty(int nMaxChars) { - ME_String *s = make_string( heap_string_free ); + ME_String *s = heap_alloc( sizeof(*s) );
if (!s) return NULL; s->nLen = nMaxChars; @@ -69,6 +57,7 @@ ME_String *ME_MakeStringEmpty(int nMaxChars) return NULL; } s->szData[s->nLen] = 0; + s->on_heap = TRUE; return s; }
@@ -96,7 +85,7 @@ ME_String *ME_MakeStringR(WCHAR cRepeat, int nMaxChars) void ME_DestroyString(ME_String *s) { if (!s) return; - if (s->free) s->free( s ); + if (s->on_heap) heap_free( s->szData ); heap_free( s ); }
On Thu Sep 21 16:19:45 2023 +0000, Huw Davies wrote:
Is there any real reason for this? I'm not convinced the change is worth it (besides `on_heap` is a poor choice since even the constant strings are allocated from the heap).
To me it seems like an unnecessarily complicated approach to managing memory, but yes, I can convert riched20 to use CRT allocation functions without this change.
This merge request was closed by Huw Davies.
Closing, since this is unnecessary.