[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2] anuj-distance-field ddfa07c 68/93: [sdf] Add alloc/free func
From: |
Anuj Verma |
Subject: |
[freetype2] anuj-distance-field ddfa07c 68/93: [sdf] Add alloc/free functions. |
Date: |
Sun, 2 Aug 2020 07:04:25 -0400 (EDT) |
branch: anuj-distance-field
commit ddfa07c5da07b73e7633233f66fa2b471d23088c
Author: Anuj Verma <anujv@iitbhilai.ac.in>
Commit: anujverma <anujv@iitbhilai.ac.in>
[sdf] Add alloc/free functions.
* src/sdf/ftsdf.c (*): Add `sdf_alloc' and `sdf_free'
to allocate and deallocate memory respectively.
By using function we can directly use them in the
conditional statements, which is not possible when
using `do {} while ( 0 )'.
* src/sdf/ftsdf.c (SDF_MEMORY_TRACKER_): When not
debugging don't leave the macros empty otherwise
some compiler may emit warning because of empty
`;' semi-colon.
---
[GSoC]ChangeLog | 15 ++++++++
src/sdf/ftsdf.c | 107 +++++++++++++++++++++++++++++++++++---------------------
2 files changed, 82 insertions(+), 40 deletions(-)
diff --git a/[GSoC]ChangeLog b/[GSoC]ChangeLog
index 5faae7a..8bdeb60 100644
--- a/[GSoC]ChangeLog
+++ b/[GSoC]ChangeLog
@@ -1,5 +1,20 @@
2020-07-19 Anuj Verma <anujv@iitbhilai.ac.in>
+ [sdf] Add alloc/free functions.
+
+ * src/sdf/ftsdf.c (*): Add `sdf_alloc' and `sdf_free'
+ to allocate and deallocate memory respectively.
+ By using function we can directly use them in the
+ conditional statements, which is not possible when
+ using `do {} while ( 0 )'.
+
+ * src/sdf/ftsdf.c (SDF_MEMORY_TRACKER_): When not
+ debugging don't leave the macros empty otherwise
+ some compiler may emit warning because of empty
+ `;' semi-colon.
+
+2020-07-19 Anuj Verma <anujv@iitbhilai.ac.in>
+
[sdf] Added new renderer `bsdf'.
* src/sdf/ftsdfrend.* (*): Added new renderer
diff --git a/src/sdf/ftsdf.c b/src/sdf/ftsdf.c
index 8437479..277ce95 100644
--- a/src/sdf/ftsdf.c
+++ b/src/sdf/ftsdf.c
@@ -14,6 +14,17 @@
#ifdef FT_DEBUG_LEVEL_TRACE
+ #undef FT_DEBUG_INNER
+ #undef FT_ASSIGNP_INNER
+
+ #define FT_DEBUG_INNER( exp ) ( _ft_debug_file = __FILE__, \
+ _ft_debug_lineno = line, \
+ (exp) )
+
+ #define FT_ASSIGNP_INNER( p, exp ) ( _ft_debug_file = __FILE__, \
+ _ft_debug_lineno = line, \
+ FT_ASSIGNP( p, exp ) )
+
/* To be used with `FT_Memory::user' in order to track */
/* memory allocations. */
typedef struct SDF_MemoryUser_
@@ -23,39 +34,57 @@
} SDF_MemoryUser;
- /* Use these macros while allocating and deallocating */
+ /* Use these functions while allocating and deallocating */
/* memory. These macros restore the previous user pointer */
/* before calling the allocation functions, which is ess- */
/* ential if the program is compiled with macro */
/* `FT_DEBUG_MEMORY'. */
- #define SDF_ALLOC( ptr, size ) \
- do \
- { \
- SDF_MemoryUser* current_user; \
- \
- \
- current_user = (SDF_MemoryUser*)memory->user; \
- memory->user = current_user->prev_user; \
- \
- if ( !FT_QALLOC( ptr, size ) ) \
- current_user->total_usage += size; \
- \
- memory->user = (void*)current_user; \
- } while ( 0 )
-
- #define SDF_FREE( ptr ) \
- do \
- { \
- SDF_MemoryUser* current_user; \
- \
- \
- current_user = (SDF_MemoryUser*)memory->user; \
- memory->user = current_user->prev_user; \
- \
- FT_FREE( ptr ); \
- \
- memory->user = (void*)current_user; \
- } while ( 0 )
+
+ static FT_Pointer
+ sdf_alloc( FT_Memory memory,
+ FT_Long size,
+ FT_Error* err,
+ FT_Int line )
+ {
+ SDF_MemoryUser* current_user;
+ FT_Pointer ptr;
+ FT_Error error;
+
+
+ current_user = (SDF_MemoryUser*)memory->user;
+ memory->user = current_user->prev_user;
+
+ if ( !FT_QALLOC( ptr, size ) )
+ current_user->total_usage += size;
+
+ memory->user = (void*)current_user;
+ *err = error;
+
+ return ptr;
+ }
+
+ static void
+ sdf_free( FT_Memory memory,
+ FT_Pointer ptr,
+ FT_Int line )
+ {
+ SDF_MemoryUser* current_user;
+
+ current_user = (SDF_MemoryUser*)memory->user;
+ memory->user = current_user->prev_user;
+
+ FT_FREE( ptr );
+
+ memory->user = (void*)current_user;
+ }
+
+ #define SDF_ALLOC( ptr, size ) \
+ ( ptr = sdf_alloc( memory, size, \
+ &error, __LINE__ ), \
+ error != 0 )
+
+ #define SDF_FREE( ptr ) \
+ sdf_free( memory, ptr, __LINE__ ) \
#define SDF_MEMORY_TRACKER_DECLARE() SDF_MemoryUser sdf_memory_user
@@ -77,9 +106,9 @@
#define SDF_FREE FT_FREE
/* Do nothing */
- #define SDF_MEMORY_TRACKER_DECLARE()
- #define SDF_MEMORY_TRACKER_SETUP()
- #define SDF_MEMORY_TRACKER_DONE()
+ #define SDF_MEMORY_TRACKER_DECLARE() do {} while ( 0 )
+ #define SDF_MEMORY_TRACKER_SETUP() do {} while ( 0 )
+ #define SDF_MEMORY_TRACKER_DONE() do {} while ( 0 )
#endif
@@ -314,8 +343,7 @@
goto Exit;
}
- SDF_ALLOC( ptr, sizeof( *ptr ) );
- if ( error == 0 )
+ if ( !SDF_ALLOC( ptr, sizeof( *ptr ) ) )
{
*ptr = null_edge;
*edge = ptr;
@@ -352,8 +380,7 @@
goto Exit;
}
- SDF_ALLOC( ptr, sizeof( *ptr ) );
- if ( error == 0 )
+ if ( !SDF_ALLOC( ptr, sizeof( *ptr ) ) )
{
*ptr = null_contour;
*contour = ptr;
@@ -405,8 +432,7 @@
goto Exit;
}
- SDF_ALLOC( ptr, sizeof( *ptr ) );
- if ( error == 0 )
+ if ( !SDF_ALLOC( ptr, sizeof( *ptr ) ) )
{
*ptr = null_shape;
ptr->memory = memory;
@@ -2669,8 +2695,7 @@
rows = bitmap->rows;
buffer = (FT_Short*)bitmap->buffer;
- SDF_ALLOC( dists, width * rows * sizeof( *dists ) );
- if ( error != 0 )
+ if ( SDF_ALLOC( dists, width * rows * sizeof( *dists ) ) )
goto Exit;
FT_MEM_ZERO( dists, width * rows * sizeof(*dists) );
@@ -3097,6 +3122,7 @@
{
FT_Error error = FT_Err_Ok;
SDF_TRaster* raster = NULL;
+ FT_Int line = __LINE__;
*araster = 0;
@@ -3249,6 +3275,7 @@
sdf_raster_done( FT_Raster raster )
{
FT_Memory memory = (FT_Memory)((SDF_TRaster*)raster)->memory;
+ FT_Int line = __LINE__;
FT_FREE( raster );
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2] anuj-distance-field ddfa07c 68/93: [sdf] Add alloc/free functions.,
Anuj Verma <=