summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSterling Hughes <sterling@php.net>2001-09-17 21:02:53 +0000
committerSterling Hughes <sterling@php.net>2001-09-17 21:02:53 +0000
commitbcb426a207baf037fd5a007e48be217bdb1a7c2b (patch)
treee743d605a5997509d1995c46ce548fdd882ee204
parentd6cecfc2135f0eb8cbc0d8c4fb7b96fdbc5bdd0e (diff)
downloadphp-git-bcb426a207baf037fd5a007e48be217bdb1a7c2b.tar.gz
Merge in qsort changes
-rw-r--r--ext/hyperwave/hg_comm.c4
-rw-r--r--ext/hyperwave/hg_comm.h4
-rw-r--r--ext/standard/array.c97
-rw-r--r--ext/standard/php_array.h2
-rw-r--r--main/mergesort.c44
-rw-r--r--main/php.h3
6 files changed, 75 insertions, 79 deletions
diff --git a/ext/hyperwave/hg_comm.c b/ext/hyperwave/hg_comm.c
index accaeb6912..8354eb5900 100644
--- a/ext/hyperwave/hg_comm.c
+++ b/ext/hyperwave/hg_comm.c
@@ -287,7 +287,7 @@ void fnListAnchor(DLIST *pAnchorList)
* 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 @@ int fnCmpAnchors(const void *e1, const void *e2)
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)
diff --git a/ext/hyperwave/hg_comm.h b/ext/hyperwave/hg_comm.h
index 4068d4619f..99ac22c189 100644
--- a/ext/hyperwave/hg_comm.h
+++ b/ext/hyperwave/hg_comm.h
@@ -154,14 +154,14 @@ void fnDeleteAnchor(void *ptr1);
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);
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 3535703e66..88622fe7c1 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -114,14 +114,13 @@ static void set_compare_func(int sort_type TSRMLS_DC)
}
}
-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 @@ static int array_key_compare(const void *a, const void *b)
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 @@ PHP_FUNCTION(krsort)
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 @@ PHP_FUNCTION(ksort)
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 @@ PHP_FUNCTION(count)
*
* 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 @@ static int array_data_compare(const void *a, const void *b)
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 @@ static int array_natural_general_compare(const void *a, const void *b, int fold_
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 @@ static void php_natsort(INTERNAL_FUNCTION_PARAMETERS, int fold_case)
}
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 @@ PHP_FUNCTION(asort)
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 @@ PHP_FUNCTION(arsort)
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 @@ PHP_FUNCTION(sort)
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 @@ PHP_FUNCTION(rsort)
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 @@ PHP_FUNCTION(usort)
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 @@ PHP_FUNCTION(uasort)
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 @@ PHP_FUNCTION(uasort)
}
/* }}} */
-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 @@ static int array_user_key_compare(const void *a, const void *b)
pval *args[2];
pval retval;
int status;
- TSRMLS_FETCH();
args[0] = &key1;
args[1] = &key2;
@@ -664,7 +660,7 @@ PHP_FUNCTION(uksort)
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 @@ PHP_FUNCTION(min)
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 @@ PHP_FUNCTION(max)
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 @@ PHP_FUNCTION(range)
/* }}} */
-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_FUNCTION(shuffle)
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 @@ PHP_FUNCTION(array_unique)
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 @@ PHP_FUNCTION(array_intersect)
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 @@ PHP_FUNCTION(array_intersect)
/* 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 @@ PHP_FUNCTION(array_intersect)
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 @@ PHP_FUNCTION(array_intersect)
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 @@ PHP_FUNCTION(array_diff)
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 @@ PHP_FUNCTION(array_diff)
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 @@ PHP_FUNCTION(array_diff)
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 @@ PHP_FUNCTION(array_diff)
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 @@ out:
#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 @@ PHP_FUNCTION(array_multisort)
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 @@ PHP_FUNCTION(array_rand)
}
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;
}
diff --git a/ext/standard/php_array.h b/ext/standard/php_array.h
index e96899af50..316d2c2a3d 100644
--- a/ext/standard/php_array.h
+++ b/ext/standard/php_array.h
@@ -81,7 +81,7 @@ PHP_FUNCTION(key_exists);
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];
diff --git a/main/mergesort.c b/main/mergesort.c
index 5ac26f5933..eaa6317c84 100644
--- a/main/mergesort.c
+++ b/main/mergesort.c
@@ -64,8 +64,8 @@ static char sccsid[] = "@(#)merge.c 8.2 (Berkeley) 2/14/94";
#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 @@ static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const voi
/* {{{ 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 @@ int php_mergesort(void *base, size_t nmemb, size_t size, int (*cmp)(const void *
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 @@ int php_mergesort(void *base, size_t nmemb, size_t size, int (*cmp)(const void *
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 @@ int php_mergesort(void *base, size_t nmemb, size_t size, int (*cmp)(const void *
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 @@ int php_mergesort(void *base, size_t nmemb, size_t size, int (*cmp)(const void *
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 @@ EXPONENTIAL: for (i = size; ; i <<= 1)
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 @@ EXPONENTIAL: for (i = size; ; i <<= 1)
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 @@ COPY: b = t;
* 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 @@ static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp
* 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 @@ static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp
} 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 @@ static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp
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 @@ static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp
#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 @@ static void setup(u_char *list1, u_char *list2, size_t n, size_t size, int (*cmp
* 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 @@ static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const voi
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 @@ static void insertionsort(u_char *a, size_t n, size_t size, int (*cmp)(const voi
* 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
*/
diff --git a/main/php.h b/main/php.h
index 1436c3ac93..c7188c7513 100644
--- a/main/php.h
+++ b/main/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 @@ int cfgparse(void);
/* 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);