Commits

Ronald Oussoren  committed f1349a8

Quick fix for problem with unicode objects. Before this patch the following
expression was False:

hash(u"") == hash(NSString.stringWithString_(''))

even though:
u"" == NSString.stringWithString_('')

There is no unittest for our unicode objects, I noticed this while checking
the failure for the unittest for PyObjCTools.Conversion.

  • Participants
  • Parent commits 5ba20e6

Comments (0)

Files changed (1)

File pyobjc/Modules/objc/unicode-object.m

 		PyUnicode_GET_DATA_SIZE(tmp));
 
 	self->base.hash = -1;
+	if (PyUnicode_GET_SIZE(tmp) == 0) {
+		self->base.hash = 0;
+	}
 	Py_XDECREF(self->base.defenc);
 	self->base.defenc = tmp->defenc;
 	Py_XINCREF(tmp->defenc);
 	PyUnicode_GET_SIZE(result) = PyUnicode_GET_SIZE(tmp);
 	memcpy((char*)PyUnicode_AS_DATA(result), PyUnicode_AS_DATA(tmp),
 		PyUnicode_GET_DATA_SIZE(tmp));
+
 	result->base.hash = -1;
+
+	if (PyUnicode_GET_SIZE(tmp) == 0) {
+		result->base.hash = 0;
+	}
+
 	result->base.defenc = tmp->defenc;
 	Py_XINCREF(tmp->defenc);
 	Py_DECREF(tmp);