Author: fijal
Branch: unicode-utf8
Changeset: r93265:cdf9331a2d41
Date: 2017-12-03 16:35 +0100
http://bitbucket.org/pypy/pypy/changeset/cdf9331a2d41/
Log: "fix" the operator module
diff --git a/pypy/module/operator/tscmp.py b/pypy/module/operator/tscmp.py
--- a/pypy/module/operator/tscmp.py
+++ b/pypy/module/operator/tscmp.py
@@ -45,15 +45,15 @@
Note: If a and b are of different lengths, or if an error occurs, a
timing attack could theoretically reveal information about the types
and lengths of a and b--but not their values.
+
+ XXX note that here the strings have to have the same length as UTF8,
+ not only as unicode. Not sure how to do better
"""
if (space.isinstance_w(w_a, space.w_unicode) and
space.isinstance_w(w_b, space.w_unicode)):
- a = space.unicode_w(w_a)
- b = space.unicode_w(w_b)
- with rffi.scoped_nonmoving_unicodebuffer(a) as a_buf:
- with rffi.scoped_nonmoving_unicodebuffer(b) as b_buf:
- result = pypy_tscmp_wide(a_buf, b_buf, len(a), len(b))
- return space.newbool(rffi.cast(lltype.Bool, result))
+ a = space.utf8_w(w_a)
+ b = space.utf8_w(w_b)
+ return space.newbool(_compare_two_strings(a, b))
return compare_digest_buffer(space, w_a, w_b)
@@ -68,7 +68,10 @@
a = a_buf.as_str()
b = b_buf.as_str()
+ return space.newbool(_compare_two_strings(a, b))
+
+def _compare_two_strings(a, b):
with rffi.scoped_nonmovingbuffer(a) as a_buf:
with rffi.scoped_nonmovingbuffer(b) as b_buf:
result = pypy_tscmp(a_buf, b_buf, len(a), len(b))
- return space.newbool(rffi.cast(lltype.Bool, result))
+ return rffi.cast(lltype.Bool, result)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit