Monkey-patch some string functions in narrow string builds

The official distribution of Python 2.7 on Windows is built with "narrow strings" (UTF-16 strings with no proper indexing or length). This makes some tests fail. "Fix" this by monkey-patching a few functions and using a wrapping unicode class, as we can't monkey-patch the actual unicode type.

This is very fragile code, but it's the best we could do given the limitations.
This commit is contained in:
Sei Lisa 2022-12-11 20:39:44 +01:00
parent 79a57e6532
commit dc655e3501
2 changed files with 71 additions and 2 deletions

View file

@ -674,6 +674,8 @@ def InternalUTF8toString(s):
# type check. Same for llGetSubString and llList2List. They are all joined into
# one single function.
def InternalGetDeleteSubSequence(val, start, end, isGet):
if type(val) == unicode:
val = uniwrap(val)
start = fi(start)
end = fi(end)
L = len(val)
@ -1298,7 +1300,7 @@ def llGetSubString(s, start, end):
return InternalGetDeleteSubSequence(s, start, end, isGet=True)
def llHash(s):
s = fs(s)
s = uniwrap(fs(s))
hash = 0
for i in s:
hash = (hash * 65599 + ord(i)) & 0xFFFFFFFF
@ -1718,7 +1720,7 @@ def llModPow(base, exp, mod):
return S32(ret)
def llOrd(val, index):
val = fs(val)
val = uniwrap(fs(val))
index = fi(index)
L = len(val)
if -L <= index < L: