<div dir="ltr">For a while, we kicked around the idea of having the hints in the comments. This would be less intrusive than adding C++11 attributes the declarations (i.e. what I've been doing so far).<div><br></div><div>The C++11 attributes are definitely the cleanest way for the wrappers to store the hints, since the hints become part of the parse tree, so I want to keep them as the primary hinting mechanism. Comment-based hints could be added as a secondary mechanism, i.e. after a declaration has been parsed we can check the docstring for extra hints, and then add the hints to the parse tree before the wrapper code is generated.</div><div><br></div><div>I'll have to search through the archives to remember what kind of syntax we were considering for comment-based hints.</div><div><br></div><div> - David</div><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 4, 2017 at 1:30 PM, Berk Geveci <span dir="ltr"><<a href="mailto:berk.geveci@kitware.com" target="_blank">berk.geveci@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">As much as I support the concept of range checking in the wrappers, this hint will make things look very ugly and non-standard at a time where we are trying to move towards more standard looking C++. Isn't there a way of doing this without mangling the signatures?</div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Fri, Aug 4, 2017 at 1:06 PM, David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Hi Andras,<div><br></div><div>Yes, this would be possible. It could be hard-coded into the wrappers, or even better, in the header file a generic hint could be added to the index parameter so that the index would be checked against the size of the array:</div><div><br></div><div> float GetValue(vtkIdType idx VTK_RANGECHECK(0,GetNumberOfVa<wbr>lues()));</div><div><br></div><div>I have a list of wrapper hints at <a href="http://www.vtk.org/Wiki/VTK/Wrapping_hints" target="_blank">http://www.vtk.org/Wiki/VTK<wbr>/Wrapping_hints</a>, and I can add this "RANGECHECK" hint to the "Proposed hints" section.</div><div><br></div><div>I'm hoping to find time to implement more of these wrapper hints over the next few weeks.</div><span class="m_3165174230481266102HOEnZb"><font color="#888888"><div><br></div><div> - David</div></font></span><div><div class="m_3165174230481266102h5"><div class="gmail_extra"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 4, 2017 at 9:53 AM, Andras Lasso <span dir="ltr"><<a href="mailto:lasso@queensu.ca" target="_blank">lasso@queensu.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div lang="EN-US">
<div class="m_3165174230481266102m_-3333330406614378145gmail-m_-8129673848077794794WordSection1">
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Hi David,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Users who mostly use VTK via Python wrapping are sometimes surprised how easily they can crash the application by accessing out-of-bounds elements in arrays.
For example, this crashes an application:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:Courier;color:black">>>>
</span><span style="font-size:8.5pt;font-family:Courier;color:rgb(0,0,150)">a=vtk.vtkStringArray()</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:Courier;color:black">>>>
</span><span style="font-size:8.5pt;font-family:Courier;color:rgb(0,0,150)">print(a.GetValue(0))<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:Courier;color:rgb(0,0,150)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">I first thought that it should be handled by documentation and training, but it would be nicer if the wrappers could handle this.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Would it be feasible to add bounds check to VTK array accessors in Python wrappers, so that in case of an out of bounds access, a Python exception would be raised
instead of crashing the application?<span class="m_3165174230481266102m_-3333330406614378145gmail-HOEnZb"><font color="#888888"><u></u><u></u></font></span></span></p><span class="m_3165174230481266102m_-3333330406614378145gmail-HOEnZb"><font color="#888888">
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u><u></u></span></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Andras</span></p>
</div>
</div>
</div>
</div>
</font></span></div>
</div>
</blockquote></div></div></div></div></div></div></div></blockquote></div></div></blockquote></div><br></div></div></div>