64-bit fixes
This commit is contained in:
parent
f8e39513f3
commit
2c0f3733ad
7 changed files with 152 additions and 80 deletions
|
|
@ -3,16 +3,20 @@
|
|||
/*
|
||||
* 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*esize, 0, INCR*esize);
|
||||
l->nalloc += INCR;
|
||||
}
|
||||
}
|
||||
|
|
@ -23,19 +27,51 @@ growlist(List *l)
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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++;
|
||||
}
|
||||
|
||||
|
|
@ -45,3 +81,16 @@ listfree(List *l)
|
|||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue