summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2022-06-24 20:26:31 -0400
committerThomas E. Dickey <dickey@invisible-island.net>2022-07-06 04:27:24 -0400
commitd4a554c9795b109085ec31eedacba6532c18d802 (patch)
tree0691109a1eee149062ad84e09ca160eddc8692f4
parent42c6616499e6ca193a0b764576a6ed8650dd3d7b (diff)
downloadxorg-lib-libXft-d4a554c9795b109085ec31eedacba6532c18d802.tar.gz
reduce clutter with macros for allocating arrays
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
-rw-r--r--src/xftdraw.c14
-rw-r--r--src/xftextent.c10
-rw-r--r--src/xftint.h6
-rw-r--r--src/xftrender.c26
4 files changed, 31 insertions, 25 deletions
diff --git a/src/xftdraw.c b/src/xftdraw.c
index c1bd9a4..4054714 100644
--- a/src/xftdraw.c
+++ b/src/xftdraw.c
@@ -525,7 +525,7 @@ XftDrawString8 (XftDraw *draw,
glyphs = glyphs_local;
else
{
- glyphs = malloc ((size_t)len * sizeof (FT_UInt));
+ glyphs = AllocUIntArray (len);
if (!glyphs)
return;
}
@@ -555,7 +555,7 @@ XftDrawString16 (XftDraw *draw,
glyphs = glyphs_local;
else
{
- glyphs = malloc ((size_t)len * sizeof (FT_UInt));
+ glyphs = AllocUIntArray (len);
if (!glyphs)
return;
}
@@ -586,7 +586,7 @@ XftDrawString32 (XftDraw *draw,
glyphs = glyphs_local;
else
{
- glyphs = malloc ((size_t)len * sizeof (FT_UInt));
+ glyphs = AllocUIntArray (len);
if (!glyphs)
return;
}
@@ -623,7 +623,7 @@ XftDrawStringUtf8 (XftDraw *draw,
{
if (i == size)
{
- glyphs_new = malloc ((size_t)size * 2 * sizeof (FT_UInt));
+ glyphs_new = AllocUIntArray (size * 2);
if (!glyphs_new)
{
if (glyphs != glyphs_local)
@@ -671,7 +671,7 @@ XftDrawStringUtf16 (XftDraw *draw,
{
if (i == size)
{
- glyphs_new = malloc ((size_t)size * 2 * sizeof (FT_UInt));
+ glyphs_new = AllocUIntArray (size * 2);
if (!glyphs_new)
{
if (glyphs != glyphs_local)
@@ -774,7 +774,7 @@ XftDrawCharSpec (XftDraw *draw,
glyphs = glyphs_local;
else
{
- glyphs = malloc ((size_t)len * sizeof (XftGlyphSpec));
+ glyphs = AllocGlyphSpecArray (len);
if (!glyphs)
return;
}
@@ -806,7 +806,7 @@ XftDrawCharFontSpec (XftDraw *draw,
glyphs = glyphs_local;
else
{
- glyphs = malloc ((size_t)len * sizeof (XftGlyphFontSpec));
+ glyphs = AllocGlyphFontSpecArray (len);
if (!glyphs)
return;
}
diff --git a/src/xftextent.c b/src/xftextent.c
index c0a141a..920edf1 100644
--- a/src/xftextent.c
+++ b/src/xftextent.c
@@ -130,7 +130,7 @@ XftTextExtents8 (Display *dpy,
glyphs = glyphs_local;
else
{
- glyphs = malloc ((size_t)len * sizeof (FT_UInt));
+ glyphs = AllocUIntArray (len);
if (!glyphs)
{
memset (extents, '\0', sizeof (XGlyphInfo));
@@ -161,7 +161,7 @@ XftTextExtents16 (Display *dpy,
glyphs = glyphs_local;
else
{
- glyphs = malloc ((size_t)len * sizeof (FT_UInt));
+ glyphs = AllocUIntArray (len);
if (!glyphs)
{
memset (extents, '\0', sizeof (XGlyphInfo));
@@ -192,7 +192,7 @@ XftTextExtents32 (Display *dpy,
glyphs = glyphs_local;
else
{
- glyphs = malloc ((size_t)len * sizeof (FT_UInt));
+ glyphs = AllocUIntArray (len);
if (!glyphs)
{
memset (extents, '\0', sizeof (XGlyphInfo));
@@ -229,7 +229,7 @@ XftTextExtentsUtf8 (Display *dpy,
{
if (i == size)
{
- glyphs_new = malloc ((size_t)size * 2 * sizeof (FT_UInt));
+ glyphs_new = AllocUIntArray (size * 2);
if (!glyphs_new)
{
if (glyphs != glyphs_local)
@@ -276,7 +276,7 @@ XftTextExtentsUtf16 (Display *dpy,
{
if (i == size)
{
- glyphs_new = malloc ((size_t)size * 2 * sizeof (FT_UInt));
+ glyphs_new = AllocUIntArray (size * 2);
if (!glyphs_new)
{
if (glyphs != glyphs_local)
diff --git a/src/xftint.h b/src/xftint.h
index 6260d4f..f35823f 100644
--- a/src/xftint.h
+++ b/src/xftint.h
@@ -290,6 +290,12 @@ extern XftDisplayInfo *_XftDisplayInfo;
#define XFT_MEM_GLYPH 3
#define XFT_MEM_NUM 4
+#define AllocTypedArray(n,type) malloc ((size_t)(n) * sizeof (type))
+#define AllocUIntArray(n) AllocTypedArray(n, FT_UInt)
+#define AllocGlyphElt8Array(n) AllocTypedArray(n, XGlyphElt8)
+#define AllocGlyphSpecArray(n) AllocTypedArray(n, XftGlyphSpec)
+#define AllocGlyphFontSpecArray(n) AllocTypedArray(n, XftGlyphFontSpec)
+
/* xftcore.c */
void
XftRectCore (XftDraw *draw,
diff --git a/src/xftrender.c b/src/xftrender.c
index dee7943..37bb499 100644
--- a/src/xftrender.c
+++ b/src/xftrender.c
@@ -269,7 +269,7 @@ XftGlyphSpecRender (Display *dpy,
elts = elts_local;
if (nelt > NUM_ELT_LOCAL)
{
- elts = malloc ((size_t)nelt * sizeof (XGlyphElt8));
+ elts = AllocGlyphElt8Array (nelt);
if (!elts)
goto bail2;
}
@@ -369,7 +369,7 @@ XftCharSpecRender (Display *dpy,
glyphs = glyphs_local;
else
{
- glyphs = malloc ((size_t)len * sizeof (XftGlyphSpec));
+ glyphs = AllocGlyphSpecArray (len);
if (!glyphs)
return;
}
@@ -557,7 +557,7 @@ XftGlyphFontSpecRender (Display *dpy,
elts = elts_local;
if (nelt > NUM_ELT_LOCAL)
{
- elts = malloc ((size_t)nelt * sizeof (XGlyphElt8));
+ elts = AllocGlyphElt8Array (nelt);
if (!elts)
goto bail2;
}
@@ -662,7 +662,7 @@ XftCharFontSpecRender (Display *dpy,
glyphs = glyphs_local;
else
{
- glyphs = malloc ((size_t)len * sizeof (XftGlyphFontSpec));
+ glyphs = AllocGlyphFontSpecArray (len);
if (!glyphs)
return;
}
@@ -702,7 +702,7 @@ XftTextRender8 (Display *dpy,
glyphs = glyphs_local;
else
{
- glyphs = malloc ((size_t)len * sizeof (FT_UInt));
+ glyphs = AllocUIntArray (len);
if (!glyphs)
return;
}
@@ -737,7 +737,7 @@ XftTextRender16 (Display *dpy,
glyphs = glyphs_local;
else
{
- glyphs = malloc ((size_t)len * sizeof (FT_UInt));
+ glyphs = AllocUIntArray (len);
if (!glyphs)
return;
}
@@ -772,7 +772,7 @@ XftTextRender16BE (Display *dpy,
glyphs = glyphs_local;
else
{
- glyphs = malloc ((size_t)len * sizeof (FT_UInt));
+ glyphs = AllocUIntArray (len);
if (!glyphs)
return;
}
@@ -808,7 +808,7 @@ XftTextRender16LE (Display *dpy,
glyphs = glyphs_local;
else
{
- glyphs = malloc ((size_t)len * sizeof (FT_UInt));
+ glyphs = AllocUIntArray (len);
if (!glyphs)
return;
}
@@ -844,7 +844,7 @@ XftTextRender32 (Display *dpy,
glyphs = glyphs_local;
else
{
- glyphs = malloc ((size_t)len * sizeof (FT_UInt));
+ glyphs = AllocUIntArray (len);
if (!glyphs)
return;
}
@@ -879,7 +879,7 @@ XftTextRender32BE (Display *dpy,
glyphs = glyphs_local;
else
{
- glyphs = malloc ((size_t)len * sizeof (FT_UInt));
+ glyphs = AllocUIntArray (len);
if (!glyphs)
return;
}
@@ -918,7 +918,7 @@ XftTextRender32LE (Display *dpy,
glyphs = glyphs_local;
else
{
- glyphs = malloc ((size_t)len * sizeof (FT_UInt));
+ glyphs = AllocUIntArray (len);
if (!glyphs)
return;
}
@@ -963,7 +963,7 @@ XftTextRenderUtf8 (Display *dpy,
{
if (i == size)
{
- glyphs_new = malloc ((size_t)size * 2 * sizeof (FT_UInt));
+ glyphs_new = AllocUIntArray (size * 2);
if (!glyphs_new)
{
if (glyphs != glyphs_local)
@@ -1016,7 +1016,7 @@ XftTextRenderUtf16 (Display *dpy,
{
if (i == size)
{
- glyphs_new = malloc ((size_t)size * 2 * sizeof (FT_UInt));
+ glyphs_new = AllocUIntArray (size * 2);
if (!glyphs_new)
{
if (glyphs != glyphs_local)