From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 8134 invoked from network); 30 Jul 2021 06:17:40 -0000 Received: from 1ess.inri.net (216.126.196.35) by inbox.vuxu.org with ESMTPUTF8; 30 Jul 2021 06:17:40 -0000 Received: from mimir.eigenstate.org ([206.124.132.107]) by 1ess; Thu Jul 29 13:15:26 -0400 2021 Received: from abbatoir.myfiosgateway.com (pool-74-108-56-225.nycmny.fios.verizon.net [74.108.56.225]) by mimir.eigenstate.org (OpenSMTPD) with ESMTPSA id 083e87f5 (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO) for <9front@9front.org>; Thu, 29 Jul 2021 10:14:51 -0700 (PDT) Message-ID: <52826367713E2C7C877494CDD97A05E7@eigenstate.org> To: 9front@9front.org Date: Thu, 29 Jul 2021 13:14:50 -0400 From: ori@eigenstate.org MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: structured virtual database event module descriptor core-based optimizer Subject: [9front] make arrays big: qsort edition Reply-To: 9front@9front.org Precedence: bulk Since usize exists, and is now 64 bit, we should start slowly going through our code and finding the places where we're using int, short, etc in unexpected ways, so that we can start allowing big arrays. In some cases -- function parameters, mainly, this is just a matter of switching the types. In others, like strlen, we may need to go through all possible callers and make sure that a new, bigger, return type doesn't get silently truncated and cause issues. This change does qsort. --- /dist/plan9front/.git/fs/object/84b77568cda98a21dd4f3403a94c56724fbd5b37/tree//sys/include/libc.h +++ /sys/include/libc.h @@ -424,7 +424,7 @@ extern int postnote(int, int, char *); extern double pow10(int); extern int putenv(char*, char*); -extern void qsort(void*, long, long, int (*)(void*, void*)); +extern void qsort(void*, usize, usize, int (*)(void*, void*)); extern int setjmp(jmp_buf); extern double strtod(char*, char**); extern long strtol(char*, char**, int); --- /dist/plan9front/.git/fs/object/84b77568cda98a21dd4f3403a94c56724fbd5b37/tree//sys/src/libc/port/qsort.c +++ /sys/src/libc/port/qsort.c @@ -8,12 +8,12 @@ struct { int (*cmp)(void*, void*); - void (*swap)(char*, char*, long); - long es; + void (*swap)(char*, char*, usize); + usize es; } Sort; static void -swapb(char *i, char *j, long es) +swapb(char *i, char *j, usize es) { char c; @@ -27,7 +27,7 @@ } static void -swapi(char *ii, char *ij, long es) +swapi(char *ii, char *ij, usize es) { long *i, *j, c; @@ -42,9 +42,9 @@ } static char* -pivot(char *a, long n, Sort *p) +pivot(char *a, usize n, Sort *p) { - long j; + usize j; char *pi, *pj, *pk; j = n/6 * p->es; @@ -69,9 +69,9 @@ } static void -qsorts(char *a, long n, Sort *p) +qsorts(char *a, usize n, Sort *p) { - long j, es; + usize j, es; char *pi, *pj, *pn; es = p->es; @@ -111,7 +111,7 @@ } void -qsort(void *va, long n, long es, int (*cmp)(void*, void*)) +qsort(void *va, usize n, usize es, int (*cmp)(void*, void*)) { Sort s;