Plan 9 from Bell Labs’s /usr/web/sources/contrib/uriel/changes/2005/1119/6

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


64-bit fixes.
 [jmk] --rw-rw-r-- M 107020 glenda sys 10774 Nov 19 20:09 sys/src/cmd/sam/cmd.c
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/cmd.c:50,59 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/cmd.c:50,61
	  Rune	*linep = line;
	  Rune	*terminp = termline;
	  Rune	*termoutp = termline;
	- List	cmdlist;
	- List	addrlist;
	- List	relist;
	- List	stringlist;
	+ 
	+ List	cmdlist = { 'p' };
	+ List	addrlist = { 'p' };
	+ List	relist = { 'p' };
	+ List	stringlist = { 'p' };
	+ 
	  int	eof;
	  
	  void
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/cmd.c:244,250 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/cmd.c:246,252
	  	Cmd *p;
	  
	  	p = emalloc(sizeof(Cmd));
	- 	inslist(&cmdlist, cmdlist.nused, (long)p);
	+ 	inslist(&cmdlist, cmdlist.nused, p);
	  	return p;
	  }
	  
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/cmd.c:254,260 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/cmd.c:256,262
	  	Addr *p;
	  
	  	p = emalloc(sizeof(Addr));
	- 	inslist(&addrlist, addrlist.nused, (long)p);
	+ 	inslist(&addrlist, addrlist.nused, p);
	  	return p;
	  }
	  
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/cmd.c:264,270 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/cmd.c:266,272
	  	String *p;
	  
	  	p = emalloc(sizeof(String));
	- 	inslist(&relist, relist.nused, (long)p);
	+ 	inslist(&relist, relist.nused, p);
	  	Strinit(p);
	  	return p;
	  }
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/cmd.c:275,281 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/cmd.c:277,283
	  	String *p;
	  
	  	p = emalloc(sizeof(String));
	- 	inslist(&stringlist, stringlist.nused, (long)p);
	+ 	inslist(&stringlist, stringlist.nused, p);
	  	Strinit(p);
	  	return p;
	  }
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/cmd.c:286,294 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/cmd.c:288,296
	  	int i;
	  
	  	while(cmdlist.nused > 0)
	- 		free(cmdlist.ucharpptr[--cmdlist.nused]);
	+ 		free(cmdlist.voidpptr[--cmdlist.nused]);
	  	while(addrlist.nused > 0)
	- 		free(addrlist.ucharpptr[--addrlist.nused]);
	+ 		free(addrlist.voidpptr[--addrlist.nused]);
	  	while(relist.nused > 0){
	  		i = --relist.nused;
	  		Strclose(relist.stringpptr[i]);
 [jmk] --rw-rw-r-- M 107020 glenda sys 1431 Nov 19 20:09 sys/src/cmd/sam/list.c
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/list.c:3,18 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/list.c:3,22
	  /*
	   * Check that list has room for one more element.
	   */
	- void
	- growlist(List *l)
	+ static void
	+ growlist(List *l, int esize)
	  {
	- 	if(l->listptr==0 || l->nalloc==0){
	+ 	uchar *p;
	+ 
	+ 	if(l->listptr == nil || l->nalloc == 0){
	  		l->nalloc = INCR;
	- 		l->listptr = emalloc(INCR*sizeof(long));
	+ 		l->listptr = emalloc(INCR*esize);
	  		l->nused = 0;
	- 	}else if(l->nused == l->nalloc){
	- 		l->listptr = erealloc(l->listptr, (l->nalloc+INCR)*sizeof(long));
	- 		memset((void*)(l->longptr+l->nalloc), 0, INCR*sizeof(long));
	+ 	}
	+ 	else if(l->nused == l->nalloc){
	+ 		p = erealloc(l->listptr, (l->nalloc+INCR)*esize);
	+ 		l->listptr = p;
	+ 		memset(p+l->nalloc, 0, INCR*esize);
	  		l->nalloc += INCR;
	  	}
	  }
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/list.c:23,30 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/list.c:27,47
	  void
	  dellist(List *l, int i)
	  {
	- 	memmove(&l->longptr[i], &l->longptr[i+1], (l->nused-(i+1))*sizeof(long));
	+ 	Posn *pp;
	+ 	void **vpp;
	+ 
	  	l->nused--;
	+ 
	+ 	switch(l->type){
	+ 	case 'P':
	+ 		pp = l->posnptr+i;
	+ 		memmove(pp, pp+1, (l->nused-i)*sizeof(*pp));
	+ 		break;
	+ 	case 'p':
	+ 		vpp = l->voidpptr+i;
	+ 		memmove(vpp, vpp+1, (l->nused-i)*sizeof(*vpp));
	+ 		break;
	+ 	}
	  }
	  
	  /*
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/list.c:31,41 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/list.c:48,77
	   * Add a new element, whose position is i, to the list
	   */
	  void
	- inslist(List *l, int i, long val)
	+ inslist(List *l, int i, ...)
	  {
	- 	growlist(l);
	- 	memmove(&l->longptr[i+1], &l->longptr[i], (l->nused-i)*sizeof(long));
	- 	l->longptr[i] = val;
	+ 	Posn *pp;
	+ 	void **vpp;
	+ 	va_list list;
	+ 
	+ 
	+ 	va_start(list, i);
	+ 	switch(l->type){
	+ 	case 'P':
	+ 		growlist(l, sizeof(*pp));
	+ 		pp = l->posnptr+i;
	+ 		memmove(pp+1, pp, (l->nused-i)*sizeof(*pp));
	+ 		*pp = va_arg(list, Posn);
	+ 		break;
	+ 	case 'p':
	+ 		growlist(l, sizeof(*vpp));
	+ 		vpp = l->voidpptr+i;
	+ 		memmove(vpp+1, vpp, (l->nused-i)*sizeof(*vpp));
	+ 		*vpp = va_arg(list, void*);
	+ 		break;
	+ 	}
	+ 	va_end(list);
	+ 
	  	l->nused++;
	  }
	  
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/list.c:44,47 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/list.c:80,96
	  {
	  	free(l->listptr);
	  	free(l);
	+ }
	+ 
	+ List*
	+ listalloc(int type)
	+ {
	+ 	List *l;
	+ 
	+ 	l = emalloc(sizeof(List));
	+ 	l->type = type;
	+ 	l->nalloc = 0;
	+ 	l->nused = 0;
	+ 
	+ 	return l;
	  }
 [jmk] --rw-rw-r-- M 107020 glenda sys 14291 Nov 19 20:09 sys/src/cmd/sam/mesg.c
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/mesg.c:13,22 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/mesg.c:13,30
	  int	noflush;
	  int	tversion;
	  
	- long	inlong(void);
	- long	invlong(void);
	  int	inshort(void);
	+ long	inlong(void);
	+ vlong	invlong(void);
	  int	inmesg(Tmesg);
	+ 
	+ void	outshort(int);
	+ void	outlong(long);
	+ void	outvlong(vlong);
	+ void	outcopy(int, void*);
	+ void	outsend(void);
	+ void	outstart(Hmesg);
	+ 
	  void	setgenstr(File*, Posn, Posn);
	  
	  #ifdef DEBUG
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/mesg.c:90,101 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/mesg.c:98,119
	  {
	  	char buf[32];
	  
	- 	sprint(buf, "%ld", n);
	+ 	snprint(buf, sizeof(buf), "%ld", n);
	  	journal(out, buf);
	  }
	+ 
	+ void
	+ journalv(int out, vlong v)
	+ {
	+ 	char buf[32];
	+ 
	+ 	sprint(buf, sizeof(buf), "%lld", v);
	+ 	journal(out, buf);
	+ }
	  #else
	  #define	journal(a, b)
	  #define journaln(a, b)
	+ #define journalv(a, b)
	  #endif
	  
	  int
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/mesg.c:176,181 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/mesg.c:194,200
	  	int i, m;
	  	short s;
	  	long l, l1;
	+ 	vlong v;
	  	File *f;
	  	Posn p0, p1, p;
	  	Range r;
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/mesg.c:204,218 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/mesg.c:223,237
	  		break;
	  
	  	case Tstartcmdfile:
	- 		l = invlong();		/* for 64-bit pointers */
	- 		journaln(0, l);
	+ 		v = invlong();		/* for 64-bit pointers */
	+ 		journalv(0, v);
	  		Strdupl(&genstr, samname);
	  		cmd = newfile();
	  		cmd->unread = 0;
	- 		outTsv(Hbindname, cmd->tag, l);
	+ 		outTsv(Hbindname, cmd->tag, v);
	  		outTs(Hcurrent, cmd->tag);
	  		logsetname(cmd, &genstr);
	- 		cmd->rasp = emalloc(sizeof(List));
	+ 		cmd->rasp = listalloc('P');
	  		cmd->mod = 0;
	  		if(cmdstr.n){
	  			loginsert(cmd, 0L, cmdstr.s, cmdstr.n);
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/mesg.c:263,269 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/mesg.c:282,288
	  		termlocked++;
	  		f = whichfile(inshort());
	  		if(!f->rasp)	/* this might be a duplicate message */
	- 			f->rasp = emalloc(sizeof(List));
	+ 			f->rasp = listalloc('P');
	  		current(f);
	  		outTsv(Hbindname, f->tag, invlong());	/* for 64-bit pointers */
	  		outTs(Hcurrent, f->tag);
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/mesg.c:353,363 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/mesg.c:372,382
	  		break;
	  
	  	case Tstartnewfile:
	- 		l = invlong();
	+ 		v = invlong();
	  		Strdupl(&genstr, empty);
	  		f = newfile();
	- 		f->rasp = emalloc(sizeof(List));
	- 		outTsv(Hbindname, f->tag, l);
	+ 		f->rasp = listalloc('P');
	+ 		outTsv(Hbindname, f->tag, v);
	  		logsetname(f, &genstr);
	  		outTs(Hcurrent, f->tag);
	  		current(f);
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/mesg.c:593,608 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/mesg.c:612,627
	  	return n;
	  }
	  
	- long
	+ vlong
	  invlong(void)
	  {
	- 	ulong n;
	+ 	vlong v;
	  	
	- 	n = (inp[7]<<24) | (inp[6]<<16) | (inp[5]<<8) | inp[4];
	- 	n = (n<<16) | (inp[3]<<8) | inp[2];
	- 	n = (n<<16) | (inp[1]<<8) | inp[0];
	+ 	v = (inp[7]<<24) | (inp[6]<<16) | (inp[5]<<8) | inp[4];
	+ 	v = (v<<16) | (inp[3]<<8) | inp[2];
	+ 	v = (v<<16) | (inp[1]<<8) | inp[0];
	  	inp += 8;
	- 	return n;
	+ 	return v;
	  }
	  
	  void
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/mesg.c:732,743 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/mesg.c:751,762
	  }
	  
	  void
	- outTsv(Hmesg type, int s, Posn l)
	+ outTsv(Hmesg type, int s, vlong v)
	  {
	  	outstart(type);
	  	outshort(s);
	- 	outvlong((void*)l);
	- 	journaln(1, l);
	+ 	outvlong(v);
	+ 	journalv(1, v);
	  	outsend();
	  }
	  
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/mesg.c:773,786 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/mesg.c:792,805
	  }
	  
	  void
	- outvlong(void *v)
	+ outvlong(vlong v)
	  {
	  	int i;
	- 	ulong l;
	  
	- 	l = (ulong) v;
	- 	for(i = 0; i < 8; i++, l >>= 8)
	- 		*outp++ = l;
	+ 	for(i = 0; i < 8; i++){
	+ 		*outp++ = v;
	+ 		v >>= 8;
	+ 	}
	  }
	  
	  void
 [jmk] --rw-rw-r-- M 107020 glenda sys 1844 Nov 19 20:09 sys/src/cmd/sam/multi.c
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/multi.c:1,6 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/multi.c:1,6
	  #include "sam.h"
	  
	- List	file;
	+ List	file = { 'p' };
	  ushort	tag;
	  
	  File *
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/multi.c:9,15 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/multi.c:9,15
	  	File *f;
	  
	  	f = fileopen();
	- 	inslist(&file, 0, (long)f);
	+ 	inslist(&file, 0, f);
	  	f->tag = tag++;
	  	if(downloaded)
	  		outTs(Hnewname, f->tag);
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/multi.c:88,94 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/multi.c:88,94
	  				break;
	  		}
	  	}
	- 	inslist(&file, i, (long)f);
	+ 	inslist(&file, i, f);
	  	if(downloaded)
	  		outTsS(Hmovname, f->tag, &f->name);
	  }
 [jmk] --rw-rw-r-- M 107020 glenda sys 5618 Nov 19 20:09 sys/src/cmd/sam/rasp.c
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/rasp.c:177,183 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/rasp.c:177,183
	  }
	  
	  #define	M	0x80000000L
	- #define	P(i)	r->longptr[i]
	+ #define	P(i)	r->posnptr[i]
	  #define	T(i)	(P(i)&M)	/* in terminal */
	  #define	L(i)	(P(i)&~M)	/* length of this piece */
	  
 [jmk] --rw-rw-r-- M 107020 glenda sys 12016 Nov 19 20:09 sys/src/cmd/sam/sam.c
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/sam.c:14,20 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/sam.c:14,20
	  File	*flist;
	  File	*cmd;
	  jmp_buf	mainloop;
	- List	tempfile;
	+ List	tempfile = { 'p' };
	  int	quitok = TRUE;
	  int	downloaded;
	  int	dflag;
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/sam.c:73,79 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/sam.c:73,78
	  	Strinit0(&genstr);
	  	Strinit0(&rhs);
	  	Strinit0(&curwd);
	- 	tempfile.listptr = emalloc(1);	/* so it can be freed later */
	  	Strinit0(&plan9cmd);
	  	home = getenv(HOME);
	  	disk = diskinit();
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/sam.c:707,716 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/sam.c:706,716
	  settempfile(void)
	  {
	  	if(tempfile.nalloc < file.nused){
	- 		free(tempfile.listptr);
	- 		tempfile.listptr = emalloc(sizeof(*tempfile.filepptr)*file.nused);
	+ 		if(tempfile.filepptr)
	+ 			free(tempfile.filepptr);
	+ 		tempfile.filepptr = emalloc(sizeof(File*)*file.nused);
	  		tempfile.nalloc = file.nused;
	  	}
	+ 	memmove(tempfile.filepptr, file.filepptr, sizeof(File*)*file.nused);
	  	tempfile.nused = file.nused;
	- 	memmove(&tempfile.filepptr[0], &file.filepptr[0], file.nused*sizeof(File*));
	  }
 [jmk] --rw-rw-r-- M 107020 glenda sys 9345 Nov 19 20:09 sys/src/cmd/sam/sam.h
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/sam.h:64,91 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/sam.h:64,89
	  	Rune	*s;
	  };
	  
	- struct List	/* code depends on a long being able to hold a pointer */
	+ struct List
	  {
	+ 	int	type;
	  	int	nalloc;
	  	int	nused;
	  	union{
	- 		void	*listp;
	- 		Block	*blkp;
	- 		long	*longp;
	- 		uchar*	*ucharp;
	- 		String*	*stringp;
	- 		File*	*filep;
	- 		long	listv;
	+ 		void*	listp;
	+ 		Block*	blkp;
	+ 		void**	voidp;
	+ 		Posn*	posnp;
	+ 		String**stringp;
	+ 		File**	filep;
	  	}g;
	  };
	  
	  #define	listptr		g.listp
	- #define	blkptr		g.blkp
	- #define	longptr		g.longp
	- #define	ucharpptr	g.ucharp
	+ #define	voidpptr	g.voidp
	+ #define	posnptr		g.posnp
	  #define	stringpptr	g.stringp
	  #define	filepptr	g.filep
	- #define	listval		g.listv
	  
	  enum
	  {
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/sam.h:262,269 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/sam.h:260,268
	  int	getname(File*, String*, int);
	  long	getnum(int);
	  void	hiccough(char*);
	- void	inslist(List*, int, long);
	+ void	inslist(List*, int, ...);
	  Address	lineaddr(Posn, Address, int);
	+ List	*listalloc(int);
	  void	listfree(List*);
	  void	load(File*);
	  File	*lookfile(String*);
	/n/sourcesdump/2005/1119/plan9/sys/src/cmd/sam/sam.h:396,406 - 
	/n/sourcesdump/2005/1120/plan9/sys/src/cmd/sam/sam.h:395,399
	  void	outTsllS(Hmesg, int, long, long, String*);
	  void	outTsll(Hmesg, int, long, long);
	  void	outTsl(Hmesg, int, long);
	- void	outTsv(Hmesg, int, long);
	- void	outstart(Hmesg);
	- void	outcopy(int, void*);
	- void	outshort(int);
	- void	outlong(long);
	- void	outvlong(void*);
	- void	outsend(void);
	+ void	outTsv(Hmesg, int, vlong);
	  void	outflush(void);


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].