Skip to content

Commit

Permalink
Make profiling correctly handle opening the same file multiple times
Browse files Browse the repository at this point in the history
This patch ensures when reopening a file we check if the filename
has been opened previously, and if so associate it with the same
filename number.

This is tested in the 'profiling' package, which is why there is no
tests here.
  • Loading branch information
ChrisJefferson authored and fingolfin committed Jan 13, 2017
1 parent 3306f0f commit 06d8435
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

#include "code.h" /* coder */

#include "bool.h" /* For fail */

#include "saveload.h" /* saving and loading */
#include "read.h" /* to access stack of for loop globals */
#include "gvars.h"
Expand Down Expand Up @@ -120,14 +122,23 @@ static inline void PopLoopNesting( void ) {
static inline void setup_gapname(TypInputFile* i)
{
UInt len;
Obj pos;
if(!i->gapname) {
C_NEW_STRING_DYN(i->gapname, i->name);
len = LEN_PLIST( FilenameCache );
GROW_PLIST( FilenameCache, len+1 );
SET_LEN_PLIST( FilenameCache, len+1 );
SET_ELM_PLIST( FilenameCache, len+1, i->gapname );
CHANGED_BAG( FilenameCache );
i->gapnameid = len+1;
pos = POS_LIST( FilenameCache, i->gapname, INTOBJ_INT(1) );
if(pos == Fail) {
len = LEN_PLIST( FilenameCache );
GROW_PLIST( FilenameCache, len+1 );
SET_LEN_PLIST( FilenameCache, len+1 );
SET_ELM_PLIST( FilenameCache, len+1, i->gapname );
CHANGED_BAG( FilenameCache );
i->gapnameid = len + 1;
}
else {
i->gapnameid = INT_INTOBJ(pos);
// Use string from FilenameCache as we know it will not get GCed
i->gapname = ELM_LIST( FilenameCache, i->gapnameid );
}
}
}

Expand Down

0 comments on commit 06d8435

Please sign in to comment.