[vtk-developers] Static methods in vtkPythonArgs
david.gobbi at gmail.com
Tue Mar 31 14:27:16 EDT 2015
What's going on with the font in your email?? Maybe it's just my browser,
but it's HUGE!
On Tue, Mar 31, 2015 at 12:22 PM, E. Tadeu <e.tadeu at gmail.com> wrote:
> Perhaps you could help me with my first problem: I'm trying to patch
> vtkWrapPython in order to fully support unicode arguments. Currently,
> unicode python objects passed to VTK must be ascii-encodable (because of _PyUnicode_AsDefaultEncodedString(o,
> NULL) being used in vtkPythonGetStringValue in vtkPythonArgs.cxx). I'm
> trying to change it so that it will support any unicode string, encoding
> them in UTF-8. This must be done in two steps: first, using a PyObject *s
> = PyUnicode_AsUTF8String(o);, which will return a new reference to a
> temporary PyStringObject, and then using PyString_AS_STRING on this
> object, which will return a char * pointing to an internal buffer in s.
> The problem is that this temporary PyStringObject (s) must be deleted
> by calling Py_XDECREF only after the call to the wrapped function. I
> thought about adding an std::vector<PyObject*> with these temporary
> python strings to the vtkPythonArgs class; each new temporary would be
> pushed to this vector, and, in the vtkPythonArgs destructor, they would
> all be released (at the very end of the wrapping function). The only
> problem now is that not all functions use an instance of vtkPythonArgs
> (such as the ones implementing the sequence protocol), and an instance
> would be always required in this case.
> Do you have a suggestion?
> Thanks! Best regards,
> On Tue, Mar 31, 2015 at 11:39 AM, David Gobbi <david.gobbi at gmail.com>
>> On Tue, Mar 31, 2015 at 7:51 AM, E. Tadeu <e.tadeu at gmail.com> wrote:
>>> Why is there a static version for many methods in vtkPythonArgs
>>> (specially GetValue)?
>> It allows those methods to be called without a vtkPythonArgs object ;)
>> I see that they are being used only by Py*_SequenceSize. Is there a
>>> special reason? Could the static versions be removed, and Py*_SequenceSize
>>> generated code use an instance of vtkPythonArgs, just like all other
>>> generated functions?
>> They're also called by the other methods that make up the python sequence
>> protocol, i.e. SequenceSetItem and Sequence(Get)Item.
>> As for why these protocol methods call the static version of GetValue(),
>> it's because they have no need to create a vtkPythonArgs object. The main
>> purpose of the vtkPythonArgs object is to check the argument list, i.e. to
>> verify that the correct number of arguments has been passed, to keep track
>> of the current position in the argument list, etc. None of that is
>> necessary for python protocol methods like SequenceSize. All they need is
>> a simple way to convert a python object to a C++ object or vice-versa. The
>> static methods serve that purpose.
>> If the python wrappers handled more python protocols, the static
>> GetValue() methods would be more widely used.
>> - David
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the vtk-developers