comp.lang.ada
 help / color / mirror / Atom feed
* ANN: PLplot plotting library with Ada bindings
@ 2013-10-02  0:31 Jerry
  2013-10-02  0:45 ` Jeffrey Carter
  2013-11-12 15:27 ` Graham Stark
  0 siblings, 2 replies; 11+ messages in thread
From: Jerry @ 2013-10-02  0:31 UTC (permalink / raw)


PLplot 5.9.10 has just been released. PLplot is an extensive plotting library with Ada bindings.

http://plplot.sourceforge.net/

In addition to the bindings, the Ada component adds substantial ease-of-use functionality that eliminates the need to learn and code a lot of set-up routines. These easy-to-use routines will work for most day-to-day plotting. For example, to make an x-y plot:


with
   PLplot;
use
   PLplot;
procedure Simple_Example is
   x, y : Real_Vector(-10 .. 10);
begin
   for i in x'range loop 
      x(i) := Long_Float(i);
      y(i) := x(i)**2;
   end loop;
   Initialize_PLplot; -- Call this only once.
   Simple_Plot(x, y); -- Make the plot.
   -- Make more plots here.
   End_PLplot;        -- Call this only once.
end Simple_Example;


Jerry


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: ANN: PLplot plotting library with Ada bindings
  2013-10-02  0:31 ANN: PLplot plotting library with Ada bindings Jerry
@ 2013-10-02  0:45 ` Jeffrey Carter
  2013-10-03  4:39   ` Anatoly Chernyshev
  2013-10-04 23:55   ` Jerry
  2013-11-12 15:27 ` Graham Stark
  1 sibling, 2 replies; 11+ messages in thread
From: Jeffrey Carter @ 2013-10-02  0:45 UTC (permalink / raw)


On 10/01/2013 05:31 PM, Jerry wrote:
>
> withPLplot;
> usePLplot;
> procedure Simple_Example is
 >     ...
> begin
>     Initialize_PLplot; -- Call this only once.

Why doesn't the elaboration of Plplot do this?
 >     ...
>     End_PLplot;        -- Call this only once.

Why not use finalization to do this?

-- 
Jeff Carter
"This school was here before you came,
and it'll be here before you go."
Horse Feathers
48

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: ANN: PLplot plotting library with Ada bindings
  2013-10-02  0:45 ` Jeffrey Carter
@ 2013-10-03  4:39   ` Anatoly Chernyshev
  2013-10-03  5:27     ` Jeffrey Carter
  2013-10-04 23:55   ` Jerry
  1 sibling, 1 reply; 11+ messages in thread
From: Anatoly Chernyshev @ 2013-10-03  4:39 UTC (permalink / raw)


> >     Initialize_PLplot; -- Call this only once.
> Why doesn't the elaboration of Plplot do this?
> >     End_PLplot;        -- Call this only once.
> Why not use finalization to do this?

Maybe because this is a binding, not the original construct. In any case, the plots examples are of high quality, comparable to those of MathCad and SigmaPlot. 

I didn't play with the Ada sources yet, but definitely will make a note of that package for the cases when more than one plot needs to be created (thanks to the authors). 

So far I used to print Ada output in a csv file to further export in a plotting program.

Anatoly


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: ANN: PLplot plotting library with Ada bindings
  2013-10-03  4:39   ` Anatoly Chernyshev
@ 2013-10-03  5:27     ` Jeffrey Carter
  0 siblings, 0 replies; 11+ messages in thread
From: Jeffrey Carter @ 2013-10-03  5:27 UTC (permalink / raw)


On 10/02/2013 09:39 PM, Anatoly Chernyshev wrote:
>>> Initialize_PLplot; -- Call this only once.
>> Why doesn't the elaboration of Plplot do this?
>>> End_PLplot;        -- Call this only once.
>> Why not use finalization to do this?
>
> Maybe because this is a binding, not the original construct.

A binding can do that, too.

-- 
Jeff Carter
"Go and boil your bottoms."
Monty Python & the Holy Grail
01


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: ANN: PLplot plotting library with Ada bindings
  2013-10-02  0:45 ` Jeffrey Carter
  2013-10-03  4:39   ` Anatoly Chernyshev
@ 2013-10-04 23:55   ` Jerry
  2013-10-19  2:27     ` Randy Brukardt
  1 sibling, 1 reply; 11+ messages in thread
