From: ori@eigenstate.org
To: 9front@9front.org
Subject: [9front] make arrays big: qsort edition
Date: Thu, 29 Jul 2021 13:14:50 -0400 [thread overview]
Message-ID: <52826367713E2C7C877494CDD97A05E7@eigenstate.org> (raw)
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;
next reply other threads:[~2021-07-30 6:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-29 17:14 ori [this message]
2021-07-29 23:15 ` Nick Owens
2021-07-30 17:24 ` Steve Simon
2021-08-01 23:53 ` ori
2021-08-02 16:14 ` cinap_lenrek
2021-08-03 4:11 ` ori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52826367713E2C7C877494CDD97A05E7@eigenstate.org \
--to=ori@eigenstate.org \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).