Skip to content

Commit bdd533f

Browse files
authored
Merge pull request #2802 from Starbuck5/freetype-use-calloc
(Freetype) use calloc where possible
2 parents b8120fb + 2b177bc commit bdd533f

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

src_c/freetype/ft_cache.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ int
134134
_PGFT_Cache_Init(FreeTypeInstance *ft, FontCache *cache)
135135
{
136136
int cache_size = MAX(ft->cache_size - 1, PGFT_MIN_CACHE_SIZE - 1);
137-
int i;
138137

139138
/*
140139
* Make sure this is a power of 2.
@@ -147,18 +146,15 @@ _PGFT_Cache_Init(FreeTypeInstance *ft, FontCache *cache)
147146

148147
cache_size = cache_size + 1;
149148

150-
cache->nodes = _PGFT_malloc((size_t)cache_size * sizeof(FontGlyph *));
149+
cache->nodes = _PGFT_calloc((size_t)cache_size, sizeof(FontGlyph *));
151150
if (!cache->nodes)
152151
return -1;
153-
for (i = 0; i < cache_size; ++i)
154-
cache->nodes[i] = 0;
155-
cache->depths = _PGFT_malloc((size_t)cache_size);
152+
cache->depths = _PGFT_calloc((size_t)cache_size, sizeof(FT_Byte));
156153
if (!cache->depths) {
157154
_PGFT_free(cache->nodes);
158155
cache->nodes = 0;
159156
return -1;
160157
}
161-
memset(cache->depths, 0, cache_size);
162158
cache->free_nodes = 0;
163159
cache->size_mask = (FT_UInt32)(cache_size - 1);
164160

@@ -307,13 +303,12 @@ static CacheNode *
307303
allocate_node(FontCache *cache, const FontRenderMode *render, GlyphIndex_t id,
308304
void *internal)
309305
{
310-
CacheNode *node = _PGFT_malloc(sizeof(CacheNode));
306+
CacheNode *node = _PGFT_calloc(1, sizeof(CacheNode));
311307
FT_UInt32 bucket;
312308

313309
if (!node) {
314310
return 0;
315311
}
316-
memset(node, 0, sizeof(CacheNode));
317312

318313
if (_PGFT_LoadGlyph(&node->glyph, id, render, internal)) {
319314
goto cleanup;

src_c/freetype/ft_wrap.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,11 @@ ft_wrap_init(FreeTypeInstance *ft, pgFontObject *fontobj)
401401
}
402402
fontobj->is_scalable = FT_IS_SCALABLE(font) ? ~0 : 0;
403403

404-
fontobj->_internals = _PGFT_malloc(sizeof(FontInternals));
404+
fontobj->_internals = _PGFT_calloc(1, sizeof(FontInternals));
405405
if (!fontobj->_internals) {
406406
PyErr_NoMemory();
407407
return -1;
408408
}
409-
memset(fontobj->_internals, 0x0, sizeof(FontInternals));
410409

411410
if (_PGFT_LayoutInit(ft, fontobj)) {
412411
_PGFT_free(fontobj->_internals);
@@ -493,12 +492,11 @@ _PGFT_TryLoadFont_RWops(FreeTypeInstance *ft, pgFontObject *fontobj,
493492
return -1;
494493
}
495494

496-
stream = _PGFT_malloc(sizeof(*stream));
495+
stream = _PGFT_calloc(1, sizeof(*stream));
497496
if (!stream) {
498497
PyErr_NoMemory();
499498
return -1;
500499
}
501-
memset(stream, 0, sizeof(*stream));
502500
stream->read = RWops_read;
503501
stream->descriptor.pointer = src;
504502
stream->pos = (unsigned long)position;

src_c/freetype/ft_wrap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ _PGFT_GetFontSized(FreeTypeInstance *, pgFontObject *, Scale_t);
432432
void
433433
_PGFT_BuildScaler(pgFontObject *, FTC_Scaler, Scale_t);
434434
#define _PGFT_malloc PyMem_Malloc
435+
#define _PGFT_calloc PyMem_Calloc
435436
#define _PGFT_free PyMem_Free
436437

437438
#endif

0 commit comments

Comments
 (0)