From: Jerry @ 2013-10-04 23:55 UTC (permalink / raw)


On Tuesday, October 1, 2013 5:45:57 PM UTC-7, Jeffrey Carter wrote:
> On 10/01/2013 05:31 PM, Jerry wrote:
> >
> > withPLplot;
> > usePLplot;
> > procedure Simple_Example is
>  >     ...
> > begin
> >     Initialize_PLplot; -- Call this only once.
> 
> Why doesn't the elaboration of Plplot do this?

In some scenarios of PLplot usage, some set-up (i.e., other PLplot calls) is required before Initialize_Plot is called. Of course, this is a matter of how the C library is designed, not the Ada bindings.

>  >     ...
> >     End_PLplot;        -- Call this only once.
> 
> Why not use finalization to do this?

I don't think there are any issues analogous to the above. I might look into this; I think in the past I said, well if the user has to initialize, s/he might as well be bothered to finalize. I don't think it would be confusing to a user to be forced to explicitly initialize but not to explicitly finalize. I don't know what happens if the library doesn't get finalized but it probably ties up resources so an automatic process would be wise in that sense. OTOH, with an opportunity to explicitly do the finalization, the user has the option to free those resources at a more optimal time. So the best design might be to provide both finalization mechanisms.

Jerry
> 
> -- 
> Jeff Carter
> "This school was here before you came,
> and it'll be here before you go."
> Horse Feathers
> 48

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: ANN: PLplot plotting library with Ada bindings
  2013-10-04 23:55   ` Jerry
@ 2013-10-19  2:27     ` Randy Brukardt
  2013-10-22  4:20       ` Jerry
  0 siblings, 1 reply; 11+ messages in thread
From: Randy Brukardt @ 2013-10-19  2:27 UTC (permalink / raw)


"Jerry" <lanceboyle@qwest.net> wrote in message 
news:9006bf4b-e682-4803-a5e3-b0363ecb61d1@googlegroups.com...
On Tuesday, October 1, 2013 5:45:57 PM UTC-7, Jeffrey Carter wrote:
> On 10/01/2013 05:31 PM, Jerry wrote:
...
>>  >     ...
>> >     End_PLplot;        -- Call this only once.
>>
>> Why not use finalization to do this?
>
>...
>I don't know what happens if the library doesn't get finalized but it 
>probably ties up
>resources so an automatic process would be wise in that sense.

The problem with requiring manual finalization is that it doesn't work when 
the program propagates an exception. In that case, the user's explicit call 
doesn't get executed. You could try to require them to handle such 
exceptions and do the finalization in a handler, but that's both a mess and 
something that's easy to forget. And even that doesn't work in the face of 
abort (although that's probably not a significant concern in this case).

Thus, I think you always want automatic finalization if any is needed. It 
might make sense to also support a manual version (especially in this case, 
where you wouldn't want to force an incompatibility on any of your users, 
which you would if you completely got rid of the End_PLPlot routine.) -- but 
you don't want that manual version to be required. (Of course, this assumes 
that the finalization actually does something important; if the OS cleans up 
well enough after an program that terminated unexpectedly, then this doesn't 
apply.)

Even if *correct* programs would be fine with manual finalization, remember 
that the program will fail many times while you're creating and debugging 
it. You don't want that to suck up resources on the user's computer.

                                  Randy.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: ANN: PLplot plotting library with Ada bindings
  2013-10-19  2:27     ` Randy Brukardt
