Commit 66c211a7 authored by David Gobbi's avatar David Gobbi
Browse files

BUG 16054: Reduce chance of mistaken swig pointer string.

In the Python wrappers, the vtkDataArray::SetVoidArray() method can take
two kinds of arguments:

1) a string formatted as a swig pointer "_addr_type" where "addr" is
the hexadecimal address and "type" is the type, e.g. "p_void".

2) a Python buffer object (any Python object with buffer protocol)

A Python string (in Python 2) is also a buffer object, therefore there
is some ambiguity.  The use of swig pointers with VTK is exceedingly
rare, so this fix requires that the string exactly matches the format
"_addr_p_void" to be interpreted as a swig pointer.

Note that in Python 3, the ambiguity disappears because a string in Py3K
does not have the buffer protocol.
parent 5efcd8d2
...@@ -227,24 +227,20 @@ static bool vtkPythonGetValue( ...@@ -227,24 +227,20 @@ static bool vtkPythonGetValue(
reinterpret_cast<char *>(p), &s, "p_void"); reinterpret_cast<char *>(p), &s, "p_void");
#ifdef VTK_PY3K #ifdef VTK_PY3K
Py_DECREF(bytes); Py_DECREF(bytes);
#endif if (s != 0)
if (s >= 0)
return true;
if (s == -1)
{ {
char buf[128]; PyErr_SetString(PyExc_TypeError, "requires a _addr_p_void string");
sprintf(buf, "value is %.80s, required type is p_void",
reinterpret_cast<char *>(p));
PyErr_SetString(PyExc_TypeError, buf);
return false; return false;
} }
else #else
if (s == -1)
{ {
PyErr_SetString(PyExc_TypeError, "cannot get a void pointer"); // matched _addr_ but not p_void, assume it isn't a swig ptr string:
return false; // use the buffer's pointer as the argument
a = p;
} }
return true;
} }
else if (p && sz >= 0) else if (p && sz >= 0)
{ {
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment