Saturday, October 19, 2013

Additional Memory Issues

Some memory errors were reported when performing memory testing on the current source.  Checking previous commits back to the last tag reported the same memory errors, which was strange because the previous commits successfully passed the memory tests.  The memory errors were reported in libglib2.0.

I remembered that there was just an update for this library within the past week, which explained why these memory errors were previously not reported.  There must be some interaction between the Qt library and the new version of this library.  These errors were added to the error suppression file so that they will no longer be reported.  These extra errors will not affect the memory tests if the update for this library is not applied.

[commit 7ccd9ac05f]

Program – Replace and Remove Lines

So far, only the insertion of program lines into the program had been implemented.  The removal  and replacement of program lines was implemented to complete the operations needed.  Some additional support functions were also needed.  The remove line routine just calls the remove routine of the QVector base class with the offset and size of the line if the size of the line if greater than zero (otherwise, no code needs to be deleted).

The replace line routine was much more involved.  If the replacement line size is zero, then the current line is deleted by calling the new remove routine.  If the replacement line is larger, then the program code vector is first resized for the net increase in the size of the line.  The code after the current line is then moved up by the net increase.  If the new line is smaller, then the code after the current line is moved down by the net decrease.  The program code vector is then resized by the net decrease in the line.  Finally, the contents of the replacement line is copied into the program.

The standard library memmove() function is used to move that program code, which is also used by the base QVector class.  The address of the code to move is obtained using the data() function of QVector (the data in the vector is guaranteed to be in continuous memory).  However, a word of caution learned while debugging: the data() function must be called after a call to the resize() function since this function may relocate the actual data.

When a line is inserted, removed or replaced with a different size line, the offset of every line after the line needs to be adjusted for the net change in program size.  To accomplish this, a new LineInfoList class was implemented based on the QList class.  The replace, insert and remove functions were reimplemented to adjust the offset of all lines after the affected line for the net change in program size.

[commit 49257e119d]

Program – Lines With Errors

For a line with a translator error, there is nothing to insert into the program for the line.  Even though there is no code to insert, the offset into where the line belongs in the program still needs to be recorded along with a size of zero.  However, if the line had an error, the offset and size for the line was not being set.  This was corrected, and as a result, the update error routine no longer needs to return whether the line has an error, which was being used as the condition whether to set the offset and size.

[commit a871ca953e]