Fix Python 2 builtin tp_hash hashfunc closure regression when using "python:slot"

Closes https://github.com/swig/swig/issues/843
This commit is contained in:
William S Fulton 2016-12-23 23:41:07 +00:00
commit 4963a7f88f
4 changed files with 35 additions and 3 deletions

View file

@ -27,7 +27,7 @@ struct ValueStruct {
};
%}
// Test 1 for tp_hash
// Test 1a for tp_hash
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:tp_hash") SimpleValue "SimpleValueHashFunction"
#endif
@ -55,6 +55,24 @@ hashfunc test_hashfunc_cast() {
}
%}
// Test 1b for tp_hash
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "tp_hash", functype="hashfunc") SimpleValue2::HashFunc;
#endif
%inline %{
struct SimpleValue2 {
int value;
SimpleValue2(int value) : value(value) {}
#if PY_VERSION_HEX >= 0x03020000
typedef Py_hash_t HashType;
#else
typedef long HashType;
#endif
HashType HashFunc() { return (HashType)value; }
};
%}
// Test 2 for tp_hash
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "tp_hash", functype="hashfunc") BadHashFunctionReturnType::bad_hash_function;