9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] make arrays big: qsort edition
@ 2021-07-29 17:14 ori
  2021-07-29 23:15 ` Nick Owens
  0 siblings, 1 reply; 6+ messages in thread
From: ori @ 2021-07-29 17:14 UTC (permalink / raw)
  To: 9front

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;
 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-08-03  9:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-29 17:14 [9front] make arrays big: qsort edition ori
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

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).