Skip to content

Commit

Permalink
Merge branch 'master' into valgrind
Browse files Browse the repository at this point in the history
  • Loading branch information
markuspf authored Aug 21, 2018
2 parents 77f4dce + 53d3776 commit 281c177
Show file tree
Hide file tree
Showing 12 changed files with 338 additions and 285 deletions.
14 changes: 6 additions & 8 deletions src/blister.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,18 @@ Obj CopyBlist (
Int mut )
{
Obj copy;
Obj tmp;

if (!IS_MUTABLE_OBJ(list)) {
return list;
}

copy = DoCopyBlist(list, mut);

/* leave a forwarding pointer */
tmp = NEW_PLIST( T_PLIST, 2 );
SET_LEN_PLIST( tmp, 2 );
SET_ELM_PLIST( tmp, 1, CONST_ADDR_OBJ(list)[0] );
SET_ELM_PLIST( tmp, 2, copy );
ADDR_OBJ(list)[0] = tmp;
ADDR_OBJ(list)[0] = copy;
CHANGED_BAG(list);

/* now it is copied */
RetypeBag( list, TNUM_OBJ(list) + COPYING );
return copy;
}
Expand All @@ -271,7 +269,7 @@ Obj ShallowCopyBlist ( Obj list)
*/
Obj CopyBlistCopy(Obj list, Int mut)
{
return ELM_PLIST(CONST_ADDR_OBJ(list)[0], 2);
return CONST_ADDR_OBJ(list)[0];
}


