<div dir="ltr"><div class="markdown-here-wrapper" style="line-height:150%;font-size:12pt;font-family:Constantia,'Hoefler Text','Bitstream Charter',Palatino,'Palatino Linotype','Lucida Bright',Lucidabright,'Lucida Serif',Lucida,'DejaVu Serif','Bitstream Vera Serif','Liberation Serif',Georgia,serif;max-width:120ex"><p style="line-height:150%;font-size:12pt;font-family:Constantia,'Hoefler Text','Bitstream Charter',Palatino,'Palatino Linotype','Lucida Bright',Lucidabright,'Lucida Serif',Lucida,'DejaVu Serif','Bitstream Vera Serif','Liberation Serif',Georgia,serif;max-width:90ex;margin-bottom:12pt!important">David,</p>
<p style="line-height:150%;font-size:12pt;font-family:Constantia,'Hoefler Text','Bitstream Charter',Palatino,'Palatino Linotype','Lucida Bright',Lucidabright,'Lucida Serif',Lucida,'DejaVu Serif','Bitstream Vera Serif','Liberation Serif',Georgia,serif;max-width:90ex;margin-bottom:12pt!important"> Perhaps you could help me with my first problem: I’m trying to patch <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;max-width:none!important;background-color:rgb(248,248,248)">vtkWrapPython</code> in order to fully support unicode arguments. Currently, <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;max-width:none!important;background-color:rgb(248,248,248)">unicode</code> python objects passed to VTK must be ascii-encodable (because of <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;max-width:none!important;background-color:rgb(248,248,248)">_PyUnicode_AsDefaultEncodedString(o, NULL)</code> being used in <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;max-width:none!important;background-color:rgb(248,248,248)">vtkPythonGetStringValue</code> 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 <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;max-width:none!important;background-color:rgb(248,248,248)">PyObject *s = PyUnicode_AsUTF8String(o);</code>, which will return a new reference to a temporary <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;max-width:none!important;background-color:rgb(248,248,248)">PyStringObject</code>, and then using <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;max-width:none!important;background-color:rgb(248,248,248)">PyString_AS_STRING</code> on this object, which will return a <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;max-width:none!important;background-color:rgb(248,248,248)">char *</code> pointing to an internal buffer in <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;max-width:none!important;background-color:rgb(248,248,248)">s</code>.</p>
<p style="line-height:150%;font-size:12pt;font-family:Constantia,'Hoefler Text','Bitstream Charter',Palatino,'Palatino Linotype','Lucida Bright',Lucidabright,'Lucida Serif',Lucida,'DejaVu Serif','Bitstream Vera Serif','Liberation Serif',Georgia,serif;max-width:90ex;margin-bottom:12pt!important"> The problem is that this temporary <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;max-width:none!important;background-color:rgb(248,248,248)">PyStringObject</code> (<code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;max-width:none!important;background-color:rgb(248,248,248)">s</code>) must be deleted by calling <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;max-width:none!important;background-color:rgb(248,248,248)">Py_XDECREF</code> only after the call to the wrapped function. I thought about adding an <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;max-width:none!important;background-color:rgb(248,248,248)">std::vector<PyObject*></code> with these temporary python strings to the <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;max-width:none!important;background-color:rgb(248,248,248)">vtkPythonArgs</code> class; each new temporary would be pushed to this vector, and, in the <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;max-width:none!important;background-color:rgb(248,248,248)">vtkPythonArgs</code> 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 <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;max-width:none!important;background-color:rgb(248,248,248)">vtkPythonArgs</code> (such as the ones implementing the sequence protocol), and an instance would be always required in this case.</p>
<p style="line-height:150%;font-size:12pt;font-family:Constantia,'Hoefler Text','Bitstream Charter',Palatino,'Palatino Linotype','Lucida Bright',Lucidabright,'Lucida Serif',Lucida,'DejaVu Serif','Bitstream Vera Serif','Liberation Serif',Georgia,serif;max-width:90ex;margin-bottom:12pt!important"> Do you have a suggestion?</p>
<p style="line-height:150%;font-size:12pt;font-family:Constantia,'Hoefler Text','Bitstream Charter',Palatino,'Palatino Linotype','Lucida Bright',Lucidabright,'Lucida Serif',Lucida,'DejaVu Serif','Bitstream Vera Serif','Liberation Serif',Georgia,serif;max-width:90ex;margin-bottom:12pt!important"> Thanks! Best regards,</p>
<p style="line-height:150%;font-size:12pt;font-family:Constantia,'Hoefler Text','Bitstream Charter',Palatino,'Palatino Linotype','Lucida Bright',Lucidabright,'Lucida Serif',Lucida,'DejaVu Serif','Bitstream Vera Serif','Liberation Serif',Georgia,serif;max-width:90ex;margin-bottom:12pt!important">Edson</p>
<div title="MDH:RGF2aWQsPGRpdj48YnI+PC9kaXY+PGRpdj4mbmJzcDsgUGVyaGFwcyB5b3UgY291bGQgaGVscCBt
ZSB3aXRoIG15IGZpcnN0IHByb2JsZW06IEknbSB0cnlpbmcgdG8gcGF0Y2ggYHZ0a1dyYXBQeXRo
b25gIGluIG9yZGVyIHRvIGZ1bGx5IHN1cHBvcnQgdW5pY29kZSBhcmd1bWVudHMuIEN1cnJlbnRs
eSwgYHVuaWNvZGVgIHB5dGhvbiBvYmplY3RzIHBhc3NlZCB0byBWVEsgbXVzdCBiZSBhc2NpaS1l
bmNvZGFibGUgKGJlY2F1c2Ugb2YgYF9QeVVuaWNvZGVfQXNEZWZhdWx0RW5jb2RlZFN0cmluZyhv
LCBOVUxMKTtgIGJlaW5nIHVzZWQgaW4gYHZ0a1B5dGhvbkdldFN0cmluZ1ZhbHVlYCBpbiB2dGtQ
eXRob25BcmdzLmN4eCkuIEknbSB0cnlpbmcgdG8gY2hhbmdlIGl0IHNvIHRoYXQgaXQgd2lsbCBz
dXBwb3J0IGFueSB1bm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lvbikuICZuYnNwO1RoZSBv
bmx5IHByb2JsZW0gbm93IGlzIHRoYXQgbm90IGFsbCBmdW5jdGlvbnMgdXNlIGFuIGluc3RhbmNl
IG9mIGB2dGtQeXRob25BcmdzYCAoc3VjaCBhcyB0aGUgb25lcyBpbXBsZW1lbnRpbmcgdGhlIHNl
cXVlbmNlIHByb3RvY29sKS48L2Rpdj48ZGl2Pjxicj48L2Rpdj48ZGl2PiZuYnNwOyBEbyB5b3Ug
aGF2ZSBhIHN1Z2dlc3Rpb24/PC9kaXY+PGRpdj48YnI+PC9kaXY+PGRpdj4mbmJzcDsgVGhhbmtz
ISBCZXN0IHJlZ2FyZHMsPC9kaXY+PGRpdj48YnI+PC9kaXY+PGRpdj5FZHNvbjwvZGl2PjxkaXY+
Jm5ic3A7Jm5ic3A7PC9kaXY+" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0"></div></div><div></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 31, 2015 at 11:39 AM, 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"><div class="gmail_extra"><div class="gmail_quote"><span class="">On Tue, Mar 31, 2015 at 7:51 AM, E. Tadeu <span dir="ltr"><<a href="mailto:e.tadeu@gmail.com" target="_blank">e.tadeu@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">Hi!<div><br></div><div> Why is there a static version for many methods in vtkPythonArgs (specially GetValue)?</div></div></blockquote><div><br></div></span><div>It allows those methods to be called without a vtkPythonArgs object ;)</div><span class=""><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div> 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?</div></div></blockquote><div><br></div></span><div>They're also called by the other methods that make up the python sequence protocol, i.e. SequenceSetItem and Sequence(Get)Item.</div><div><br></div><div>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.</div><div><br></div><div>If the python wrappers handled more python protocols, the static GetValue() methods would be more widely used.</div><div><br></div><div>Cheers,</div><div><br></div><div> - David</div><div> </div></div><br></div></div>
</blockquote></div><br></div></div>