Skip to content

Commit

Permalink
make SDL_qsort.c to actually link (missing SDL_stdinc.h include)
Browse files Browse the repository at this point in the history
also sync its comments with version 1.15 from mainstream
  • Loading branch information
sezero committed Sep 14, 2019
1 parent 301432f commit f5344c2
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/stdlib/SDL_qsort.c
Expand Up @@ -22,6 +22,7 @@
#include "SDL_config.h"

#ifndef HAVE_QSORT
#include "SDL_stdinc.h"

#ifdef assert
#undef assert
Expand Down Expand Up @@ -50,7 +51,7 @@

/*
This code came from Gareth McCaughan, under the zlib license.
Specifically this: https://www.mccaughan.org.uk/software/qsort.c-1.14
Specifically this: https://www.mccaughan.org.uk/software/qsort.c-1.15
Everything below this comment until the HAVE_QSORT #endif was from Gareth
(any minor changes will be noted inline).
Expand Down Expand Up @@ -129,17 +130,21 @@ benefit!
* 2016-02-21 v1.14 Replace licence with 2-clause BSD,
* and clarify a couple of things in
* comments. No code changes.
* 2016-03-10 v1.15 Fix bug kindly reported by Ryan Gordon
* (pre-insertion-sort messed up).
* Disable DEBUG_QSORT by default.
* Tweak comments very slightly.
*/

/* BEGIN SDL CHANGE ... commented this out with an #if 0 block. --ryan. */
#if 0
#include <assert.h>
#include <stdlib.h>
#include <string.h>

/* BEGIN SDL CHANGE ... commented this out with an #if 0 block. --ryan. */
#if 0
#define DEBUG_QSORT
#undef DEBUG_QSORT

static char _ID[]="<qsort.c gjm 1.14 2016-02-21>";
static char _ID[]="<qsort.c gjm 1.15 2016-03-10>";
#endif
/* END SDL CHANGE ... commented this out with an #if 0 block. --ryan. */

Expand Down Expand Up @@ -302,7 +307,9 @@ typedef struct { char * first; char * last; } stack_entry;
* We find the smallest element from the first |nmemb|,
* or the first |limit|, whichever is smaller;
* therefore we must have ensured that the globally smallest
* element is in the first |limit|.
* element is in the first |limit| (because our
* quicksort recursion bottoms out only once we
* reach subarrays smaller than |limit|).
*/
#define PreInsertion(swapper,limit,sz) \
first=base; \
Expand Down Expand Up @@ -485,7 +492,7 @@ fprintf(stderr, "after partitioning first=#%lu last=#%lu\n", (first-(char*)base)
Recurse(TRUNC_words)
}
}
PreInsertion(SWAP_words,(TRUNC_words/WORD_BYTES),WORD_BYTES);
PreInsertion(SWAP_words,TRUNC_words/WORD_BYTES,WORD_BYTES);
/* Now do insertion sort. */
last=((char*)base)+nmemb*WORD_BYTES;
for (first=((char*)base)+WORD_BYTES;first!=last;first+=WORD_BYTES) {
Expand Down

0 comments on commit f5344c2

Please sign in to comment.