Make Python builtin types hashable by default
Default hash is the underlying C/C++ pointer. This matches up with testing for equivalence (Py_EQ in SwigPyObject_richcompare) which compares the pointers.
This commit is contained in:
parent
253a39fdff
commit
5b7c08c214
5 changed files with 53 additions and 16 deletions
|
|
@ -10,6 +10,17 @@ bool is_python_builtin() { return false; }
|
|||
#endif
|
||||
%}
|
||||
|
||||
// Test 0 for default tp_hash
|
||||
%inline %{
|
||||
struct ValueStruct {
|
||||
int value;
|
||||
ValueStruct(int value) : value(value) {}
|
||||
static ValueStruct *inout(ValueStruct *v) {
|
||||
return v;
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
// Test 1 for tp_hash
|
||||
#if defined(SWIGPYTHON_BUILTIN)
|
||||
%feature("python:tp_hash") SimpleValue "SimpleValueHashFunction"
|
||||
|
|
@ -19,9 +30,6 @@ bool is_python_builtin() { return false; }
|
|||
struct SimpleValue {
|
||||
int value;
|
||||
SimpleValue(int value) : value(value) {}
|
||||
static SimpleValue *inout(SimpleValue *sv) {
|
||||
return sv;
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue