From 2045ea392013b835c17e865b8d4db8bfa507ef2b Mon Sep 17 00:00:00 2001 From: Alexei Podtelezhnikov Date: Tue, 3 Nov 2026 10:25:11 -0500 Subject: [PATCH] [base] Use unsigned zero-based refcounts. This reverts 67cf7a88 to unsigned refcounts, with conditional decrements. * include/freetype/internal/ftobjs.c (FT_Face_InternalRec, FT_LibraryRec): Make `refcount' unsigned. * src/base/ftobjs.c (FT_New_Library, ft_open_face_internal): Keep it zero. (FT_Done_Library, FT_Done_Face): ... and decrement it conditionally. --- include/freetype/internal/ftobjs.h | 4 ++-- src/base/ftobjs.c | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h index f97262ffa..eeb8dcbcc 100644 --- a/include/freetype/internal/ftobjs.h +++ b/include/freetype/internal/ftobjs.h @@ -386,7 +386,7 @@ FT_BEGIN_HEADER FT_Char no_stem_darkening; FT_Int32 random_seed; - FT_Int refcount; + FT_UInt refcount; } FT_Face_InternalRec; @@ -916,7 +916,7 @@ FT_BEGIN_HEADER FT_Vector lcd_geometry[3]; /* RGB subpixel positions */ #endif - FT_Int refcount; + FT_UInt refcount; } FT_LibraryRec; diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index acefdf46f..2c73df47a 100644 --- a/src/base/ftobjs.c +++ b/src/base/ftobjs.c @@ -2838,8 +2838,6 @@ internal->transform_delta.x = 0; internal->transform_delta.y = 0; - internal->refcount = 1; - internal->no_stem_darkening = -1; } @@ -2970,9 +2968,11 @@ error = FT_ERR( Invalid_Face_Handle ); if ( face && face->driver ) { - face->internal->refcount--; if ( face->internal->refcount > 0 ) + { + face->internal->refcount--; error = FT_Err_Ok; + } else { driver = face->driver; @@ -5525,8 +5525,6 @@ library->version_minor = FREETYPE_MINOR; library->version_patch = FREETYPE_PATCH; - library->refcount = 1; - /* That's ok now */ *alibrary = library; @@ -5576,9 +5574,11 @@ if ( !library ) return FT_THROW( Invalid_Library_Handle ); - library->refcount--; if ( library->refcount > 0 ) + { + library->refcount--; goto Exit; + } memory = library->memory;