aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitry Antipov2013-08-04 08:07:18 +0400
committerDmitry Antipov2013-08-04 08:07:18 +0400
commitf0b79313d9be108a17b8a8c689fbf64f6ba75044 (patch)
tree1d1efcbc4ecbeac9f61471c8902c196b90af5a07 /src
parent00f98a9d5c2c1b7fc069478698778ea782cf6667 (diff)
downloademacs-f0b79313d9be108a17b8a8c689fbf64f6ba75044.tar.gz
emacs-f0b79313d9be108a17b8a8c689fbf64f6ba75044.zip
* dispnew.c (glyph_matrix_count, glyph_pool_count):
Move under GLYPH_DEBUG and ENABLE_CHECKING. (new_glyph_matrix, free_glyph_matrix, new_glyph_pool) (free_glyph_pool, check_glyph_memory): Likewise for all users. Adjust comments where appropriate.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog8
-rw-r--r--src/dispnew.c49
2 files changed, 38 insertions, 19 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 69e00cadbe9..8a9de96358d 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
12013-08-04 Dmitry Antipov <dmantipov@yandex.ru>
2
3 * dispnew.c (glyph_matrix_count, glyph_pool_count):
4 Move under GLYPH_DEBUG and ENABLE_CHECKING.
5 (new_glyph_matrix, free_glyph_matrix, new_glyph_pool)
6 (free_glyph_pool, check_glyph_memory): Likewise for
7 all users. Adjust comments where appropriate.
8
12013-08-03 Paul Eggert <eggert@cs.ucla.edu> 92013-08-03 Paul Eggert <eggert@cs.ucla.edu>
2 10
3 * composite.h: Minor fixups. 11 * composite.h: Minor fixups.
diff --git a/src/dispnew.c b/src/dispnew.c
index 522a0e6a30d..c69f4b3bed5 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -148,12 +148,16 @@ int updated_area;
148 148
149struct glyph space_glyph; 149struct glyph space_glyph;
150 150
151#if defined GLYPH_DEBUG && defined ENABLE_CHECKING
152
151/* Counts of allocated structures. These counts serve to diagnose 153/* Counts of allocated structures. These counts serve to diagnose
152 memory leaks and double frees. */ 154 memory leaks and double frees. */
153 155
154static int glyph_matrix_count; 156static int glyph_matrix_count;
155static int glyph_pool_count; 157static int glyph_pool_count;
156 158
159#endif /* GLYPH_DEBUG and ENABLE_CHECKING */
160
157/* If non-null, the frame whose frame matrices are manipulated. If 161/* If non-null, the frame whose frame matrices are manipulated. If
158 null, window matrices are worked on. */ 162 null, window matrices are worked on. */
159 163
@@ -307,9 +311,11 @@ new_glyph_matrix (struct glyph_pool *pool)
307{ 311{
308 struct glyph_matrix *result = xzalloc (sizeof *result); 312 struct glyph_matrix *result = xzalloc (sizeof *result);
309 313
314#if defined GLYPH_DEBUG && defined ENABLE_CHECKING
310 /* Increment number of allocated matrices. This count is used 315 /* Increment number of allocated matrices. This count is used
311 to detect memory leaks. */ 316 to detect memory leaks. */
312 ++glyph_matrix_count; 317 ++glyph_matrix_count;
318#endif
313 319
314 /* Set pool and return. */ 320 /* Set pool and return. */
315 result->pool = pool; 321 result->pool = pool;
@@ -319,10 +325,10 @@ new_glyph_matrix (struct glyph_pool *pool)
319 325
320/* Free glyph matrix MATRIX. Passing in a null MATRIX is allowed. 326/* Free glyph matrix MATRIX. Passing in a null MATRIX is allowed.
321 327
322 The global counter glyph_matrix_count is decremented when a matrix 328 If GLYPH_DEBUG and ENABLE_CHECKING are in effect, the global counter
323 is freed. If the count gets negative, more structures were freed 329 glyph_matrix_count is decremented when a matrix is freed. If the count
324 than allocated, i.e. one matrix was freed more than once or a bogus 330 gets negative, more structures were freed than allocated, i.e. one matrix
325 pointer was passed to this function. 331 was freed more than once or a bogus pointer was passed to this function.
326 332
327 If MATRIX->pool is null, this means that the matrix manages its own 333 If MATRIX->pool is null, this means that the matrix manages its own
328 glyph memory---this is done for matrices on X frames. Freeing the 334 glyph memory---this is done for matrices on X frames. Freeing the
@@ -335,10 +341,12 @@ free_glyph_matrix (struct glyph_matrix *matrix)
335 { 341 {
336 int i; 342 int i;
337 343
344#if defined GLYPH_DEBUG && defined ENABLE_CHECKING
338 /* Detect the case that more matrices are freed than were 345 /* Detect the case that more matrices are freed than were
339 allocated. */ 346 allocated. */
340 if (--glyph_matrix_count < 0) 347 --glyph_matrix_count;
341 emacs_abort (); 348 eassert (glyph_matrix_count >= 0);
349#endif
342 350
343 /* Free glyph memory if MATRIX owns it. */ 351 /* Free glyph memory if MATRIX owns it. */
344 if (matrix->pool == NULL) 352 if (matrix->pool == NULL)
@@ -1310,38 +1318,41 @@ row_equal_p (struct glyph_row *a, struct glyph_row *b, bool mouse_face_p)
1310 See dispextern.h for an overall explanation of glyph pools. 1318 See dispextern.h for an overall explanation of glyph pools.
1311 ***********************************************************************/ 1319 ***********************************************************************/
1312 1320
1313/* Allocate a glyph_pool structure. The structure returned is 1321/* Allocate a glyph_pool structure. The structure returned is initialized
1314 initialized with zeros. The global variable glyph_pool_count is 1322 with zeros. If GLYPH_DEBUG and ENABLE_CHECKING are in effect, the global
1315 incremented for each pool allocated. */ 1323 variable glyph_pool_count is incremented for each pool allocated. */
1316 1324
1317static struct glyph_pool * 1325static struct glyph_pool *
1318new_glyph_pool (void) 1326new_glyph_pool (void)
1319{ 1327{
1320 struct glyph_pool *result = xzalloc (sizeof *result); 1328 struct glyph_pool *result = xzalloc (sizeof *result);
1321 1329
1330#if defined GLYPH_DEBUG && defined ENABLE_CHECKING
1322 /* For memory leak and double deletion checking. */ 1331 /* For memory leak and double deletion checking. */
1323 ++glyph_pool_count; 1332 ++glyph_pool_count;
1333#endif
1324 1334
1325 return result; 1335 return result;
1326} 1336}
1327 1337
1328 1338
1329/* Free a glyph_pool structure POOL. The function may be called with 1339/* Free a glyph_pool structure POOL. The function may be called with
1330 a null POOL pointer. The global variable glyph_pool_count is 1340 a null POOL pointer. If GLYPH_DEBUG and ENABLE_CHECKING are in effect,
1331 decremented with every pool structure freed. If this count gets 1341 global variable glyph_pool_count is decremented with every pool structure
1332 negative, more structures were freed than allocated, i.e. one 1342 freed. If this count gets negative, more structures were freed than
1333 structure must have been freed more than once or a bogus pointer 1343 allocated, i.e. one structure must have been freed more than once or
1334 was passed to free_glyph_pool. */ 1344 a bogus pointer was passed to free_glyph_pool. */
1335 1345
1336static void 1346static void
1337free_glyph_pool (struct glyph_pool *pool) 1347free_glyph_pool (struct glyph_pool *pool)
1338{ 1348{
1339 if (pool) 1349 if (pool)
1340 { 1350 {
1351#if defined GLYPH_DEBUG && defined ENABLE_CHECKING
1341 /* More freed than allocated? */ 1352 /* More freed than allocated? */
1342 --glyph_pool_count; 1353 --glyph_pool_count;
1343 eassert (glyph_pool_count >= 0); 1354 eassert (glyph_pool_count >= 0);
1344 1355#endif
1345 xfree (pool->glyphs); 1356 xfree (pool->glyphs);
1346 xfree (pool); 1357 xfree (pool);
1347 } 1358 }
@@ -2254,11 +2265,11 @@ check_glyph_memory (void)
2254 FOR_EACH_FRAME (tail, frame) 2265 FOR_EACH_FRAME (tail, frame)
2255 free_glyphs (XFRAME (frame)); 2266 free_glyphs (XFRAME (frame));
2256 2267
2268#if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2257 /* Check that nothing is left allocated. */ 2269 /* Check that nothing is left allocated. */
2258 if (glyph_matrix_count) 2270 eassert (glyph_matrix_count == 0);
2259 emacs_abort (); 2271 eassert (glyph_pool_count == 0);
2260 if (glyph_pool_count) 2272#endif
2261 emacs_abort ();
2262} 2273}
2263 2274
2264 2275