<div dir="ltr"><div>The vtkSmartPointer isn't very safe in this regard. It is easy to accidentally do the following, since VTK smart pointers implicitly convert to raw pointers:<br></div><div><br></div><div>  vtkSmartPointer<vtkObject> MyMethod();</div><div>  vtkObject *obj = MyMethod(); // ownership is not caught, object is autodeleted</div><div><br></div><div>The preferred way of dealing with transfer of ownership for returned values in VTK is to add the VTK_NEWINSTANCE hint to the return value.  Then the wrappers will automatically handle the reference count.  As for people who use these methods from C++, they still have to worry about memory leaks, but at least they don't have to worry about memory corruption caused by mistakes like the one in the example above.</div><div><br></div><div> - David</div><div><br></div><div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 17, 2018 at 4:29 PM, 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12.0pt;line-height:1.3;color:#1f497d">
<div>The main advantage of the ability to return smart pointers would be that ownership of VTK objects could be transferred safely to the caller, without requiring calling UnRegister(None). C++ developers are aware of pointers but for Python users it is a mistery
 why sometimes they need to call UnRegister to avoid memory leaks. <br>
</div>
<div><br>
</div>
<div id="m_5083259659620692987signature-x" class="m_5083259659620692987signature_editor" style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12.0pt;color:#1f497d">
Andras<br>
</div>
</div>
<div id="m_5083259659620692987quoted_header" style="clear:both">
<hr style="border:none;height:1px;color:#e1e1e1;background-color:#e1e1e1">
<div style="border:none;padding:3.0pt 0cm 0cm 0cm"><span style="font-size:11.0pt;font-family:'Calibri','sans-serif'"><b>From:</b> David Gobbi <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>><br>
<b>Sent:</b> Thursday, May 17, 2018 4:55 PM<span class=""><br>
<b>To:</b> Kyle Sunderland<br>
<b>Cc:</b> <a href="mailto:vtkusers@vtk.org" target="_blank">vtkusers@vtk.org</a><br>
<b>Subject:</b> Re: [vtkusers] Questions About Python Wrapping<br>
</span></span></div>
</div><div><div class="h5">
<br type="attribution">
<div>
<div dir="ltr">Hi Kyle,
<div><br>
</div>
<div>Thanks for sending the files.  I see that the parameters for those methods are actually smart pointers, and as you have already noted, smart pointers aren't wrapped.</div>
<div><br>
</div>
<div>This has never been an issue in VTK proper or for most VTK projects, since VTK methods generally use raw pointers.  The header file you sent is closer to ITK style than to VTK style.</div>
<div><br>
</div>
<div>I definitely think that it would be worthwhile to add better smart pointer handling to the wrappers.</div>
<div><br>
</div>
<div> - David</div>
<div><br>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Thu, May 17, 2018 at 12:13 PM, David Gobbi <span dir="ltr">
<<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.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"><span>On Thu, May 17, 2018 at 10:10 AM, Kyle Sunderland <<a href="mailto:1krs1@queensu.ca" target="_blank">1krs1@queensu.ca</a>> wrote:<br>
> It (mostly) works, however I noticed that no functions are wrapped which have a definition that contains any of the wrapped classes. Does anyone have insight into what I might have missed?<br>
<br>
</span>Is a vtk..Hierarchy.txt file generated for the wrapped module when you build it?  If so, send it to me along with the header files you're wrapping, and I can take a look.<span><br>
<br>
> Also, as an additional question, is it still not possible to wrap functions that return a smart pointer?<br>
<br>
</span>
<div>If this is a feature that you need, then add it to the bug tracker.</div>
<div><br>
</div>
<div>Cheers,</div>
<div> - David</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div></div></div>

</blockquote></div><br></div></div></div>