Expand All @@ -292,7 +290,7 @@ void CleanBlist (
void CleanBlistCopy(Obj list)
{
/* remove the forwarding pointer */
ADDR_OBJ(list)[0] = ELM_PLIST(CONST_ADDR_OBJ(list)[0], 1);
ADDR_OBJ(list)[0] = CONST_ADDR_OBJ(CONST_ADDR_OBJ(list)[0])[0];

/* now it is cleaned */
RetypeBag(list, TNUM_OBJ(list) - COPYING);
Expand Down
4 changes: 2 additions & 2 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2015,15 +2015,15 @@ Obj FuncIS_INPUT_TTY(Obj self)
GAP_ASSERT(IO()->Input);
if (IO()->Input->isstream)
return False;
return syBuf[IO()->Input->file].isTTY ? True : False;
return SyBufIsTTY(IO()->Input->file) ? True : False;
}

Obj FuncIS_OUTPUT_TTY(Obj self)
{
GAP_ASSERT(IO()->Output);
if (IO()->Output->isstream)
return False;
return syBuf[IO()->Output->file].isTTY ? True : False;
return SyBufIsTTY(IO()->Output->file) ? True : False;
}

Obj FuncGET_FILENAME_CACHE(Obj self)
Expand Down
36 changes: 21 additions & 15 deletions src/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,12 @@ Obj ShallowCopyObjDefault (
Obj new;
const Obj * o;
Obj * n;
UInt len;
UInt i;

/* make the new object and copy the contents */
len = (SIZE_OBJ( obj ) + sizeof(Obj)-1) / sizeof(Obj);
new = NewBag( MUTABLE_TNUM(TNUM_OBJ(obj)), SIZE_OBJ(obj) );
o = CONST_ADDR_OBJ(obj);
n = ADDR_OBJ( new );
for ( i = 0; i < len; i++ ) {
*n++ = *o++;
}
memcpy(n, o, SIZE_OBJ(obj) );

/* 'CHANGED_BAG(new);' not needed, <new> is newest object */
return new;
Expand Down Expand Up @@ -498,6 +493,12 @@ Obj CopyObjPosObj (
}

/* leave a forwarding pointer */
// Note that unlike for plists, ranges etc., we cannot simply restore the
// overwritten value (which points to the type of <obj>) by copying the
// value from <copy>, as the type may have changed in case we are making
// an immutable copy of a mutable object. Hence the forwarding pointer
// actually points to a plist with two entries: the overwritten value, and
// the actual forwarding pointer.
tmp = NEW_PLIST( T_PLIST, 2 );
SET_LEN_PLIST( tmp, 2 );
SET_ELM_PLIST(tmp, 1, CONST_ADDR_OBJ(obj)[0]);
Expand Down Expand Up @@ -601,6 +602,12 @@ Obj CopyObjComObj (
}

/* leave a forwarding pointer */
// Note that unlike for plists, ranges etc., we cannot simply restore the
// overwritten value (which points to the type of <obj>) by copying the
// value from <copy>, as the type may have changed in case we are making
// an immutable copy of a mutable object. Hence the forwarding pointer
// actually points to a plist with two entries: the overwritten value, and
// the actual forwarding pointer.
tmp = NEW_PLIST( T_PLIST, 2 );
SET_LEN_PLIST( tmp, 2 );
SET_ELM_PLIST(tmp, 1, CONST_ADDR_OBJ(obj)[0]);
Expand Down Expand Up @@ -680,7 +687,6 @@ Obj CopyObjDatObj (
{
Obj copy; /* copy, result */
Obj tmp; /* temporary variable */
UInt i; /* loop variable */
const Int * src;
Int * dst;

Expand All @@ -703,6 +709,12 @@ Obj CopyObjDatObj (
}

/* leave a forwarding pointer */
// Note that unlike for plists, ranges etc., we cannot simply restore the
// overwritten value (which points to the type of <obj>) by copying the
// value from <copy>, as the type may have changed in case we are making
// an immutable copy of a mutable object. Hence the forwarding pointer
// actually points to a plist with two entries: the overwritten value, and
// the actual forwarding pointer.
tmp = NEW_PLIST( T_PLIST, 2 );
SET_LEN_PLIST( tmp, 2 );
SET_ELM_PLIST(tmp, 1, CONST_ADDR_OBJ(obj)[0]);
Expand All @@ -716,10 +728,7 @@ Obj CopyObjDatObj (
/* copy the subvalues */
src = (const Int *)(CONST_ADDR_OBJ(obj) + 1);
dst = (Int *)(ADDR_OBJ(copy) + 1);
i = (SIZE_OBJ(obj)-sizeof(Obj)+sizeof(Int)-1) / sizeof(Int);
for ( ; 0 < i; i--, src++, dst++ ) {
*dst = *src;
}
memcpy(dst, src, SIZE_OBJ(obj)-sizeof(Obj));
CHANGED_BAG(copy);

/* return the copy */
Expand Down Expand Up @@ -1683,7 +1692,6 @@ Obj FuncCLONE_OBJ (
{
const Obj * psrc;
Obj * pdst;
Int i;

/* check <src> */
if ( IS_INTOBJ(src) ) {
Expand Down Expand Up @@ -1745,9 +1753,7 @@ Obj FuncCLONE_OBJ (
pdst = ADDR_OBJ(dst);
#endif
psrc = CONST_ADDR_OBJ(src);
for ( i = (SIZE_OBJ(src)+sizeof(Obj) - 1)/sizeof(Obj); 0 < i; i-- ) {
*pdst++ = *psrc++;
}
memcpy(pdst, psrc, SIZE_OBJ(src));
CHANGED_BAG(dst);
#ifdef HPCGAP
REGION(dst) = REGION(src);
Expand Down
8 changes: 4 additions & 4 deletions src/plist.c
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,8 @@ Obj CopyPlist (

/* copy the subvalues */
for ( i = 1; i <= LEN_PLIST(copy); i++ ) {
if ( ADDR_OBJ(list)[i] != 0 ) {
tmp = COPY_OBJ( ADDR_OBJ(list)[i], mut );
if (CONST_ADDR_OBJ(list)[i] != 0) {
tmp = COPY_OBJ(CONST_ADDR_OBJ(list)[i], mut);
ADDR_OBJ(copy)[i] = tmp;
CHANGED_BAG( copy );
}
Expand All @@ -961,7 +961,7 @@ Obj CopyPlistCopy (
Obj list,
Int mut )
{
return ADDR_OBJ(list)[0];
return CONST_ADDR_OBJ(list)[0];
}


Expand All @@ -985,7 +985,7 @@ void CleanPlistCopy (
UInt i; /* loop variable */

/* remove the forwarding pointer */
ADDR_OBJ(list)[0] = ADDR_OBJ( ADDR_OBJ(list)[0] )[0];
ADDR_OBJ(list)[0] = CONST_ADDR_OBJ(CONST_ADDR_OBJ(list)[0])[0];

/* now it is cleaned */
RetypeBag( list, TNUM_OBJ(list) - COPYING );
Expand Down
2 changes: 1 addition & 1 deletion src/precord.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ Obj CopyPRecCopy (
Obj rec,
Int mut )
{
return ADDR_OBJ(rec)[0];
return CONST_ADDR_OBJ(rec)[0];
}

void CleanPRec (
Expand Down
2 changes: 1 addition & 1 deletion src/range.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Obj CopyRangeCopy (
Obj list,
Int mut )
{
return ADDR_OBJ(list)[0];
return CONST_ADDR_OBJ(list)[0];
}


Expand Down
70 changes: 17 additions & 53 deletions src/streams.c
Original file line number Diff line number Diff line change
Expand Up @@ -1613,12 +1613,6 @@ Obj FuncPOSITION_FILE (
return Fail;
}

// Need to account for characters in buffer
if (syBuf[ifid].bufno >= 0) {
UInt bufno = syBuf[ifid].bufno;
ret -= syBuffers[bufno].buflen - syBuffers[bufno].bufstart;
}

return INTOBJ_INT(ret);
}

Expand Down Expand Up @@ -1746,31 +1740,13 @@ Obj FuncREAD_ALL_FILE (
len = 0;
lstr = 0;


if (syBuf[ifid].bufno >= 0) {
UInt bufno = syBuf[ifid].bufno;

/* first drain the buffer */
lstr = syBuffers[bufno].buflen - syBuffers[bufno].bufstart;
if (ilim != -1) {
if (lstr > ilim)
lstr = ilim;
ilim -= lstr;
}
GROW_STRING(str, lstr);
memcpy(CHARS_STRING(str),
syBuffers[bufno].buf + syBuffers[bufno].bufstart, lstr);
len = lstr;
SET_LEN_STRING(str, len);
syBuffers[bufno].bufstart += lstr;
}
#ifdef SYS_IS_CYGWIN32
getmore:
#endif
while (ilim == -1 || len < ilim ) {
if ( len > 0 && !HasAvailableBytes(ifid))
break;
if (syBuf[ifid].isTTY) {
if (SyBufIsTTY(ifid)) {
if (ilim == -1) {
Pr("#W Warning -- reading to end of input tty will never "
"end\n",
Expand All @@ -1789,11 +1765,11 @@ Obj FuncREAD_ALL_FILE (
do {
csize =
(ilim == -1 || (ilim - len) > 20000) ? 20000 : ilim - len;
lstr = SyRead(ifid, buf, csize);
lstr = SyReadWithBuffer(ifid, buf, csize);
} while (lstr == -1 && errno == EAGAIN);
}
if (lstr <= 0) {
syBuf[ifid].ateof = 1;
SyBufSetEOF(ifid);
break;
}
GROW_STRING( str, len+lstr );
Expand Down Expand Up @@ -1854,11 +1830,6 @@ Obj FuncSEEK_POSITION_FILE (
"you can replace <pos> via 'return <pos>;'" );
}

if (syBuf[INT_INTOBJ(fid)].bufno >= 0)
{
syBuffers[syBuf[INT_INTOBJ(fid)].bufno].buflen = 0;
syBuffers[syBuf[INT_INTOBJ(fid)].bufno].bufstart = 0;
}
ret = SyFseek( INT_INTOBJ(fid), INT_INTOBJ(pos) );
return ret == -1 ? Fail : True;
}
Expand Down Expand Up @@ -1951,33 +1922,26 @@ Obj FuncFD_OF_FILE(Obj self,Obj fid)
}

Int fd = INT_INTOBJ(fid);

// gzipped files don't have a fd
if (syBuf[fd].type == gzip_socket)
return INTOBJ_INT(-1);

Int fdi = syBuf[fd].fp;
Int fdi = SyBufFileno(fd);
return INTOBJ_INT(fdi);
}

#ifdef HPCGAP
Obj FuncRAW_MODE_FILE(Obj self, Obj fid, Obj onoff)
{
Int fd;
int fdi;
while (fid == (Obj) 0 || !(IS_INTOBJ(fid)))
{
fid = ErrorReturnObj(
"<fid> must be a small integer (not a %s)",
(Int)TNAM_OBJ(fid),0L,
"you can replace <fid> via 'return <fid>;'" );
}
fd = INT_INTOBJ(fid);
fdi = syBuf[fd].fp;
if (onoff == False || onoff == Fail)
return syStopraw(fdi), False;
else
return syStartraw(fdi) ? True : False;
while (!IS_INTOBJ(fid)) {
fid = ErrorReturnObj("<fid> must be a small integer (not a %s)",
(Int)TNAM_OBJ(fid), 0L,
"you can replace <fid> via 'return <fid>;'");
}

Int fd = INT_INTOBJ(fid);
if (onoff == False || onoff == Fail) {
syStopraw(fd);
return False;
}
else
return syStartraw(fd) ? True : False;
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/stringobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ Obj CopyString (

/* copy the subvalues */
memcpy(ADDR_OBJ(copy)+1, CONST_ADDR_OBJ(list)+1,
((SIZE_OBJ(copy)+sizeof(Obj)-1)/sizeof(Obj)-1) * sizeof(Obj));
SIZE_OBJ(list)-sizeof(Obj) );

/* return the copy */
return copy;
Expand Down
Loading

0 comments on commit 281c177

Please sign in to comment.