Added checks to prevent PyUnicode_Count() from dumping core
in case the parameters are out of bounds and fixes error handling
for .count(), .startswith() and .endswith() for the case of
mixed string/Unicode objects.

This patch adds Python style index semantics to PyUnicode_Count()
indices (including the special handling of negative indices).

The patch is an extended version of patch #103249 submitted
by Michael Hudson (mwh) on SF. It also includes new test cases.
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 579bab1..c71f927 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -32,6 +32,13 @@
 test('capitalize', u' hello ', u' hello ')
 test('capitalize', u'hello ', u'Hello ')
 
+test('count', u'aaa', 3, u'a')
+test('count', u'aaa', 0, u'b')
+test('count', 'aaa', 3, u'a')
+test('count', 'aaa', 0, u'b')
+test('count', u'aaa', 3, 'a')
+test('count', u'aaa', 0, 'b')
+
 test('title', u' hello ', u' Hello ')
 test('title', u'hello ', u'Hello ')
 test('title', u"fOrMaT thIs aS titLe String", u'Format This As Title String')