Changed a run-time test into compile-time

This commit is contained in:
John Wiegley 2012-02-10 19:56:48 -10:00
parent ff666a4469
commit 63c8d9054c

View file

@ -111,13 +111,12 @@ struct string_from_python
const Py_UNICODE* value = PyUnicode_AS_UNICODE(obj_ptr); const Py_UNICODE* value = PyUnicode_AS_UNICODE(obj_ptr);
string str; string str;
if (sizeof(Py_UNICODE) == 2) // UTF-16 #if Py_UNICODE_SIZE == 2 // UTF-16
utf8::unchecked::utf16to8(value, value + size, std::back_inserter(str)); utf8::unchecked::utf16to8(value, value + size, std::back_inserter(str));
else if (sizeof(Py_UNICODE) == 4) // UTF-32 #elif Py_UNICODE_SIZE == 4 // UTF-32
utf8::unchecked::utf32to8(value, value + size, std::back_inserter(str)); utf8::unchecked::utf32to8(value, value + size, std::back_inserter(str));
#if !defined(NO_ASSERTS) #else
else assert("Py_UNICODE has an unexpected size" == NULL);
assert(! "Py_UNICODE has an unexpected size");
#endif #endif
if (value == 0) throw_error_already_set(); if (value == 0) throw_error_already_set();