Fixed bugs in the Knight shared files (not that these are used in SM).
authorDavid Anderson <dvander@alliedmods.net>
Thu Jan 29 12:50:32 2009 -0500 (2009-01-29)
changeset 25410352326a1f3f
parent 2540 0ebc3ea8884d
child 2542 bae5a337bff7
Fixed bugs in the Knight shared files (not that these are used in SM).
knight/shared/KeHashTable.cpp
knight/shared/KeHashTable.h
knight/shared/KeLumpAllocator.cpp
     1.1 --- a/knight/shared/KeHashTable.cpp	Wed Jan 28 02:14:41 2009 -0600
     1.2 +++ b/knight/shared/KeHashTable.cpp	Thu Jan 29 12:50:32 2009 -0500
     1.3 @@ -1,3 +1,4 @@
     1.4 +#include <string.h>
     1.5  #include <KeHashTable.h>
     1.6  
     1.7  using namespace Knight;
     1.8 @@ -82,7 +83,7 @@
     1.9  	table->key_m = *key_marshal;
    1.10  	table->val_m = *val_marshal;
    1.11  	table->num_entries = 0;
    1.12 -	table->shift = bits;
    1.13 +	table->shift = 32 - bits;
    1.14  	table->node_alloc = nodeAlloc == NULL ? &s_DefHashAllocator : nodeAlloc;
    1.15  	table->num_buckets = (1 << bits);
    1.16  	table->grow_limit = (uint32_t)(0.9f * table->num_buckets);
    1.17 @@ -145,7 +146,7 @@
    1.18  
    1.19  	/* Save new data */
    1.20  	table->num_buckets = (1 << new_shift);
    1.21 -	table->shift = new_shift;
    1.22 +	table->shift = 32 - new_shift;
    1.23  	table->grow_limit = (uint32_t)(0.9f * table->num_buckets);
    1.24  
    1.25  	table->buckets = (KeHashNode **)malloc(sizeof(KeHashNode *) * table->num_buckets);
    1.26 @@ -407,3 +408,9 @@
    1.27  
    1.28  	return h;
    1.29  }
    1.30 +
    1.31 +bool Knight::KE_AreStringsEqual(const void* str1, const void* str2)
    1.32 +{
    1.33 +    return (strcmp((const char*)str1, (const char*)str2) == 0) ? true : false;
    1.34 +}
    1.35 +
     2.1 --- a/knight/shared/KeHashTable.h	Wed Jan 28 02:14:41 2009 -0600
     2.2 +++ b/knight/shared/KeHashTable.h	Thu Jan 29 12:50:32 2009 -0500
     2.3 @@ -117,12 +117,22 @@
     2.4  	extern void KE_ClearHashTable(KeHashTable *table);
     2.5  
     2.6  	/**
     2.7 -	 * @brief Generic function for hasing strings.
     2.8 +	 * @brief Generic function for hashing strings.
     2.9  	 *
    2.10  	 * @param str				Key string.
    2.11  	 * @return					Hash value.
    2.12  	 */
    2.13  	extern uint32_t KE_HashString(const void *str);
    2.14 +
    2.15 +    /**
    2.16 +     * @brief Generic case-sensitive comparison of strings.
    2.17 +     *
    2.18 +     * @param str1              First string.
    2.19 +     * @param str2              Second string.
    2.20 +     * @return                  True if equal, false otherwise.
    2.21 +     */
    2.22 +    extern bool KE_AreStringsEqual(const void* str1, const void* str2);
    2.23  }
    2.24  
    2.25  #endif //_INCLUDE_KNIGHT_KE_HASHTABLE_H_
    2.26 +
     3.1 --- a/knight/shared/KeLumpAllocator.cpp	Wed Jan 28 02:14:41 2009 -0600
     3.2 +++ b/knight/shared/KeLumpAllocator.cpp	Thu Jan 29 12:50:32 2009 -0500
     3.3 @@ -88,6 +88,8 @@
     3.4  			
     3.5  #if defined KE_PLATFORM_WINDOWS
     3.6  			VirtualFree(region, 0, MEM_RELEASE);
     3.7 +#else
     3.8 +            free(region);
     3.9  #endif
    3.10  			region = next;
    3.11  		}
    3.12 @@ -193,6 +195,8 @@
    3.13  			m_DefLumpSize,
    3.14  			MEM_COMMIT|MEM_RESERVE,
    3.15  			PAGE_READWRITE);
    3.16 +#else
    3.17 +        base = (char*)valloc(m_DefLumpSize);
    3.18  #endif
    3.19  
    3.20  		/* Initialize the region */
    3.21 @@ -256,3 +260,4 @@
    3.22  {
    3.23  	ke_LumpFromAllocator(alloc)->Reset();
    3.24  }
    3.25 +