CVS update: php3
| From: | thies | Date: | Tue, 22 Jun 1999 10:18:19 +0000 |
| Subject: | CVS update: php3 | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-7394@lists.php.net to get a copy of this message | ||
Date: Tuesday June 22, 1999 @ 6:18
Author: thies
Update of /repository/php3
In directory php:/tmp/cvs-serv14195
Modified Files:
php3_hash.c php3_hash.h
Log Message:
added checking (active only when --enable-debug is set) for working with destroyed/currently
destroying HashTables
this one shows a problem in the clenup-code of unified_odbc.c
Index: php3/php3_hash.c
diff -u php3/php3_hash.c:1.8 php3/php3_hash.c:1.9
--- php3/php3_hash.c:1.8 Fri Jan 1 12:58:51 1999
+++ php3/php3_hash.c Tue Jun 22 06:18:19 1999
@@ -29,7 +29,7 @@
*/
-/* $Id: php3_hash.c,v 1.8 1999/01/01 17:58:51 zeev Exp $ */
+/* $Id: php3_hash.c,v 1.9 1999/06/22 10:18:19 thies Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
@@ -76,6 +76,19 @@
uint nNumPrimeNumbers = sizeof(PrimeNumbers) / sizeof(ulong);
+#if DEBUG
+static void _php3_hash_indestroy(HashTable *ht,char *function)
+{
+ TLS_VARS;
+ if (ht->indestroy) {
+ php3_error(E_WARNING, "%s ht=%08x is already destroyed/destroying",function,ht);
+ }
+}
+#define CHECK_INDESTROY(a) _php3_hash_indestroy(a,__FUNCTION__);
+#else
+#define CHECK_INDESTROY(a)
+#endif
+
static ulong hashpjw(char *arKey, uint nKeyLength)
{
ulong h = 0, g;
@@ -126,6 +139,9 @@
ht->nNextFreeElement = 0;
ht->pInternalPointer = NULL;
ht->persistent = persistent;
+#if DEBUG
+ ht->indestroy = 0;
+#endif
return SUCCESS;
}
@@ -138,6 +154,8 @@
TLS_VARS;
#endif
+ CHECK_INDESTROY(ht);
+
if (nKeyLength <= 0) {
#if DEBUG
PUTS("_php3_hash_update: Can't put in empty key\n");
@@ -236,6 +254,8 @@
TLS_VARS;
#endif
+ CHECK_INDESTROY(ht);
+
if (flag == HASH_NEXT_INSERT) {
h = ht->nNextFreeElement;
}
@@ -323,6 +343,7 @@
TLS_VARS;
#endif
+ CHECK_INDESTROY(ht);
if (nKeyLength <= 0) {
#if DEBUG
@@ -409,6 +430,8 @@
TLS_VARS;
#endif
+ CHECK_INDESTROY(ht);
+
if (flag == HASH_NEXT_INSERT) {
h = ht->nNextFreeElement;
}
@@ -489,6 +512,8 @@
TLS_VARS;
#endif
+ CHECK_INDESTROY(ht);
+
if (nKeyLength <= 0) {
#if DEBUG
PUTS("_php3_hash_update: Can't check for empty key\n");
@@ -535,6 +560,8 @@
{
Bucket **t;
+ CHECK_INDESTROY(ht);
+
if ((ht->nNumOfElements > ht->nTableSize) && (ht->nHashSizeIndex <
nNumPrimeNumbers - 1)) { /* Let's double the table
size */
t = (Bucket **) perealloc(ht->arBuckets, PrimeNumbers[ht->nHashSizeIndex + 1] *
sizeof(Bucket *),ht->persistent);
@@ -557,6 +584,8 @@
Bucket *p;
uint nIndex;
+ CHECK_INDESTROY(ht);
+
memset(ht->arBuckets, 0, PrimeNumbers[ht->nHashSizeIndex] * sizeof(Bucket *));
p = ht->pListHead;
while (p != NULL) {
@@ -573,6 +602,8 @@
uint nIndex;
Bucket *p, *t = NULL; /* initialize just to shut gcc up with -Wall */
+ CHECK_INDESTROY(ht);
+
if (flag == HASH_DEL_KEY) {
HANDLE_NUMERIC(arKey,nKeyLength,_php3_hash_del_key_or_index(ht,arKey,nKeyLength,idx,HASH_DEL_INDEX));
h = ht->pHashFunction(arKey, nKeyLength);
@@ -628,6 +659,12 @@
{
Bucket *p, *q;
+ CHECK_INDESTROY(ht);
+
+#if DEBUG
+ ht->indestroy = 1;
+#endif
+
p = ht->pListHead;
while (p != NULL) {
q = p;
@@ -657,6 +694,8 @@
{
Bucket *p, *q;
+ CHECK_INDESTROY(ht);
+
p = ht->pListHead;
while (p != NULL) {
q = p;
@@ -676,6 +715,8 @@
{
Bucket *p, *q;
+ CHECK_INDESTROY(ht);
+
p = ht->pListHead;
while (p != NULL) {
q = p;
@@ -697,6 +738,9 @@
HashTable *t;
Bucket *p;
+ CHECK_INDESTROY(*target);
+ CHECK_INDESTROY(source);
+
t = (HashTable *) pemalloc(sizeof(HashTable),0);
if (!t) {
*target = NULL;
@@ -728,6 +772,9 @@
Bucket *p;
void *t;
+ CHECK_INDESTROY(target);
+ CHECK_INDESTROY(source);
+
p = source->pListHead;
while (p) {
memcpy(tmp, p->pData, size);
@@ -753,6 +800,9 @@
Bucket *p,*nb;
uint nIndex;
+ CHECK_INDESTROY(*target);
+ CHECK_INDESTROY(source);
+
t = (HashTable *) pemalloc(sizeof(HashTable),0);
if (!t) {
*target = NULL;
@@ -831,6 +881,8 @@
uint nIndex;
Bucket *p;
+ CHECK_INDESTROY(ht);
+
HANDLE_NUMERIC(arKey, nKeyLength, _php3_hash_index_find(ht,idx,pData));
h = ht->pHashFunction(arKey, nKeyLength);
@@ -855,6 +907,8 @@
uint nIndex;
Bucket *p;
+ CHECK_INDESTROY(ht);
+
HANDLE_NUMERIC(arKey, nKeyLength, _php3_hash_index_exists(ht,idx));
h = ht->pHashFunction(arKey, nKeyLength);
@@ -878,6 +932,8 @@
uint nIndex;
Bucket *p;
+ CHECK_INDESTROY(ht);
+
nIndex = h % ht->nTableSize;
p = ht->arBuckets[nIndex];
@@ -897,6 +953,8 @@
uint nIndex;
Bucket *p;
+ CHECK_INDESTROY(ht);
+
nIndex = h % ht->nTableSize;
p = ht->arBuckets[nIndex];
@@ -912,12 +970,16 @@
PHPAPI inline int _php3_hash_num_elements(HashTable *ht)
{
+ CHECK_INDESTROY(ht);
+
return ht->nNumOfElements;
}
void _php3_hash_internal_pointer_reset(HashTable *ht)
{
+ CHECK_INDESTROY(ht);
+
ht->pInternalPointer = ht->pListHead;
}
@@ -927,12 +989,16 @@
*/
PHPAPI void _php3_hash_internal_pointer_end(HashTable *ht)
{
+ CHECK_INDESTROY(ht);
+
ht->pInternalPointer = ht->pListTail;
}
PHPAPI void _php3_hash_move_forward(HashTable *ht)
{
+ CHECK_INDESTROY(ht);
+
if (ht->pInternalPointer) {
ht->pInternalPointer = ht->pInternalPointer->pListNext;
}
@@ -940,6 +1006,8 @@
PHPAPI void _php3_hash_move_backwards(HashTable *ht)
{
+ CHECK_INDESTROY(ht);
+
if (ht->pInternalPointer) {
ht->pInternalPointer = ht->pInternalPointer->pListLast;
}
@@ -950,6 +1018,8 @@
{
Bucket *p = ht->pInternalPointer;
+ CHECK_INDESTROY(ht);
+
if (p) {
if (p->arKey) {
*str_index = (char *) pemalloc(p->nKeyLength,ht->persistent);
@@ -968,6 +1038,8 @@
{
Bucket *p = ht->pInternalPointer;
+ CHECK_INDESTROY(ht);
+
if (p) {
*pData = p->pData;
return SUCCESS;
@@ -983,6 +1055,8 @@
Bucket *p;
int i, j;
+ CHECK_INDESTROY(ht);
+
if (ht->nNumOfElements <= 1) { /* Doesn't require sorting */
return SUCCESS;
}
@@ -1039,6 +1113,8 @@
{
Bucket *p,*res;
+ CHECK_INDESTROY(ht);
+
if (ht->nNumOfElements == 0 ) {
*pData=NULL;
return FAILURE;
@@ -1062,6 +1138,8 @@
PHPAPI ulong _php3_hash_next_free_element(HashTable *ht)
{
+ CHECK_INDESTROY(ht);
+
return ht->nNextFreeElement;
}
Index: php3/php3_hash.h
diff -u php3/php3_hash.h:1.7 php3/php3_hash.h:1.8
--- php3/php3_hash.h:1.7 Fri Jan 1 12:58:51 1999
+++ php3/php3_hash.h Tue Jun 22 06:18:19 1999
@@ -29,7 +29,7 @@
*/
-/* $Id: php3_hash.h,v 1.7 1999/01/01 17:58:51 zeev Exp $ */
+/* $Id: php3_hash.h,v 1.8 1999/06/22 10:18:19 thies Exp $ */
#ifndef _HASH_
@@ -73,6 +73,9 @@
Bucket **arBuckets;
void (*pDestructor) (void *pData);
unsigned char persistent;
+#if DEBUG
+ unsigned char indestroy;
+#endif
} HashTable;