aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.lima@openbossa.org>2010-04-06 17:02:13 -0300
committerHugo Parente Lima <hugo.lima@openbossa.org>2010-04-06 19:11:16 -0300
commitfa9a91b59e4dee7e289c9711b86525016491e414 (patch)
tree4a2b814703cd483278f2f992982ddcf8699ab867
parentfc08b8878113645692f65d84e488de8288fa09b7 (diff)
QStrign uses the same hash function of str/unicode objects.
-rw-r--r--PySide/QtCore/glue/qstring_hashfunc.cpp6
-rw-r--r--PySide/QtCore/typesystem_core.xml4
-rw-r--r--tests/qtcore/qstring_test.py5
3 files changed, 14 insertions, 1 deletions
diff --git a/PySide/QtCore/glue/qstring_hashfunc.cpp b/PySide/QtCore/glue/qstring_hashfunc.cpp
new file mode 100644
index 000000000..b2fb6a1c9
--- /dev/null
+++ b/PySide/QtCore/glue/qstring_hashfunc.cpp
@@ -0,0 +1,6 @@
+static long QStringCustomHashFunction(const QString& str)
+{
+ QByteArray data = str.toUtf8();
+ Shiboken::AutoDecRef unicodeObj(PyUnicode_DecodeUTF8(data.constData(), data.length(), 0));
+ return unicodeObj->ob_type->tp_hash(unicodeObj);
+}
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml
index f928feb72..1f9b9ac91 100644
--- a/PySide/QtCore/typesystem_core.xml
+++ b/PySide/QtCore/typesystem_core.xml
@@ -976,13 +976,15 @@
</modify-function>
</object-type>
- <value-type name="QString" hash-function="qHash">
+ <value-type name="QString" hash-function="QStringCustomHashFunction">
<extra-includes>
<include file-name="QTextCodec" location="global"/>
</extra-includes>
<conversion-rule file="qstring_conversions.h" />
<modify-documentation xpath="/description/section[@id='initializing-a-string']/para[2]" />
<modify-documentation xpath="/description/section[@id='initializing-a-string']/para[3]" />
+ <!-- Custom hash function -->
+ <inject-code class="native" position="beginning" file="glue/qstring_hashfunc.cpp" />
<!-- buffer protocol -->
<inject-code class="native" position="beginning" file="glue/qstring_bufferprotocol.cpp" />
<inject-code class="target" position="end">
diff --git a/tests/qtcore/qstring_test.py b/tests/qtcore/qstring_test.py
index 9bb68a3ed..3f0fb4931 100644
--- a/tests/qtcore/qstring_test.py
+++ b/tests/qtcore/qstring_test.py
@@ -183,5 +183,10 @@ class QStringImplicitConvertion(unittest.TestCase):
obj.setObjectName(QByteArray('foobar'))
self.assertEqual(obj.objectName(), QString('foobar'))
+class QStringHash(unittest.TestCase):
+ def testHash(self):
+ self.assertEqual(hash("key"), hash(QString("key")))
+ self.assertEqual(hash(u"aéióu"), hash(QString(u"aéióu")))
+
if __name__ == '__main__':
unittest.main()