Re: [PHP4BETA] (Fwd) Re: [PHP4BETA] cvs: /php4 ChangeLog /php4/ext/standard basic_functions.c basic_functions.h
| From: | Rasmus Lerdorf | Date: | Thu, 01 Jan 1970 00:00:00 +0000 |
| Subject: | Re: [PHP4BETA] (Fwd) Re: [PHP4BETA] cvs: /php4 ChangeLog /php4/ext/standard basic_functions.c basic_functions.h | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-5396@lists.php.net to get a copy of this message | ||
On Fri, 8 Oct 1999, Andrei Zmievski wrote:
> Sascha Schumann wrote:
> > Nope. As I stated earlier, qsort isn't broken (even not on
> > Solaris), so there is no reason to replace it.
>
> Ok, then it doesn't make sense to introduce merge_sort since we can just copy
> zend_hash_sort() and swap the entries around manually. I just didn't want to
> do that because zend_hash_sort() uses a lot of internal structures like
> Bucket* and calls like HANDLE_INTERRUPTIONS().
qsort() on Solaris seems pretty broken to me. When you feed it a
non-causal comparison function, it sometimes screws up.
For example, try this test broken on both Linux and Solaris:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
static int cmp(const void *a, const void *b) {
return( (rand()%2) ? -1 : 1 );
}
int main(void) {
int i,l;
char *foo = malloc(32);
srand(time(NULL));
for(i=0;i<1000;i++) {
strcpy(foo,"AAABBBAAABBBAAABBBAAABBB");
l=strlen(foo);
qsort(foo,l,1,cmp);
if(strlen(foo)!=l) printf("Broken!\n");
else printf("%s\n",foo);
}
}
Run it a few times and grep its output for "Broken". You will notice that
it never says Broken on Linux but just about always has a couple of Broken
lines on Solaris.
-Rasmus