[vtk-developers] Python wrapping & factory methods
Michael Halle
mhalle at bwh.harvard.edu
Tue Apr 26 16:26:18 EDT 2011
A longer-term alternative could be a wrapper generation decorator for factory methods that could live in the .h file.
--Mike
On Apr 26, 2011, at 4:23 PM, David Gobbi wrote:
> Hi David,
>
> That's great, I can use the same list and centralize it so that it is
> shared between the Python, Tcl, and Java wrappers.
>
> This issue represents a significant oversight in the wrapper design.
> Thanks for bringing this up, Tim.
>
> - David
>
>
> On Tue, Apr 26, 2011 at 2:15 PM, David Cole <david.cole at kitware.com> wrote:
>> I use the following regular expression in the ActiViz .NET C# wrappers to
>> determine what methods of VTK are "factory methods."
>>
>> "^(CreateImageReader2|CreateInstance|MakeTransform|New|NewInstance)$"
>>
>> (seen in action in this file:
>> http://public.kitware.com/gitweb?p=activizdotnet.git;a=blob;f=MummySettings.xml.in;h=786b24431b7fc75749c1ebb16840757857cfff13;hb=HEAD
>> )
>>
>> Perhaps I need to extend it to include CreateArray as well?
>>
>> Does anybody know of any others?
>>
>>
>> HTH,
>> David
>>
>>
>> On Tue, Apr 26, 2011 at 4:08 PM, David Gobbi <david.gobbi at gmail.com> wrote:
>>>
>>> Hi Tim,
>>>
>>> All NewInstance() methods are wrapped the same way. There isn't any
>>> hinting mechanism to tell the wrappers that a new instance is being
>>> created. In fact the only way even a human programmer can tell is by
>>> reading the documentation.
>>>
>>> Since instance-creation methods are rare in VTK, I would be
>>> comfortable hard-coding the few that exist into the wrappers. For
>>> instance, any method called NewInstance that returns an object can be
>>> assumed to return a new instance (because honestly, why else would a
>>> method have such a name?).
>>>
>>> As a temporary and very dirty fix, you can use SetReferenceCount() to
>>> avoid the memory leaks.
>>>
>>> - David
>>>
>>> On Tue, Apr 26, 2011 at 1:39 PM, Timothy Shead <tshead at sandia.gov> wrote:
>>>>
>>>> I'm troubleshooting a reference-counting issue in the Python bindings
>>>> for VTK - in a nutshell, the only way to instantiate vtkArray-derived
>>>> classes from Python is through the vtkArray::CreateArray() static factory
>>>> method (because vtkArray derivates are template classes).
>>>>
>>>> However, using vtkArray::CreateArray() from Python returns objects that
>>>> have a reference-count of 2, because the Python wrapping code increments the
>>>> reference-count of objects returned from "normal" class methods. This leads
>>>> to annoying leaks when the program ends.
>>>>
>>>> From what I can see, there's a separate code path when instantiating VTK
>>>> objects from Python. I'm thinking that there must be other examples of
>>>> factory methods in VTK, and that there must be some clean way of using them
>>>> from Python?
>>>>
>>>> Thanks in advance,
>>>> Tim
>>>>
>>>>
>>>> --
>>>> Timothy M. Shead
>>>> Sandia National Laboratories
>>>> 1461, Scalable Analysis and Visualization
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.vtk.org/mailman/listinfo/vtk-developers
>>>
>>
>>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
More information about the vtk-developers
mailing list