From c13cf0d69094bd586df16bb5cf1aa306f8923307 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Tue, 11 Nov 2008 23:27:27 +0900 Subject: gallium: Make handle_table reentrant. Ensure that the object has consistent state also when calling the destroy callback. Namely, ensure the object passed to the callback is removed from the table prior to calling the destroy callback to avoid a infinite loop or double free. --- src/gallium/auxiliary/util/u_handle_table.c | 34 ++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'src/gallium/auxiliary') diff --git a/src/gallium/auxiliary/util/u_handle_table.c b/src/gallium/auxiliary/util/u_handle_table.c index 2c40011923d..2d15932ce3b 100644 --- a/src/gallium/auxiliary/util/u_handle_table.c +++ b/src/gallium/auxiliary/util/u_handle_table.c @@ -124,6 +124,28 @@ handle_table_resize(struct handle_table *ht, } +static INLINE void +handle_table_clear(struct handle_table *ht, + unsigned index) +{ + void *object; + + /* The order here is important so that the object being destroyed is not + * present in the table when seen by the destroy callback, because the + * destroy callback may directly or indirectly call the other functions in + * this module. + */ + + object = ht->objects[index]; + if(object) { + ht->objects[index] = NULL; + + if(ht->destroy) + ht->destroy(object); + } +} + + unsigned handle_table_add(struct handle_table *ht, void *object) @@ -184,9 +206,8 @@ handle_table_set(struct handle_table *ht, if(!handle_table_resize(ht, index)) return 0; - if(ht->objects[index] && ht->destroy) - ht->destroy(ht->objects[index]); - + handle_table_clear(ht, index); + ht->objects[index] = object; return handle; @@ -227,10 +248,8 @@ handle_table_remove(struct handle_table *ht, if(!object) return; - if(ht->destroy) - ht->destroy(object); + handle_table_clear(ht, index); - ht->objects[index] = NULL; if(index < ht->filled) ht->filled = index; } @@ -266,8 +285,7 @@ handle_table_destroy(struct handle_table *ht) if(ht->destroy) for(index = 0; index < ht->size; ++index) - if(ht->objects[index]) - ht->destroy(ht->objects[index]); + handle_table_clear(ht, index); FREE(ht->objects); FREE(ht); -- cgit v1.2.3 From 1e35d92953207dd5e40be4954ccc9015913f7f06 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 13 Nov 2008 20:34:10 +0900 Subject: gallium: State when there are no memory leaks detected. --- src/gallium/auxiliary/util/p_debug_mem.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/gallium/auxiliary') diff --git a/src/gallium/auxiliary/util/p_debug_mem.c b/src/gallium/auxiliary/util/p_debug_mem.c index 9511479cbbe..250fd60f634 100644 --- a/src/gallium/auxiliary/util/p_debug_mem.c +++ b/src/gallium/auxiliary/util/p_debug_mem.c @@ -265,6 +265,9 @@ debug_memory_end(unsigned long start_no) size_t total_size = 0; struct list_head *entry; + if(start_no == last_no) + return; + entry = list.prev; for (; entry != &list; entry = entry->prev) { struct debug_memory_header *hdr; @@ -302,4 +305,7 @@ debug_memory_end(unsigned long start_no) debug_printf("Total of %u KB of system memory apparently leaked\n", (total_size + 1023)/1024); } + else { + debug_printf("No memory leaks detected.\n"); + } } -- cgit v1.2.3 From 228afbc8e012769983c5504d60c0772c84359bb1 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 17 Nov 2008 16:40:21 +0900 Subject: gallium: Use costum log2 for all windows builds. --- src/gallium/auxiliary/util/u_math.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/gallium/auxiliary') diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h index ac11d7001bc..1ae3234423a 100644 --- a/src/gallium/auxiliary/util/u_math.h +++ b/src/gallium/auxiliary/util/u_math.h @@ -119,6 +119,7 @@ __inline double __cdecl atan2(double val) #if defined(_MSC_VER) + #if _MSC_VER < 1400 && !defined(__cplusplus) || defined(PIPE_SUBSYSTEM_WINDOWS_CE) static INLINE float cosf( float f ) @@ -161,12 +162,6 @@ static INLINE float logf( float f ) return (float) log( (double) f ); } -static INLINE double log2( double x ) -{ - const double invln2 = 1.442695041; - return log( x ) * invln2; -} - #else /* Work-around an extra semi-colon in VS 2005 logf definition */ #ifdef logf @@ -174,6 +169,13 @@ static INLINE double log2( double x ) #define logf(x) ((float)log((double)(x))) #endif /* logf */ #endif + +static INLINE double log2( double x ) +{ + const double invln2 = 1.442695041; + return log( x ) * invln2; +} + #endif /* _MSC_VER */ -- cgit v1.2.3