@ 2013-10-22  4:20       ` Jerry
  0 siblings, 0 replies; 11+ messages in thread
From: Jerry @ 2013-10-22  4:20 UTC (permalink / raw)


On Friday, October 18, 2013 7:27:50 PM UTC-7, Randy Brukardt wrote:
> "Jerry"  wrote in message 
> On Tuesday, October 1, 2013 5:45:57 PM UTC-7, Jeffrey Carter wrote:
> > On 10/01/2013 05:31 PM, Jerry wrote:
> ...
> >>  >     ...
> >> >     End_PLplot;        -- Call this only once.
> >>
> >> Why not use finalization to do this?
> >
> >...
> >I don't know what happens if the library doesn't get finalized but it 
> >probably ties up
> >resources so an automatic process would be wise in that sense.
> 
> The problem with requiring manual finalization is that it doesn't work when 
> the program propagates an exception. In that case, the user's explicit call 
> doesn't get executed. You could try to require them to handle such 
> exceptions and do the finalization in a handler, but that's both a mess and 
> something that's easy to forget. And even that doesn't work in the face of 
> abort (although that's probably not a significant concern in this case).
> 
> Thus, I think you always want automatic finalization if any is needed. It 
> might make sense to also support a manual version (especially in this case, 
> where you wouldn't want to force an incompatibility on any of your users, 
> which you would if you completely got rid of the End_PLPlot routine.) -- but 
> you don't want that manual version to be required. (Of course, this assumes 
> that the finalization actually does something important; if the OS cleans up 
> well enough after an program that terminated unexpectedly, then this doesn't 
> apply.)
> 
> Even if *correct* programs would be fine with manual finalization, remember 
> that the program will fail many times while you're creating and debugging 
> it. You don't want that to suck up resources on the user's computer.
> 
>                                   Randy.

Good point. Thanks, Randy. I think I'll work this into the next release.
Jerry

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: ANN: PLplot plotting library with Ada bindings
  2013-10-02  0:31 ANN: PLplot plotting library with Ada bindings Jerry
  2013-10-02  0:45 ` Jeffrey Carter
@ 2013-11-12 15:27 ` Graham Stark
  2013-11-13 22:51   ` Jerry
  2013-11-15  5:16   ` Jerry
  1 sibling, 2 replies; 11+ messages in thread
From: Graham Stark @ 2013-11-12 15:27 UTC (permalink / raw)


Hi Jerry,

That looks really interesting.

I'm looking for a plotter routine that could be used safely inside the AWS web server, so I can implement a 'callback' chart server (currently I have one written in Java). 

Could this be used for that? Some simple tests suggest to me that it isn't thread safe. The  Initialize_PLplot and associated procedures to set filenames, etc, seem to set global variables somewhere. Is there some trick I'm missing?

It does make lovely looking charts.

thanks very much for this.

Graham

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: ANN: PLplot plotting library with Ada bindings
  2013-11-12 15:27 ` Graham Stark
@ 2013-11-13 22:51   ` Jerry
  2013-11-15  5:16   ` Jerry
  1 sibling, 0 replies; 11+ messages in thread
From: Jerry @ 2013-11-13 22:51 UTC (permalink / raw)


On Tuesday, November 12, 2013 8:27:37 AM UTC-7, Graham Stark wrote:
> Hi Jerry,
> 
> That looks really interesting.
> 
> I'm looking for a plotter routine that could be used safely inside the AWS web server, so I can implement a 'callback' chart server (currently I have one written in Java). 
> 
> Could this be used for that? Some simple tests suggest to me that it isn't thread safe. The  Initialize_PLplot and associated procedures to set filenames, etc, seem to set global variables somewhere. Is there some trick I'm missing?
> 
> It does make lovely looking charts.
> 
> 
> 
> thanks very much for this.
> 
> Graham

Hi Graham,

Thanks for your interest in PLplot. I don't know how to answer your question about thread safety so I put it to the PLplot developmenet list. There are two responses so far, from Alan and Hezekiah.

Jerry


====
Alan
====

To answer the question at hand, I am virtually positive PLplot is not thread safe, but you should wait for Andrew's response for the definitive view on that, especially the question of what would need to be done to make PLplot thread safe and ideally a plan for getting there.

Just as important as thread safety in my option is security. If I were a webserver designer interested in safe plotting, then it is important to acknowledge that plotting software by its very nature is inherently insecure; the problem is that plotting software has lots of different user input channels (titles, text annotations, legends, colorbars, etc.,) that could be the source of potential buffer overflows or other intrusion possibilities. We do make some concious decisions for PLplot development to avoid obvious security issues, but at the same time security is not our primary interest and certainly not a fundamentally important area of expertise for us. And I am sure that is the case for developers of other plotting software as well; we are all primarily interested in making pretty pictures ("lovely looking charts") rather than designing secure software. :-)

So for any plot software including PLplot, the web designer should filter down the possible user input channels as much as possible (ideally no user-controlled input text allowed at all). After that, a full security audit (only possible with open-source plotting software such as PLplot) should be done of what is left to target by a malicious user after such filtering. And we would certainly be happy to accept patches that were the result of any such audit.


