On Jan 9, 2009, at 12:51 AM, Andrew Ross wrote:

>
> Jerry,
>
> While adapting example 12 to use plcol1 and plscmap1l I came across  
> one
> interesting issue with ada.
>
> Several example use something like
>
>     A_Boolean : Boolean_Array_1D(1 .. 1);
>
>     A_Boolean(1) := False;
>
>     plscmap1l(HLS, i, h, l, s, A_Boolean);
>
> Note that in these cases the h, l, s arrays are only of length 2. This
> works for these examples, but when I try for example 12 with colour
> arrays of length 5 then it doesn't work. I assume this is trying to
> emulate the C usage of NULL for the array pointer to signal no colours
> are reversed. Explicitly defining an array of length 5 and willing  
> with
> False values works as expected.

Andrew,

Thanks for catching this.

I'm not sure what happened to lead to my converting several examples  
to use A_Boolean : Boolean_Array_1D(1 .. 1) in this way, but it now  
seems wrong to me. I currently do not check that the five arrays  
passed to plscmap1l are actually the same length and so passing a  
length-one array to the reverse flag slot when the others are more  
than length 1 probably caused the C code to execute a out-of-bounds  
array access. It was only a matter of luck that this didn't cause  
problems on the other examples. When you tried this with Example 12,  
some of these out-of-bounds accesses probably resulted in non-zero  
numbers, interpreted by C as True, and caused several of the colors  
to be wrong. That's my best guess as to what happened.

I looked into what would be required to emulate the C behavior and  
found that to implement the C expectation exactly in Ada would  
require asking the user to pass a pointer to the reversing array in  
stead of the array itself. This would be very high level of weirdness  
to ask of the user. Alternately, it might be possible to hack up  
something whereby if the user passed a null array (an array of zero  
length) then call a different version of the thin-binding routine. I  
looked into this and it looked like at best a _lot_ of trouble. And  
all this to emulate a frankly dubious C trick.

So I changed all of the examples to use a proper-length reverse flag  
array and added a note to the documentation that this is a variance  
with the C documentation. One could argue I suppose if this is a  
variance with the actual C API.

Jerry

>
> With f77 I found some errors in the examples where a value of 0 was
> passed for this purpose. Because f77 passes all arguments by reference
> this actually got interpreted as an array of length 5 with the first
> value 0. Obviously the subsequent values were undefined. I wonder if
> something similar is happening in Ada? Perhaps you could explain?  
> Use of
> valgrind shows use of uninitialised values in the case which doesn't
> work, but only when the array length is > 2. This suggests my  
> diagnosis
> might be correct. Can you think of a way of fixing this so a NULL  
> value
> equivalent works, or if not, then correct the examples?

It sounds like your analysis is right, as I expound on above.
>
> Thanks
>
> Andrew
>



------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel

Reply via email to