riched20: Create macro functions for allocating and freeing memory.

This commit is contained in:
Mike McCormack 2006-10-24 14:26:28 +09:00 committed by Alexandre Julliard
parent e971e0fb89
commit 8939587b19
5 changed files with 31 additions and 29 deletions

View file

@ -77,7 +77,7 @@ static ULONG WINAPI EnumFormatImpl_Release(IEnumFORMATETC *iface)
if(!ref) {
GlobalFree(This->fmtetc);
HeapFree(GetProcessHeap(), 0, This);
richedit_free(This);
}
return ref;
@ -152,7 +152,7 @@ static HRESULT EnumFormatImpl_Create(FORMATETC *fmtetc, UINT fmtetc_cnt, IEnumFO
EnumFormatImpl *ret;
TRACE("\n");
ret = HeapAlloc(GetProcessHeap(), 0, sizeof(EnumFormatImpl));
ret = richedit_alloc(sizeof(EnumFormatImpl));
ret->lpVtbl = &VT_EnumFormatImpl;
ret->ref = 1;
ret->cur = 0;
@ -195,7 +195,7 @@ static ULONG WINAPI DataObjectImpl_Release(IDataObject* iface)
if(This->unicode) GlobalFree(This->unicode);
if(This->rtf) GlobalFree(This->rtf);
if(This->fmtetc) GlobalFree(This->fmtetc);
HeapFree(GetProcessHeap(), 0, This);
richedit_free(This);
}
return ref;
@ -388,7 +388,7 @@ HRESULT ME_GetDataObject(ME_TextEditor *editor, CHARRANGE *lpchrg, LPDATAOBJECT
DataObjectImpl *obj;
TRACE("(%p,%d,%d)\n", editor, lpchrg->cpMin, lpchrg->cpMax);
obj = HeapAlloc(GetProcessHeap(), 0, sizeof(DataObjectImpl));
obj = richedit_alloc(sizeof(DataObjectImpl));
if(cfRTF == 0)
cfRTF = RegisterClipboardFormatA("Rich Text Format");

View file

@ -1998,7 +1998,7 @@ LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lP
/* potentially each char may be a CR, why calculate the exact value with O(N) when
we can just take a bigger buffer? :) */
int crlfmul = (ex->flags & GT_USECRLF) ? 2 : 1;
LPWSTR buffer = HeapAlloc(GetProcessHeap(), 0, (crlfmul*nCount + 1) * sizeof(WCHAR));
LPWSTR buffer = richedit_alloc((crlfmul*nCount + 1) * sizeof(WCHAR));
DWORD buflen = ex->cb;
LRESULT rc;
DWORD flags = 0;
@ -2006,7 +2006,7 @@ LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lP
buflen = ME_GetTextW(editor, buffer, nStart, nCount, ex->flags & GT_USECRLF);
rc = WideCharToMultiByte(ex->codepage, flags, buffer, -1, (LPSTR)lParam, ex->cb, ex->lpDefaultChar, ex->lpUsedDefaultChar);
HeapFree(GetProcessHeap(),0,buffer);
richedit_free(buffer);
return rc;
}
}

View file

@ -21,9 +21,26 @@
#include "editstr.h"
#include "wine/unicode.h"
#define ALLOC_OBJ(type) HeapAlloc(me_heap, 0, sizeof(type))
#define ALLOC_N_OBJ(type, count) HeapAlloc(me_heap, 0, (count)*sizeof(type))
#define FREE_OBJ(ptr) HeapFree(me_heap, 0, ptr)
extern HANDLE me_heap;
static inline void *richedit_alloc( size_t len )
{
return HeapAlloc( me_heap, 0, len );
}
static inline BOOL richedit_free( void *ptr )
{
return HeapFree( me_heap, 0, ptr );
}
static inline void *richedit_realloc( void *ptr, size_t len )
{
return HeapReAlloc( me_heap, 0, ptr, len );
}
#define ALLOC_OBJ(type) richedit_alloc(sizeof(type))
#define ALLOC_N_OBJ(type, count) richedit_alloc((count)*sizeof(type))
#define FREE_OBJ(ptr) richedit_free(ptr)
#define RUN_IS_HIDDEN(run) ((run)->style->fmt.dwMask & CFM_HIDDEN \
&& (run)->style->fmt.dwEffects & CFE_HIDDEN)
@ -264,7 +281,6 @@ ME_DisplayItem *ME_FindItemAtOffset(ME_TextEditor *editor, ME_DIType nItemType,
void ME_StreamInFill(ME_InStream *stream);
int ME_AutoURLDetect(ME_TextEditor *editor, WCHAR curChar);
extern int me_debug;
extern HANDLE me_heap;
extern void DoWrap(ME_TextEditor *editor);
/* writer.c */

View file

@ -86,17 +86,9 @@ static void RTFPutCodePageChar(RTF_Info *info, int c);
* Return pointer to block of size bytes, or NULL if there's
* not enough memory available.
*/
static inline void *RTFAlloc(int size)
{
return HeapAlloc(me_heap, 0, size);
}
static inline void * RTFReAlloc(void *ptr, int size)
{
return HeapReAlloc(me_heap, 0, ptr, size);
}
#define RTFAlloc(size) richedit_alloc(size)
#define RTFReAlloc(ptr, size) richedit_realloc(ptr, size)
#define RTFFree(ptr) richedit_free(ptr)
/*
* Saves a string on the heap and returns a pointer to it.
@ -112,12 +104,6 @@ static inline char *RTFStrSave(char *s)
}
static inline void RTFFree(void *p)
{
HeapFree(me_heap, 0, p);
}
/* ---------------------------------------------------------------------- */

View file

@ -112,7 +112,7 @@ IRichEditOle_fnRelease(IRichEditOle *me)
if (!ref)
{
TRACE ("Destroying %p\n", This);
HeapFree(GetProcessHeap(),0,This);
richedit_free(This);
}
return ref;
}
@ -529,7 +529,7 @@ LRESULT CreateIRichEditOle(ME_TextEditor *editor, LPVOID *ppObj)
{
IRichEditOleImpl *reo;
reo = HeapAlloc(GetProcessHeap(), 0, sizeof(IRichEditOleImpl));
reo = richedit_alloc(sizeof(IRichEditOleImpl));
if (!reo)
return 0;