========
Hezekiah
========

PLplot is not thread safe. While you can use PLplot in a threaded program, only one thread per process may interact with PLplot at a given time. This limitation holds even if you are working with multiple plot streams in a single process.

Regarding Alan's follow-up - while it is possible to make PLplot thread-safe, the changes required are invasive and pervasive. They are all good changes to make! But there is a lot to be done and the result is a completely backwards-incompatible API. The three big pieces required are:

a) All PLplot functions will need to explicitly operate on a given plstream value representing the affected plot stream. This requires adding an additional stream argument to all PLplot functions and removing any global state from plot streams. 
b) Remove all of the globals used through the PLplot code base in the actual plotting logic. One example is the contour/shading routines which use several global variables to track their state. 
c) Confirm/ensure that each of our output devices can be and are used in a thread-safe manner.

Each of these big pieces is made up of several smaller chunks. (a) is where the API breakage would come in. It is also likely the simplest (simple being relative here!) to complete. (b) could be pretty hairy as the logic in the contouring routines in particular is tricky to translate to something which doesn't use globals. (c) should be attainable for at least the Cairo, Qt and built-in output drivers (SVG, PS, null). I would be happy to help in putting together a plan for this work. Unfortunately my PLplot time is very limited these days so it's unlikely I'll be able to provide much development assistance.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: ANN: PLplot plotting library with Ada bindings
  2013-11-12 15:27 ` Graham Stark
  2013-11-13 22:51   ` Jerry
@ 2013-11-15  5:16   ` Jerry
  2013-11-18 15:11     ` Graham Stark
  1 sibling, 1 reply; 11+ messages in thread
From: Jerry @ 2013-11-15  5:16 UTC (permalink / raw)


On Tuesday, November 12, 2013 8:27:37 AM UTC-7, Graham Stark wrote:
> Hi Jerry,
> 
> That looks really interesting.
> 
> I'm looking for a plotter routine that could be used safely inside the AWS web server, so I can implement a 'callback' chart server (currently I have one written in Java). 
> 
> Could this be used for that? Some simple tests suggest to me that it isn't thread safe. The  Initialize_PLplot and associated procedures to set filenames, etc, seem to set global variables somewhere. Is there some trick I'm missing?
> 
> It does make lovely looking charts.
> 
> thanks very much for this.
> 
> Graham

Hi Graham,

Here's another comment from a PLplot developer:

======
Andrew
======

I'd concur with what Hez said, however there is one further source of thread problems - namely a number of the language bindings use globals to work round passing things like function pointers between languages. This would also need checking.

This would be a useful, but substantive job.

In terms of security we try to follow best practice in terms of checking buffer lengths, avoiding insecure library calls etc to avoid the obvious problems. Newer versions of gcc / gnu ld are getting better at flagging some of these. There is certainly no systematic attempt to harden plplot or fully check it for potential security issues.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: ANN: PLplot plotting library with Ada bindings
  2013-11-15  5:16   ` Jerry
@ 2013-11-18 15:11     ` Graham Stark
  0 siblings, 0 replies; 11+ messages in thread
From: Graham Stark @ 2013-11-18 15:11 UTC (permalink / raw)


Jerry,
      thanks for that, that's very useful and thorough. It may be that 'synchronising' PlPlot so it only ever does one plot at a time might be all that's needed for my purposes since it's very fast. I think I can see how to do that.

Those are good points about security. A typical use-case is to convert all the inputs into numbers, which I imagine is safe enough (I hope so, since that's what we've been doing for years).

thanks again,

Graham


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-11-18 15:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-02  0:31 ANN: PLplot plotting library with Ada bindings Jerry
2013-10-02  0:45 ` Jeffrey Carter
2013-10-03  4:39   ` Anatoly Chernyshev
2013-10-03  5:27     ` Jeffrey Carter
2013-10-04 23:55   ` Jerry
2013-10-19  2:27     ` Randy Brukardt
2013-10-22  4:20       ` Jerry
2013-11-12 15:27 ` Graham Stark
2013-11-13 22:51   ` Jerry
2013-11-15  5:16   ` Jerry
2013-11-18 15:11     ` Graham Stark

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox