psplot.h bug: tries to close file twice (fixed in V. 3.02)


Bill Press
05-01-2008, 08:51 PM
Because PSplot copies the file pointer from PSpage, and is also a derived class from PSpage, it is liable to try to close the file twice. This seems to be innocuous in MSVC++ (Windows), but can cause page faults and other bad behavior in Linux. It's definitely a bug.

After some off-line discussion with davekw7x, we think that the easiest fix is to make the file pointer (and also the stored file name) static, so that a single copy is shared among all PSpages and PSplots. This introduces the slight limitation that you can't plot to more than one different plot file simultaneously with interleaved commands; you have to do them consecutively, closing each before opening the next.

Here is a diff file showing the changes:


*** psplot_old.h Tue Apr 22 17:05:08 2008
--- psplot_new.h Tue Apr 22 17:14:23 2008
***************
*** 3,4 ****
! FILE *PLT;
! char *file;
--- 3,4 ----
! static FILE *PLT;
! static char *file;
***************
*** 20 ****
! PSpage(FILE *PPLT, char *ffile) : PLT(PPLT), file(ffile){}
--- 20 ----
! PSpage(){}
***************
*** 100,101 ****
! : PSpage(page.PLT,page.file),
! pll(ppll), qll(qqll), pur(ppur), qur(qqur),
--- 100 ----
! : pll(ppll), qll(qqll), pur(ppur), qur(qqur),
***************
*** 202 ****
--- 202,203 ----
+ FILE *PSpage::PLT;
+ char *PSpage::file;


In this thread (http://www.nr.com/forum/showthread.php?t=1431), davekw7x suggested another possible fix, but we are not recommending it.