Fix unicode handling for octet arrays, and finally fix the test suite

for Python 2.2.

Not part of the build.
This commit is contained in:
markh%activestate.com 2001-08-22 05:33:05 +00:00
Родитель bcab0f9dbc
Коммит 4b98ee80cf
2 изменённых файлов: 24 добавлений и 3 удалений

Просмотреть файл

@ -206,11 +206,23 @@ PRBool FillSingleArray(void *array_ptr, PyObject *sequence_ob, PRUint32 sequence
PRUint8 *pthis = (PRUint8 *)array_ptr;
NS_ABORT_IF_FALSE(pthis, "Don't have a valid array to fill!");
PRBool rc = PR_TRUE;
// We handle T_U8 specially as a string.
// We handle T_U8 specially as a string/Unicode.
// If it is NOT a string, we just fall through and allow the standard
// sequence unpack code process it (just slower!)
if ( (array_type & XPT_TDP_TAGMASK) == nsXPTType::T_U8 && PyString_Check(sequence_ob)) {
if ( (array_type & XPT_TDP_TAGMASK) == nsXPTType::T_U8 &&
(PyString_Check(sequence_ob) || PyUnicode_Check(sequence_ob))) {
PRBool release_seq;
if (PyUnicode_Check(sequence_ob)) {
release_seq = PR_TRUE;
sequence_ob = PyObject_Str(sequence_ob);
} else
release_seq = PR_FALSE;
if (!sequence_ob) // presumably a memory error, or Unicode encoding error.
return PR_FALSE;
nsCRT::memcpy(pthis, PyString_AS_STRING(sequence_ob), sequence_size);
if (release_seq)
Py_DECREF(sequence_ob);
return PR_TRUE;
}

Просмотреть файл

@ -30,6 +30,13 @@ contractid = "Python.TestComponent"
really_big_string = "This is really repetitive!" * 10000
really_big_wstring = u"This is really repetitive!" * 10000
# Exception raised when a -ve integer is converted to an unsigned C integer
# (via an extension module). This changed in Python 2.2
if sys.hexversion > 0x02010000:
UnsignedMismatchException = TypeError
else:
UnsignedMismatchException = OverflowError
def print_error(error):
print error
global num_errors
@ -149,7 +156,7 @@ def test_base_interface(c):
test_attribute(c, "ulong_long_value", 8, 9)
test_attribute(c, "ulong_long_value", 8, 0)
test_attribute_failure(c, "ulong_long_value", "boo", ValueError)
test_attribute_failure(c, "ulong_long_value", -1, OverflowError) # can't convert negative value to unsigned long)
test_attribute_failure(c, "ulong_long_value", -1, UnsignedMismatchException) # can't convert negative value to unsigned long)
test_attribute(c, "float_value", 9.0, 10.2)
test_attribute(c, "float_value", 9.0, 0)
@ -308,6 +315,8 @@ def test_derived_interface(c, test_flat = 0):
val = "Hello\0there"
test_method(c.UpOctetArray, (val,), val.upper())
test_method(c.UpOctetArray, (unicode(val),), val.upper())
# Passing Unicode objects here used to cause us grief.
test_method(c.UpOctetArray2, (val,), val.upper())
test_method(c.CheckInterfaceArray, ((c, c),), 1)