On Jan 13, 2009, at 1:37 PM, Andrew Ross wrote:

> On Tue, Jan 13, 2009 at 12:51:03PM -0700, Jerry wrote:
>>
>> 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,
>
> I think that is fine. Some other bindings do the same thing. The NULL
> pointer trick in C is really a convenience to the user. Doesn't always
> make sense. One other trick that some languages use it to treat the
> pointer as NULL if the argument is missing. This depends on whether  
> the
> language allows default values for arguments (e.g. C++). If neither of
> these is relevant in Ada, then don't worry.
>
> Andrew
>
Fixed with overloaded procs in rev. 9300.
Jerry


------------------------------------------------------------------------------
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