Fixing setting this in Python when using __slots__

Don't attempt to use the class's __dict__ for setting 'this' when
a user has extended a class with:
    __slots__ = ['this'].
Was segfaulting. Now we fall back to a simple PyObject_SetAttr if the
usual approach to setting 'this' in __dict__ does not work.

Closes #1673 Closes #1674
This commit is contained in:
William S Fulton 2020-02-06 06:45:11 +00:00
commit a01e8474f6
4 changed files with 46 additions and 15 deletions

View file

@ -42,13 +42,31 @@ import os.path
%}
%inline %{
class Test {
public:
static void static_func() {};
void funk() {};
};
%}
// Github issue #1674
%extend ForSlots {
%pythoncode %{
__slots__ = ["this"]
%}
}
// While __slots__ does not contain 'ValidVariable' in the list, it is still possible
// to set 'ValidVariable'. A little odd, but the whole attribute setting is bypassed
// for setting C/C++ member variables.
// Not sure how to test the equivalent for -builtin.
%inline %{
struct ForSlots {
int ValidVariable;
ForSlots() : ValidVariable(99) {}
};
%}
%inline %{
#ifdef SWIGPYTHON_BUILTIN
bool is_python_builtin() { return true; }
#else