>
> Hi All
> I have had the exit() calls in Plplot rolling around in the back of my head 
> for a while. They were brought to the fore, recently when I had some code 
> which generated a lot of plots and displayed them all via wxWidgets - except 
> it didn't. The program exited half way through. It turned out that I ran out 
> of memory and this caused a call to plexit which exited my code without even 
> an unhandled exception error, which is what I usually expect with out of 
> memory problems. Also the move to git has got me excited about doing some 
> work.
>
> Obviously the API functions do not return an error code, but we do have the 
> plserror function which allows us to report errors back to the user. The 
> difficulty however is more internal. If the program runs out of memory, but 
> we allow things to continue, then when attempts are made to access the array 
> then we'll get a segfault or similar crash.
>
> As far as I can see we have two solutions:
> 1) Change all internal functions so they return an error code. If another 
> internal function finds it is passed an error code then in must clean up and 
> return this error code - which passes down the chain. This sounds quite 
> difficult as some functions already return values. Also if an internal 
> function calls an API function we break the chain.
> 2) Add an internalerrorcode variable to PLStream. This is reset to 0 when an 
> API call is made, and if a function generates an error then this code and the 
> user's code) get set and the calling function can check this. The downside 
> here is probably a lot of error checking, but?I don't think this can be 
> helped.
>
> I'm in favour of 2), mostly because I haven't thought of any killer problems 
> like 1). Has anyone got any thoughts before I start working on this?

What fraction of the functions would have to changed for (1)? Glancing 
through the API it seems that only a small fraction of them return a 
value. I would guess that most of the work is going to be doing all the 
error checking, which is likely more or less the same for either (1) or 
(2). I thought (1) was the approach that most libraries used, but 
looking at the Cairo, Gtk, WxWidgets and Qt libraries it appears that 
they do not use either. Qt and WxWidgets probably throw more or less 
meaningful exceptions. I'm not sure what Cairo and GTK would do, maybe 
they just segfault?

How about the minimalist change of just removing the exit() from 
plexit()? Yes the program will continue to run, but a modern OS can 
pretty easily deal with any trouble it is likely to cause. And if the 
user really wants the exit behavior then they can implement it in their 
own exit handler.

-Hazen


------------------------------------------------------------------------------
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel

Reply via email to