cvs: php4 /ext/hyperwave hg_comm.c hg_comm.h /ext/standard array.c php_array.h /main mergesort.c php.h
| From: | Sterling Hughes | Date: | Mon, 17 Sep 2001 21:02:53 +0000 |
| Subject: | cvs: php4 /ext/hyperwave hg_comm.c hg_comm.h /ext/standard array.c php_array.h /main mergesort.c php.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-7450@lists.php.net to get a copy of this message | ||
sterling Mon Sep 17 17:02:53 2001 EDT
Modified files:
/php4/ext/hyperwave hg_comm.c hg_comm.h
/php4/ext/standard array.c php_array.h
/php4/main mergesort.c php.h
Log:
Merge in qsort changes
Index: php4/ext/hyperwave/hg_comm.c diff -u php4/ext/hyperwave/hg_comm.c:1.44 php4/ext/hyperwave/hg_comm.c:1.45 --- php4/ext/hyperwave/hg_comm.c:1.44 Sat Aug 11 12:38:32 2001 +++ php4/ext/hyperwave/hg_comm.c Mon Sep 17 17:02:49 2001 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: hg_comm.c,v 1.44 2001/08/11 16:38:32 zeev Exp $ */ +/* $Id: hg_comm.c,v 1.45 2001/09/17 21:02:49 sterling Exp $ */ /* #define HW_DEBUG */ @@ -287,7 +287,7 @@ * Return: As strcmp * ***********************************************************************/ #ifdef newlist -int fnCmpAnchors(const void *e1, const void *e2) +int fnCmpAnchors(const void *e1, const void *e2 TSRMLS_DC) { ANCHOR *a1, **aa1, *a2, **aa2; zend_llist_element **ee1, **ee2; @@ -298,7 +298,7 @@ a1 = *aa1; a2 = *aa2; #else -int fnCmpAnchors(ANCHOR *a1, ANCHOR *a2) +int fnCmpAnchors(ANCHOR *a1, ANCHOR *a2 TSRMLS_DC) { #endif if(a1->start < a2->start) Index: php4/ext/hyperwave/hg_comm.h diff -u php4/ext/hyperwave/hg_comm.h:1.16 php4/ext/hyperwave/hg_comm.h:1.17 --- php4/ext/hyperwave/hg_comm.h:1.16 Sat Aug 11 12:38:39 2001 +++ php4/ext/hyperwave/hg_comm.h Mon Sep 17 17:02:50 2001 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: hg_comm.h,v 1.16 2001/08/11 16:38:39 zeev Exp $ */ +/* $Id: hg_comm.h,v 1.17 2001/09/17 21:02:50 sterling Exp $ */ #ifndef HG_COMM_H #define HG_COMM_H @@ -154,14 +154,14 @@ void fnListAnchor(zend_llist *pAnchorList); zend_llist *fnCreateAnchorList(hw_objectID objID, char **anchors, char **docofanchorrec, char **reldestrec, int ancount, int anchormode); char *fnInsAnchorsIntoText(char *text, zend_llist *pAnchorList, char **bodytag, char **urlprefix); -int fnCmpAnchors(const void *e1, const void *e2); +int fnCmpAnchors(const void *e1, const void *e2 TSRMLS_DC); ANCHOR *fnAddAnchor(zend_llist *pAnchorList, int objectID, int start, int end); #else void fnDeleteAnchor(ANCHOR *ptr); void fnListAnchor(DLIST *pAnchorList); DLIST *fnCreateAnchorList(hw_objectID objID, char **anchors, char **docofanchorrec, char **reldestrec, int ancount, int anchormode); char *fnInsAnchorsIntoText(char *text, DLIST *pAnchorList, char **bodytag, char **urlprefix); -int fnCmpAnchors(ANCHOR *a1, ANCHOR *a2); +int fnCmpAnchors(ANCHOR *a1, ANCHOR *a2 TSRMLS_DC); ANCHOR *fnAddAnchor(DLIST *pAnchorList, int objectID, int start, int end); #endif extern void set_swap(int do_swap); Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.136 php4/ext/standard/array.c:1.137 --- php4/ext/standard/array.c:1.136 Sun Sep 16 16:49:57 2001 +++ php4/ext/standard/array.c Mon Sep 17 17:02:51 2001 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: array.c,v 1.136 2001/09/16 20:49:57 sterling Exp $ */ +/* $Id: array.c,v 1.137 2001/09/17 21:02:51 sterling Exp $ */ #include "php.h" #include "php_ini.h" @@ -114,14 +114,13 @@ } } -static int array_key_compare(const void *a, const void *b) +static int array_key_compare(const void *a, const void *b TSRMLS_DC) { Bucket *f; Bucket *s; - pval result; - pval first; - pval second; - TSRMLS_FETCH(); + zval result; + zval first; + zval second; f = *((Bucket **) a); s = *((Bucket **) b); @@ -169,9 +168,9 @@ return 0; } -static int array_reverse_key_compare(const void *a, const void *b) +static int array_reverse_key_compare(const void *a, const void *b TSRMLS_DC) { - return array_key_compare(a, b)*-1; + return array_key_compare(a, b TSRMLS_CC) * -1; } /* {{{ proto int krsort(array array_arg [, int sort_flags]) @@ -196,7 +195,7 @@ sort_type_val = Z_LVAL_PP(sort_type); } set_compare_func(sort_type_val TSRMLS_CC); - if (zend_hash_sort(target_hash, qsort, array_reverse_key_compare, 0) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_reverse_key_compare, 0 TSRMLS_CC) == FAILURE) { return; } RETURN_TRUE; @@ -225,7 +224,7 @@ sort_type_val = Z_LVAL_PP(sort_type); } set_compare_func(sort_type_val TSRMLS_CC); - if (zend_hash_sort(target_hash, qsort, array_key_compare, 0) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_key_compare, 0 TSRMLS_CC) == FAILURE) { return; } RETURN_TRUE; @@ -261,14 +260,13 @@ * * This is not correct any more, depends on what compare_func is set to. */ -static int array_data_compare(const void *a, const void *b) +static int array_data_compare(const void *a, const void *b TSRMLS_DC) { Bucket *f; Bucket *s; pval result; pval *first; pval *second; - TSRMLS_FETCH(); f = *((Bucket **) a); s = *((Bucket **) b); @@ -301,9 +299,9 @@ return 0; } -static int array_reverse_data_compare(const void *a, const void *b) +static int array_reverse_data_compare(const void *a, const void *b TSRMLS_DC) { - return array_data_compare(a, b)*-1; + return array_data_compare(a, b TSRMLS_CC)*-1; } static int array_natural_general_compare(const void *a, const void *b, int fold_case) @@ -340,12 +338,12 @@ return result; } -static int array_natural_compare(const void *a, const void *b) +static int array_natural_compare(const void *a, const void *b TSRMLS_DC) { return array_natural_general_compare(a, b, 0); } -static int array_natural_case_compare(const void *a, const void *b) +static int array_natural_case_compare(const void *a, const void *b TSRMLS_DC) { return array_natural_general_compare(a, b, 1); } @@ -367,11 +365,11 @@ } if (fold_case) { - if (zend_hash_sort(target_hash, qsort, array_natural_case_compare, 0) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_natural_case_compare, 0 TSRMLS_CC) == FAILURE) { return; } } else { - if (zend_hash_sort(target_hash, qsort, array_natural_compare, 0) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_natural_compare, 0 TSRMLS_CC) == FAILURE) { return; } } @@ -420,7 +418,7 @@ sort_type_val = Z_LVAL_PP(sort_type); } set_compare_func(sort_type_val TSRMLS_CC); - if (zend_hash_sort(target_hash, qsort, array_data_compare, 0) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_data_compare, 0 TSRMLS_CC) == FAILURE) { return; } RETURN_TRUE; @@ -449,7 +447,7 @@ sort_type_val = Z_LVAL_PP(sort_type); } set_compare_func(sort_type_val TSRMLS_CC); - if (zend_hash_sort(target_hash, qsort, array_reverse_data_compare, 0) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_reverse_data_compare, 0 TSRMLS_CC) == FAILURE) { RETURN_FALSE; } RETURN_TRUE; @@ -478,7 +476,7 @@ sort_type_val = Z_LVAL_PP(sort_type); } set_compare_func(sort_type_val TSRMLS_CC); - if (zend_hash_sort(target_hash, qsort, array_data_compare, 1) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_data_compare, 1 TSRMLS_CC) == FAILURE) { RETURN_FALSE; } RETURN_TRUE; @@ -507,26 +505,25 @@ sort_type_val = Z_LVAL_PP(sort_type); } set_compare_func(sort_type_val TSRMLS_CC); - if (zend_hash_sort(target_hash, qsort, array_reverse_data_compare, 1) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_reverse_data_compare, 1 TSRMLS_CC) == FAILURE) { RETURN_FALSE; } RETURN_TRUE; } -static int array_user_compare(const void *a, const void *b) +static int array_user_compare(const void *a, const void *b TSRMLS_DC) { Bucket *f; Bucket *s; - pval **args[2]; - pval *retval_ptr; - TSRMLS_FETCH(); + zval **args[2]; + zval *retval_ptr; f = *((Bucket **) a); s = *((Bucket **) b); - args[0] = (pval **) f->pData; - args[1] = (pval **) s->pData; + args[0] = (zval **) f->pData; + args[1] = (zval **) s->pData; if (call_user_function_ex(EG(function_table), NULL, *BG(user_compare_func_name), &retval_ptr, 2, args, 0, NULL TSRMLS_CC)==SUCCESS && retval_ptr) { @@ -560,7 +557,7 @@ BG(user_compare_func_name) = old_compare_func; RETURN_FALSE; } - if (zend_hash_sort(target_hash, qsort, array_user_compare, 1) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_user_compare, 1 TSRMLS_CC) == FAILURE) { BG(user_compare_func_name) = old_compare_func; RETURN_FALSE; } @@ -588,7 +585,7 @@ BG(user_compare_func_name) = old_compare_func; RETURN_FALSE; } - if (zend_hash_sort(target_hash, qsort, array_user_compare, 0) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_user_compare, 0 TSRMLS_CC) == FAILURE) { BG(user_compare_func_name) = old_compare_func; RETURN_FALSE; } @@ -597,7 +594,7 @@ } /* }}} */ -static int array_user_key_compare(const void *a, const void *b) +static int array_user_key_compare(const void *a, const void *b TSRMLS_DC) { Bucket *f; Bucket *s; @@ -605,7 +602,6 @@ pval *args[2]; pval retval; int status; - TSRMLS_FETCH(); args[0] = &key1; args[1] = &key2; @@ -664,7 +660,7 @@ BG(user_compare_func_name) = old_compare_func; RETURN_FALSE; } - if (zend_hash_sort(target_hash, qsort, array_user_key_compare, 0) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_user_key_compare, 0 TSRMLS_CC) == FAILURE) { BG(user_compare_func_name) = old_compare_func; RETURN_FALSE; } @@ -856,7 +852,7 @@ if (zend_get_parameters_ex(1, &arr) == FAILURE || Z_TYPE_PP(arr) != IS_ARRAY) { WRONG_PARAM_COUNT; } - if (zend_hash_minmax(Z_ARRVAL_PP(arr), array_data_compare, 0, (void **) &result)==SUCCESS) { + if (zend_hash_minmax(Z_ARRVAL_PP(arr), array_data_compare, 0, (void **) &result TSRMLS_CC)==SUCCESS) { *return_value = **result; zval_copy_ctor(return_value); } else { @@ -908,7 +904,7 @@ if (zend_get_parameters_ex(1, &arr) == FAILURE || Z_TYPE_PP(arr) != IS_ARRAY) { WRONG_PARAM_COUNT; } - if (zend_hash_minmax(Z_ARRVAL_PP(arr), array_data_compare, 1, (void **) &result)==SUCCESS) { + if (zend_hash_minmax(Z_ARRVAL_PP(arr), array_data_compare, 1, (void **) &result TSRMLS_CC)==SUCCESS) { *return_value = **result; zval_copy_ctor(return_value); } else { @@ -1376,8 +1372,8 @@ /* }}} */ -static int array_data_shuffle(const void *a, const void*b) { - TSRMLS_FETCH(); +static int array_data_shuffle(const void *a, const void *b TSRMLS_DC) +{ return (php_rand(TSRMLS_C) % 2) ? 1 : -1; } @@ -1395,7 +1391,7 @@ php_error(E_WARNING, "Wrong datatype in shuffle() call"); RETURN_FALSE; } - if (zend_hash_sort(Z_ARRVAL_PP(array), (sort_func_t)php_mergesort, array_data_shuffle, 1) == FAILURE) { + if (zend_hash_sort(Z_ARRVAL_PP(array), (sort_func_t)php_mergesort, array_data_shuffle, 1 TSRMLS_CC) == FAILURE) { RETURN_FALSE; } RETURN_TRUE; @@ -2276,12 +2272,12 @@ arTmp[i] = p; arTmp[i] = NULL; set_compare_func(SORT_STRING TSRMLS_CC); - qsort((void *) arTmp, i, sizeof(Bucket *), array_data_compare); + zend_qsort((void *) arTmp, i, sizeof(Bucket *), array_data_compare TSRMLS_CC); /* go through the sorted array and delete duplicates from the copy */ lastkept = arTmp; for (cmpdata = arTmp + 1; *cmpdata; cmpdata++) { - if (array_data_compare(lastkept, cmpdata)) { + if (array_data_compare(lastkept, cmpdata TSRMLS_CC)) { lastkept = cmpdata; } else { p = *cmpdata; @@ -2334,7 +2330,7 @@ for (p = hash->pListHead; p; p = p->pListNext) *list++ = p; *list = NULL; - qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), array_data_compare); + zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), array_data_compare TSRMLS_CC); } /* copy the argument array */ @@ -2344,7 +2340,7 @@ /* go through the lists and look for common values */ while (*ptrs[0]) { for (i=1; i<argc; i++) { - while (*ptrs[i] && (0 < (c = array_data_compare(ptrs[0], ptrs[i])))) + while (*ptrs[i] && (0 < (c = array_data_compare(ptrs[0], ptrs[i] TSRMLS_CC)))) ptrs[i]++; if (!*ptrs[i]) { /* delete any values corresponding to remains of ptrs[0] */ @@ -2374,7 +2370,7 @@ zend_hash_index_del(Z_ARRVAL_P(return_value), p->h); if (!*++ptrs[0]) goto out; - if (0 <= array_data_compare(ptrs[0], ptrs[i])) + if (0 <= array_data_compare(ptrs[0], ptrs[i] TSRMLS_CC)) break; } } else { @@ -2383,7 +2379,7 @@ for (;;) { if (!*++ptrs[0]) goto out; - if (array_data_compare(ptrs[0]-1, ptrs[0])) + if (array_data_compare(ptrs[0]-1, ptrs[0] TSRMLS_CC)) break; } } @@ -2439,7 +2435,7 @@ for (p = hash->pListHead; p; p = p->pListNext) *list++ = p; *list = NULL; - qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), array_data_compare); + zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), array_data_compare TSRMLS_CC); } /* copy the argument array */ @@ -2451,7 +2447,7 @@ while (*ptrs[0]) { c = 1; for (i=1; i<argc; i++) { - while (*ptrs[i] && (0 < (c = array_data_compare(ptrs[0], ptrs[i])))) + while (*ptrs[i] && (0 < (c = array_data_compare(ptrs[0], ptrs[i] TSRMLS_CC)))) ptrs[i]++; if (!c) { if (*ptrs[i]) @@ -2470,7 +2466,7 @@ zend_hash_index_del(Z_ARRVAL_P(return_value), p->h); if (!*++ptrs[0]) goto out; - if (array_data_compare(ptrs[0]-1, ptrs[0])) + if (array_data_compare(ptrs[0]-1, ptrs[0] TSRMLS_CC)) break; } } else { @@ -2479,7 +2475,7 @@ for (;;) { if (!*++ptrs[0]) goto out; - if (array_data_compare(ptrs[0]-1, ptrs[0])) + if (array_data_compare(ptrs[0]-1, ptrs[0] TSRMLS_CC)) break; } } @@ -2499,14 +2495,13 @@ #define MULTISORT_TYPE 1 #define MULTISORT_LAST 2 -int multisort_compare(const void *a, const void *b) +int multisort_compare(const void *a, const void *b TSRMLS_DC) { Bucket** ab = *(Bucket ***)a; Bucket** bb = *(Bucket ***)b; int r; int result = 0; zval temp; - TSRMLS_FETCH(); r = 0; do { @@ -2670,7 +2665,7 @@ indirect[k][num_arrays] = NULL; /* Do the actual sort magic - bada-bim, bada-boom. */ - qsort(indirect, array_size, sizeof(Bucket **), multisort_compare); + zend_qsort(indirect, array_size, sizeof(Bucket **), multisort_compare TSRMLS_CC); /* Restructure the arrays based on sorted indirect - this is mostly taken from zend_hash_sort() function. */ @@ -2791,7 +2786,7 @@ } if (num_req_val == num_avail) { - if (zend_hash_sort(Z_ARRVAL_P(return_value), (sort_func_t)php_mergesort, array_data_shuffle, 1) == FAILURE) { + if (zend_hash_sort(Z_ARRVAL_P(return_value), (sort_func_t)php_mergesort, array_data_shuffle, 1 TSRMLS_CC) == FAILURE) { zval_dtor(return_value); RETURN_FALSE; } Index: php4/ext/standard/php_array.h diff -u php4/ext/standard/php_array.h:1.27 php4/ext/standard/php_array.h:1.28 --- php4/ext/standard/php_array.h:1.27 Mon Jul 30 00:58:05 2001 +++ php4/ext/standard/php_array.h Mon Sep 17 17:02:52 2001 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_array.h,v 1.27 2001/07/30 04:58:05 zeev Exp $ */ +/* $Id: php_array.h,v 1.28 2001/09/17 21:02:52 sterling Exp $ */ #ifndef PHP_ARRAY_H #define PHP_ARRAY_H @@ -81,7 +81,7 @@ HashTable* php_splice(HashTable *, int, int, zval ***, int, HashTable **); PHPAPI void php_array_merge(HashTable *dest, HashTable *src, int recursive); -int multisort_compare(const void *a, const void *b); +int multisort_compare(const void *a, const void *b TSRMLS_DC); typedef struct { int *multisort_flags[2]; Index: php4/main/mergesort.c diff -u php4/main/mergesort.c:1.10 php4/main/mergesort.c:1.11 --- php4/main/mergesort.c:1.10 Sun Sep 9 09:29:28 2001 +++ php4/main/mergesort.c Mon Sep 17 17:02:53 2001 @@ -64,8 +64,8 @@ #include <winsock.h> /* Includes definition for u_char */ #endif -static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp)(const void *, const void *)); -static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const void *, const void *)); +static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC); +static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC); #define ISIZE sizeof(int) #define PSIZE sizeof(u_char *) @@ -100,7 +100,7 @@ /* {{{ php_mergesort * Arguments are as for qsort. */ -int php_mergesort(void *base, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) +int php_mergesort(void *base, size_t nmemb, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC) { register unsigned int i; register int sense; @@ -128,7 +128,7 @@ return (-1); list1 = base; - setup(list1, list2, nmemb, size, cmp); + setup(list1, list2, nmemb, size, cmp TSRMLS_CC); last = list2 + nmemb * size; i = big = 0; while (*EVAL(list2) != last) { @@ -142,7 +142,7 @@ p2 = *EVAL(p2); l2 = list1 + (p2 - list2); while (f1 < l1 && f2 < l2) { - if ((*cmp)(f1, f2) <= 0) { + if ((*cmp)(f1, f2 TSRMLS_CC) <= 0) { q = f2; b = f1, t = l1; sense = -1; @@ -152,7 +152,7 @@ sense = 0; } if (!big) { /* here i = 0 */ - while ((b += size) < t && cmp(q, b) >sense) + while ((b += size) < t && cmp(q, b TSRMLS_CC) >sense) if (++i == 6) { big = 1; goto EXPONENTIAL; @@ -161,12 +161,12 @@ EXPONENTIAL: for (i = size; ; i <<= 1) if ((p = (b + i)) >= t) { if ((p = t - size) > b && - (*cmp)(q, p) <= sense) + (*cmp)(q, p TSRMLS_CC) <= sense) t = p; else b = p; break; - } else if ((*cmp)(q, p) <= sense) { + } else if ((*cmp)(q, p TSRMLS_CC) <= sense) { t = p; if (i == size) big = 0; @@ -175,7 +175,7 @@ b = p; while (t > b+size) { i = (((t - b) / size) >> 1) * size; - if ((*cmp)(q, p = b + i) <= sense) + if ((*cmp)(q, p = b + i TSRMLS_CC) <= sense) t = p; else b = p; @@ -183,7 +183,7 @@ goto COPY; FASTCASE: while (i > size) if ((*cmp)(q, - p = b + (i >>= 1)) <= sense) + p = b + (i >>= 1) TSRMLS_CC) <= sense) t = p; else b = p; @@ -260,14 +260,14 @@ * when THRESHOLD/2 pairs compare with same sense. (Only used when NATURAL * is defined. Otherwise simple pairwise merging is used.) */ -static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp)(const void *, const void *)) +static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC) { int i, length, size2, tmp, sense; u_char *f1, *f2, *s, *l2, *last, *p2; size2 = size*2; if (n <= 5) { - insertionsort(list1, n, size, cmp); + insertionsort(list1, n, size, cmp TSRMLS_CC); *EVAL(list2) = (u_char*) list2 + n*size; return; } @@ -276,19 +276,19 @@ * for simplicity. */ i = 4 + (n & 1); - insertionsort(list1 + (n - i) * size, i, size, cmp); + insertionsort(list1 + (n - i) * size, i, size, cmp TSRMLS_CC); last = list1 + size * (n - i); *EVAL(list2 + (last - list1)) = list2 + n * size; #ifdef NATURAL p2 = list2; f1 = list1; - sense = (cmp(f1, f1 + size) > 0); + sense = (cmp(f1, f1 + size TSRMLS_CC) > 0); for (; f1 < last; sense = !sense) { length = 2; /* Find pairs with same sense. */ for (f2 = f1 + size2; f2 < last; f2 += size2) { - if ((cmp(f2, f2+ size) > 0) != sense) + if ((cmp(f2, f2+ size TSRMLS_CC) > 0) != sense) break; length += 2; } @@ -301,7 +301,7 @@ } else { /* Natural merge */ l2 = f2; for (f2 = f1 + size2; f2 < l2; f2 += size2) { - if ((cmp(f2-size, f2) > 0) != sense) { + if ((cmp(f2-size, f2 TSRMLS_CC) > 0) != sense) { p2 = *EVAL(p2) = f2 - list1 + list2; if (sense > 0) reverse(f1, f2-size); @@ -311,7 +311,7 @@ if (sense > 0) reverse (f1, f2-size); f1 = f2; - if (f2 < last || cmp(f2 - size, f2) > 0) + if (f2 < last || cmp(f2 - size, f2 TSRMLS_CC) > 0) p2 = *EVAL(p2) = f2 - list1 + list2; else p2 = *EVAL(p2) = list2 + n*size; @@ -320,7 +320,7 @@ #else /* pairwise merge only. */ for (f1 = list1, p2 = list2; f1 < last; f1 += size2) { p2 = *EVAL(p2) = p2 + size2; - if (cmp (f1, f1 + size) > 0) + if (cmp (f1, f1 + size TSRMLS_CC) > 0) swap(f1, f1 + size); } #endif /* NATURAL */ @@ -331,7 +331,7 @@ * This is to avoid out-of-bounds addresses in sorting the * last 4 elements. */ -static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const void *, const void *)) +static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC) { u_char *ai, *s, *t, *u, tmp; int i; @@ -339,7 +339,7 @@ for (ai = a+size; --n >= 1; ai += size) for (t = ai; t > a; t -= size) { u = t - size; - if (cmp(u, t) <= 0) + if (cmp(u, t TSRMLS_CC) <= 0) break; swap(u, t); } @@ -351,6 +351,6 @@ * tab-width: 4 * c-basic-offset: 4 * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 + * vim600: fdm=marker + * vim: noet sw=4 ts=4 */ Index: php4/main/php.h diff -u php4/main/php.h:1.156 php4/main/php.h:1.157 --- php4/main/php.h:1.156 Sun Sep 9 09:29:28 2001 +++ php4/main/php.h Mon Sep 17 17:02:53 2001 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php.h,v 1.156 2001/09/09 13:29:28 derick Exp $ */ +/* $Id: php.h,v 1.157 2001/09/17 21:02:53 sterling Exp $ */ #ifndef PHP_H #define PHP_H @@ -32,6 +32,7 @@ #include "php_version.h" #include "zend.h" +#include "zend_qsort.h" #include "php_compat.h" #include "zend_API.h" @@ -240,7 +241,7 @@ /* functions */ int php_startup_internal_extensions(void); -int php_mergesort(void *base, size_t nmemb, register size_t size, int (*cmp) (const void *, const void *)); +int php_mergesort(void *base, size_t nmemb, register size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC); PHPAPI void php_register_pre_request_shutdown(void (*func)(void *), void *userdata);
Index: php4/ext/hyperwave/hg_comm.c diff -u php4/ext/hyperwave/hg_comm.c:1.44 php4/ext/hyperwave/hg_comm.c:1.45 --- php4/ext/hyperwave/hg_comm.c:1.44 Sat Aug 11 12:38:32 2001 +++ php4/ext/hyperwave/hg_comm.c Mon Sep 17 17:02:49 2001 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: hg_comm.c,v 1.44 2001/08/11 16:38:32 zeev Exp $ */ +/* $Id: hg_comm.c,v 1.45 2001/09/17 21:02:49 sterling Exp $ */ /* #define HW_DEBUG */ @@ -287,7 +287,7 @@ * Return: As strcmp * ***********************************************************************/ #ifdef newlist -int fnCmpAnchors(const void *e1, const void *e2) +int fnCmpAnchors(const void *e1, const void *e2 TSRMLS_DC) { ANCHOR *a1, **aa1, *a2, **aa2; zend_llist_element **ee1, **ee2; @@ -298,7 +298,7 @@ a1 = *aa1; a2 = *aa2; #else -int fnCmpAnchors(ANCHOR *a1, ANCHOR *a2) +int fnCmpAnchors(ANCHOR *a1, ANCHOR *a2 TSRMLS_DC) { #endif if(a1->start < a2->start) Index: php4/ext/hyperwave/hg_comm.h diff -u php4/ext/hyperwave/hg_comm.h:1.16 php4/ext/hyperwave/hg_comm.h:1.17 --- php4/ext/hyperwave/hg_comm.h:1.16 Sat Aug 11 12:38:39 2001 +++ php4/ext/hyperwave/hg_comm.h Mon Sep 17 17:02:50 2001 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: hg_comm.h,v 1.16 2001/08/11 16:38:39 zeev Exp $ */ +/* $Id: hg_comm.h,v 1.17 2001/09/17 21:02:50 sterling Exp $ */ #ifndef HG_COMM_H #define HG_COMM_H @@ -154,14 +154,14 @@ void fnListAnchor(zend_llist *pAnchorList); zend_llist *fnCreateAnchorList(hw_objectID objID, char **anchors, char **docofanchorrec, char **reldestrec, int ancount, int anchormode); char *fnInsAnchorsIntoText(char *text, zend_llist *pAnchorList, char **bodytag, char **urlprefix); -int fnCmpAnchors(const void *e1, const void *e2); +int fnCmpAnchors(const void *e1, const void *e2 TSRMLS_DC); ANCHOR *fnAddAnchor(zend_llist *pAnchorList, int objectID, int start, int end); #else void fnDeleteAnchor(ANCHOR *ptr); void fnListAnchor(DLIST *pAnchorList); DLIST *fnCreateAnchorList(hw_objectID objID, char **anchors, char **docofanchorrec, char **reldestrec, int ancount, int anchormode); char *fnInsAnchorsIntoText(char *text, DLIST *pAnchorList, char **bodytag, char **urlprefix); -int fnCmpAnchors(ANCHOR *a1, ANCHOR *a2); +int fnCmpAnchors(ANCHOR *a1, ANCHOR *a2 TSRMLS_DC); ANCHOR *fnAddAnchor(DLIST *pAnchorList, int objectID, int start, int end); #endif extern void set_swap(int do_swap); Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.136 php4/ext/standard/array.c:1.137 --- php4/ext/standard/array.c:1.136 Sun Sep 16 16:49:57 2001 +++ php4/ext/standard/array.c Mon Sep 17 17:02:51 2001 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: array.c,v 1.136 2001/09/16 20:49:57 sterling Exp $ */ +/* $Id: array.c,v 1.137 2001/09/17 21:02:51 sterling Exp $ */ #include "php.h" #include "php_ini.h" @@ -114,14 +114,13 @@ } } -static int array_key_compare(const void *a, const void *b) +static int array_key_compare(const void *a, const void *b TSRMLS_DC) { Bucket *f; Bucket *s; - pval result; - pval first; - pval second; - TSRMLS_FETCH(); + zval result; + zval first; + zval second; f = *((Bucket **) a); s = *((Bucket **) b); @@ -169,9 +168,9 @@ return 0; } -static int array_reverse_key_compare(const void *a, const void *b) +static int array_reverse_key_compare(const void *a, const void *b TSRMLS_DC) { - return array_key_compare(a, b)*-1; + return array_key_compare(a, b TSRMLS_CC) * -1; } /* {{{ proto int krsort(array array_arg [, int sort_flags]) @@ -196,7 +195,7 @@ sort_type_val = Z_LVAL_PP(sort_type); } set_compare_func(sort_type_val TSRMLS_CC); - if (zend_hash_sort(target_hash, qsort, array_reverse_key_compare, 0) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_reverse_key_compare, 0 TSRMLS_CC) == FAILURE) { return; } RETURN_TRUE; @@ -225,7 +224,7 @@ sort_type_val = Z_LVAL_PP(sort_type); } set_compare_func(sort_type_val TSRMLS_CC); - if (zend_hash_sort(target_hash, qsort, array_key_compare, 0) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_key_compare, 0 TSRMLS_CC) == FAILURE) { return; } RETURN_TRUE; @@ -261,14 +260,13 @@ * * This is not correct any more, depends on what compare_func is set to. */ -static int array_data_compare(const void *a, const void *b) +static int array_data_compare(const void *a, const void *b TSRMLS_DC) { Bucket *f; Bucket *s; pval result; pval *first; pval *second; - TSRMLS_FETCH(); f = *((Bucket **) a); s = *((Bucket **) b); @@ -301,9 +299,9 @@ return 0; } -static int array_reverse_data_compare(const void *a, const void *b) +static int array_reverse_data_compare(const void *a, const void *b TSRMLS_DC) { - return array_data_compare(a, b)*-1; + return array_data_compare(a, b TSRMLS_CC)*-1; } static int array_natural_general_compare(const void *a, const void *b, int fold_case) @@ -340,12 +338,12 @@ return result; } -static int array_natural_compare(const void *a, const void *b) +static int array_natural_compare(const void *a, const void *b TSRMLS_DC) { return array_natural_general_compare(a, b, 0); } -static int array_natural_case_compare(const void *a, const void *b) +static int array_natural_case_compare(const void *a, const void *b TSRMLS_DC) { return array_natural_general_compare(a, b, 1); } @@ -367,11 +365,11 @@ } if (fold_case) { - if (zend_hash_sort(target_hash, qsort, array_natural_case_compare, 0) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_natural_case_compare, 0 TSRMLS_CC) == FAILURE) { return; } } else { - if (zend_hash_sort(target_hash, qsort, array_natural_compare, 0) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_natural_compare, 0 TSRMLS_CC) == FAILURE) { return; } } @@ -420,7 +418,7 @@ sort_type_val = Z_LVAL_PP(sort_type); } set_compare_func(sort_type_val TSRMLS_CC); - if (zend_hash_sort(target_hash, qsort, array_data_compare, 0) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_data_compare, 0 TSRMLS_CC) == FAILURE) { return; } RETURN_TRUE; @@ -449,7 +447,7 @@ sort_type_val = Z_LVAL_PP(sort_type); } set_compare_func(sort_type_val TSRMLS_CC); - if (zend_hash_sort(target_hash, qsort, array_reverse_data_compare, 0) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_reverse_data_compare, 0 TSRMLS_CC) == FAILURE) { RETURN_FALSE; } RETURN_TRUE; @@ -478,7 +476,7 @@ sort_type_val = Z_LVAL_PP(sort_type); } set_compare_func(sort_type_val TSRMLS_CC); - if (zend_hash_sort(target_hash, qsort, array_data_compare, 1) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_data_compare, 1 TSRMLS_CC) == FAILURE) { RETURN_FALSE; } RETURN_TRUE; @@ -507,26 +505,25 @@ sort_type_val = Z_LVAL_PP(sort_type); } set_compare_func(sort_type_val TSRMLS_CC); - if (zend_hash_sort(target_hash, qsort, array_reverse_data_compare, 1) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_reverse_data_compare, 1 TSRMLS_CC) == FAILURE) { RETURN_FALSE; } RETURN_TRUE; } -static int array_user_compare(const void *a, const void *b) +static int array_user_compare(const void *a, const void *b TSRMLS_DC) { Bucket *f; Bucket *s; - pval **args[2]; - pval *retval_ptr; - TSRMLS_FETCH(); + zval **args[2]; + zval *retval_ptr; f = *((Bucket **) a); s = *((Bucket **) b); - args[0] = (pval **) f->pData; - args[1] = (pval **) s->pData; + args[0] = (zval **) f->pData; + args[1] = (zval **) s->pData; if (call_user_function_ex(EG(function_table), NULL, *BG(user_compare_func_name), &retval_ptr, 2, args, 0, NULL TSRMLS_CC)==SUCCESS && retval_ptr) { @@ -560,7 +557,7 @@ BG(user_compare_func_name) = old_compare_func; RETURN_FALSE; } - if (zend_hash_sort(target_hash, qsort, array_user_compare, 1) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_user_compare, 1 TSRMLS_CC) == FAILURE) { BG(user_compare_func_name) = old_compare_func; RETURN_FALSE; } @@ -588,7 +585,7 @@ BG(user_compare_func_name) = old_compare_func; RETURN_FALSE; } - if (zend_hash_sort(target_hash, qsort, array_user_compare, 0) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_user_compare, 0 TSRMLS_CC) == FAILURE) { BG(user_compare_func_name) = old_compare_func; RETURN_FALSE; } @@ -597,7 +594,7 @@ } /* }}} */ -static int array_user_key_compare(const void *a, const void *b) +static int array_user_key_compare(const void *a, const void *b TSRMLS_DC) { Bucket *f; Bucket *s; @@ -605,7 +602,6 @@ pval *args[2]; pval retval; int status; - TSRMLS_FETCH(); args[0] = &key1; args[1] = &key2; @@ -664,7 +660,7 @@ BG(user_compare_func_name) = old_compare_func; RETURN_FALSE; } - if (zend_hash_sort(target_hash, qsort, array_user_key_compare, 0) == FAILURE) { + if (zend_hash_sort(target_hash, zend_qsort, array_user_key_compare, 0 TSRMLS_CC) == FAILURE) { BG(user_compare_func_name) = old_compare_func; RETURN_FALSE; } @@ -856,7 +852,7 @@ if (zend_get_parameters_ex(1, &arr) == FAILURE || Z_TYPE_PP(arr) != IS_ARRAY) { WRONG_PARAM_COUNT; } - if (zend_hash_minmax(Z_ARRVAL_PP(arr), array_data_compare, 0, (void **) &result)==SUCCESS) { + if (zend_hash_minmax(Z_ARRVAL_PP(arr), array_data_compare, 0, (void **) &result TSRMLS_CC)==SUCCESS) { *return_value = **result; zval_copy_ctor(return_value); } else { @@ -908,7 +904,7 @@ if (zend_get_parameters_ex(1, &arr) == FAILURE || Z_TYPE_PP(arr) != IS_ARRAY) { WRONG_PARAM_COUNT; } - if (zend_hash_minmax(Z_ARRVAL_PP(arr), array_data_compare, 1, (void **) &result)==SUCCESS) { + if (zend_hash_minmax(Z_ARRVAL_PP(arr), array_data_compare, 1, (void **) &result TSRMLS_CC)==SUCCESS) { *return_value = **result; zval_copy_ctor(return_value); } else { @@ -1376,8 +1372,8 @@ /* }}} */ -static int array_data_shuffle(const void *a, const void*b) { - TSRMLS_FETCH(); +static int array_data_shuffle(const void *a, const void *b TSRMLS_DC) +{ return (php_rand(TSRMLS_C) % 2) ? 1 : -1; } @@ -1395,7 +1391,7 @@ php_error(E_WARNING, "Wrong datatype in shuffle() call"); RETURN_FALSE; } - if (zend_hash_sort(Z_ARRVAL_PP(array), (sort_func_t)php_mergesort, array_data_shuffle, 1) == FAILURE) { + if (zend_hash_sort(Z_ARRVAL_PP(array), (sort_func_t)php_mergesort, array_data_shuffle, 1 TSRMLS_CC) == FAILURE) { RETURN_FALSE; } RETURN_TRUE; @@ -2276,12 +2272,12 @@ arTmp[i] = p; arTmp[i] = NULL; set_compare_func(SORT_STRING TSRMLS_CC); - qsort((void *) arTmp, i, sizeof(Bucket *), array_data_compare); + zend_qsort((void *) arTmp, i, sizeof(Bucket *), array_data_compare TSRMLS_CC); /* go through the sorted array and delete duplicates from the copy */ lastkept = arTmp; for (cmpdata = arTmp + 1; *cmpdata; cmpdata++) { - if (array_data_compare(lastkept, cmpdata)) { + if (array_data_compare(lastkept, cmpdata TSRMLS_CC)) { lastkept = cmpdata; } else { p = *cmpdata; @@ -2334,7 +2330,7 @@ for (p = hash->pListHead; p; p = p->pListNext) *list++ = p; *list = NULL; - qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), array_data_compare); + zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), array_data_compare TSRMLS_CC); } /* copy the argument array */ @@ -2344,7 +2340,7 @@ /* go through the lists and look for common values */ while (*ptrs[0]) { for (i=1; i<argc; i++) { - while (*ptrs[i] && (0 < (c = array_data_compare(ptrs[0], ptrs[i])))) + while (*ptrs[i] && (0 < (c = array_data_compare(ptrs[0], ptrs[i] TSRMLS_CC)))) ptrs[i]++; if (!*ptrs[i]) { /* delete any values corresponding to remains of ptrs[0] */ @@ -2374,7 +2370,7 @@ zend_hash_index_del(Z_ARRVAL_P(return_value), p->h); if (!*++ptrs[0]) goto out; - if (0 <= array_data_compare(ptrs[0], ptrs[i])) + if (0 <= array_data_compare(ptrs[0], ptrs[i] TSRMLS_CC)) break; } } else { @@ -2383,7 +2379,7 @@ for (;;) { if (!*++ptrs[0]) goto out; - if (array_data_compare(ptrs[0]-1, ptrs[0])) + if (array_data_compare(ptrs[0]-1, ptrs[0] TSRMLS_CC)) break; } } @@ -2439,7 +2435,7 @@ for (p = hash->pListHead; p; p = p->pListNext) *list++ = p; *list = NULL; - qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), array_data_compare); + zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), array_data_compare TSRMLS_CC); } /* copy the argument array */ @@ -2451,7 +2447,7 @@ while (*ptrs[0]) { c = 1; for (i=1; i<argc; i++) { - while (*ptrs[i] && (0 < (c = array_data_compare(ptrs[0], ptrs[i])))) + while (*ptrs[i] && (0 < (c = array_data_compare(ptrs[0], ptrs[i] TSRMLS_CC)))) ptrs[i]++; if (!c) { if (*ptrs[i]) @@ -2470,7 +2466,7 @@ zend_hash_index_del(Z_ARRVAL_P(return_value), p->h); if (!*++ptrs[0]) goto out; - if (array_data_compare(ptrs[0]-1, ptrs[0])) + if (array_data_compare(ptrs[0]-1, ptrs[0] TSRMLS_CC)) break; } } else { @@ -2479,7 +2475,7 @@ for (;;) { if (!*++ptrs[0]) goto out; - if (array_data_compare(ptrs[0]-1, ptrs[0])) + if (array_data_compare(ptrs[0]-1, ptrs[0] TSRMLS_CC)) break; } } @@ -2499,14 +2495,13 @@ #define MULTISORT_TYPE 1 #define MULTISORT_LAST 2 -int multisort_compare(const void *a, const void *b) +int multisort_compare(const void *a, const void *b TSRMLS_DC) { Bucket** ab = *(Bucket ***)a; Bucket** bb = *(Bucket ***)b; int r; int result = 0; zval temp; - TSRMLS_FETCH(); r = 0; do { @@ -2670,7 +2665,7 @@ indirect[k][num_arrays] = NULL; /* Do the actual sort magic - bada-bim, bada-boom. */ - qsort(indirect, array_size, sizeof(Bucket **), multisort_compare); + zend_qsort(indirect, array_size, sizeof(Bucket **), multisort_compare TSRMLS_CC); /* Restructure the arrays based on sorted indirect - this is mostly taken from zend_hash_sort() function. */ @@ -2791,7 +2786,7 @@ } if (num_req_val == num_avail) { - if (zend_hash_sort(Z_ARRVAL_P(return_value), (sort_func_t)php_mergesort, array_data_shuffle, 1) == FAILURE) { + if (zend_hash_sort(Z_ARRVAL_P(return_value), (sort_func_t)php_mergesort, array_data_shuffle, 1 TSRMLS_CC) == FAILURE) { zval_dtor(return_value); RETURN_FALSE; } Index: php4/ext/standard/php_array.h diff -u php4/ext/standard/php_array.h:1.27 php4/ext/standard/php_array.h:1.28 --- php4/ext/standard/php_array.h:1.27 Mon Jul 30 00:58:05 2001 +++ php4/ext/standard/php_array.h Mon Sep 17 17:02:52 2001 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_array.h,v 1.27 2001/07/30 04:58:05 zeev Exp $ */ +/* $Id: php_array.h,v 1.28 2001/09/17 21:02:52 sterling Exp $ */ #ifndef PHP_ARRAY_H #define PHP_ARRAY_H @@ -81,7 +81,7 @@ HashTable* php_splice(HashTable *, int, int, zval ***, int, HashTable **); PHPAPI void php_array_merge(HashTable *dest, HashTable *src, int recursive); -int multisort_compare(const void *a, const void *b); +int multisort_compare(const void *a, const void *b TSRMLS_DC); typedef struct { int *multisort_flags[2]; Index: php4/main/mergesort.c diff -u php4/main/mergesort.c:1.10 php4/main/mergesort.c:1.11 --- php4/main/mergesort.c:1.10 Sun Sep 9 09:29:28 2001 +++ php4/main/mergesort.c Mon Sep 17 17:02:53 2001 @@ -64,8 +64,8 @@ #include <winsock.h> /* Includes definition for u_char */ #endif -static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp)(const void *, const void *)); -static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const void *, const void *)); +static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC); +static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC); #define ISIZE sizeof(int) #define PSIZE sizeof(u_char *) @@ -100,7 +100,7 @@ /* {{{ php_mergesort * Arguments are as for qsort. */ -int php_mergesort(void *base, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) +int php_mergesort(void *base, size_t nmemb, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC) { register unsigned int i; register int sense; @@ -128,7 +128,7 @@ return (-1); list1 = base; - setup(list1, list2, nmemb, size, cmp); + setup(list1, list2, nmemb, size, cmp TSRMLS_CC); last = list2 + nmemb * size; i = big = 0; while (*EVAL(list2) != last) { @@ -142,7 +142,7 @@ p2 = *EVAL(p2); l2 = list1 + (p2 - list2); while (f1 < l1 && f2 < l2) { - if ((*cmp)(f1, f2) <= 0) { + if ((*cmp)(f1, f2 TSRMLS_CC) <= 0) { q = f2; b = f1, t = l1; sense = -1; @@ -152,7 +152,7 @@ sense = 0; } if (!big) { /* here i = 0 */ - while ((b += size) < t && cmp(q, b) >sense) + while ((b += size) < t && cmp(q, b TSRMLS_CC) >sense) if (++i == 6) { big = 1; goto EXPONENTIAL; @@ -161,12 +161,12 @@ EXPONENTIAL: for (i = size; ; i <<= 1) if ((p = (b + i)) >= t) { if ((p = t - size) > b && - (*cmp)(q, p) <= sense) + (*cmp)(q, p TSRMLS_CC) <= sense) t = p; else b = p; break; - } else if ((*cmp)(q, p) <= sense) { + } else if ((*cmp)(q, p TSRMLS_CC) <= sense) { t = p; if (i == size) big = 0; @@ -175,7 +175,7 @@ b = p; while (t > b+size) { i = (((t - b) / size) >> 1) * size; - if ((*cmp)(q, p = b + i) <= sense) + if ((*cmp)(q, p = b + i TSRMLS_CC) <= sense) t = p; else b = p; @@ -183,7 +183,7 @@ goto COPY; FASTCASE: while (i > size) if ((*cmp)(q, - p = b + (i >>= 1)) <= sense) + p = b + (i >>= 1) TSRMLS_CC) <= sense) t = p; else b = p; @@ -260,14 +260,14 @@ * when THRESHOLD/2 pairs compare with same sense. (Only used when NATURAL * is defined. Otherwise simple pairwise merging is used.) */ -static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp)(const void *, const void *)) +static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC) { int i, length, size2, tmp, sense; u_char *f1, *f2, *s, *l2, *last, *p2; size2 = size*2; if (n <= 5) { - insertionsort(list1, n, size, cmp); + insertionsort(list1, n, size, cmp TSRMLS_CC); *EVAL(list2) = (u_char*) list2 + n*size; return; } @@ -276,19 +276,19 @@ * for simplicity. */ i = 4 + (n & 1); - insertionsort(list1 + (n - i) * size, i, size, cmp); + insertionsort(list1 + (n - i) * size, i, size, cmp TSRMLS_CC); last = list1 + size * (n - i); *EVAL(list2 + (last - list1)) = list2 + n * size; #ifdef NATURAL p2 = list2; f1 = list1; - sense = (cmp(f1, f1 + size) > 0); + sense = (cmp(f1, f1 + size TSRMLS_CC) > 0); for (; f1 < last; sense = !sense) { length = 2; /* Find pairs with same sense. */ for (f2 = f1 + size2; f2 < last; f2 += size2) { - if ((cmp(f2, f2+ size) > 0) != sense) + if ((cmp(f2, f2+ size TSRMLS_CC) > 0) != sense) break; length += 2; } @@ -301,7 +301,7 @@ } else { /* Natural merge */ l2 = f2; for (f2 = f1 + size2; f2 < l2; f2 += size2) { - if ((cmp(f2-size, f2) > 0) != sense) { + if ((cmp(f2-size, f2 TSRMLS_CC) > 0) != sense) { p2 = *EVAL(p2) = f2 - list1 + list2; if (sense > 0) reverse(f1, f2-size); @@ -311,7 +311,7 @@ if (sense > 0) reverse (f1, f2-size); f1 = f2; - if (f2 < last || cmp(f2 - size, f2) > 0) + if (f2 < last || cmp(f2 - size, f2 TSRMLS_CC) > 0) p2 = *EVAL(p2) = f2 - list1 + list2; else p2 = *EVAL(p2) = list2 + n*size; @@ -320,7 +320,7 @@ #else /* pairwise merge only. */ for (f1 = list1, p2 = list2; f1 < last; f1 += size2) { p2 = *EVAL(p2) = p2 + size2; - if (cmp (f1, f1 + size) > 0) + if (cmp (f1, f1 + size TSRMLS_CC) > 0) swap(f1, f1 + size); } #endif /* NATURAL */ @@ -331,7 +331,7 @@ * This is to avoid out-of-bounds addresses in sorting the * last 4 elements. */ -static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const void *, const void *)) +static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC) { u_char *ai, *s, *t, *u, tmp; int i; @@ -339,7 +339,7 @@ for (ai = a+size; --n >= 1; ai += size) for (t = ai; t > a; t -= size) { u = t - size; - if (cmp(u, t) <= 0) + if (cmp(u, t TSRMLS_CC) <= 0) break; swap(u, t); } @@ -351,6 +351,6 @@ * tab-width: 4 * c-basic-offset: 4 * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 + * vim600: fdm=marker + * vim: noet sw=4 ts=4 */ Index: php4/main/php.h diff -u php4/main/php.h:1.156 php4/main/php.h:1.157 --- php4/main/php.h:1.156 Sun Sep 9 09:29:28 2001 +++ php4/main/php.h Mon Sep 17 17:02:53 2001 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php.h,v 1.156 2001/09/09 13:29:28 derick Exp $ */ +/* $Id: php.h,v 1.157 2001/09/17 21:02:53 sterling Exp $ */ #ifndef PHP_H #define PHP_H @@ -32,6 +32,7 @@ #include "php_version.h" #include "zend.h" +#include "zend_qsort.h" #include "php_compat.h" #include "zend_API.h" @@ -240,7 +241,7 @@ /* functions */ int php_startup_internal_extensions(void); -int php_mergesort(void *base, size_t nmemb, register size_t size, int (*cmp) (const void *, const void *)); +int php_mergesort(void *base, size_t nmemb, register size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC); PHPAPI void php_register_pre_request_shutdown(void (*func)(void *), void *userdata);