[pypy-commit] pypy py3.3: merge py3k
pjenvey
noreply at buildbot.pypy.org
Fri Sep 12 00:15:26 CEST 2014
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3.3
Changeset: r73491:a4b792a114c2
Date: 2014-09-11 15:14 -0700
http://bitbucket.org/pypy/pypy/changeset/a4b792a114c2/
Log: merge py3k
diff --git a/pypy/interpreter/test/test_app_main.py b/pypy/interpreter/test/test_app_main.py
--- a/pypy/interpreter/test/test_app_main.py
+++ b/pypy/interpreter/test/test_app_main.py
@@ -1107,7 +1107,7 @@
assert sys.executable == '' # not executable!
assert sys.path == old_sys_path + [self.goal_dir]
- os.chmod(self.fake_exe, 0755)
+ os.chmod(self.fake_exe, 0o755)
app_main.setup_bootstrap_path(self.fake_exe)
assert sys.executable == self.fake_exe
assert self.goal_dir not in sys.path
diff --git a/pypy/module/operator/test/test_tscmp.py b/pypy/module/operator/test/test_tscmp.py
--- a/pypy/module/operator/test/test_tscmp.py
+++ b/pypy/module/operator/test/test_tscmp.py
@@ -1,28 +1,14 @@
-from pypy.module.operator.tscmp import pypy_tscmp, pypy_tscmp_wide
+from pypy.module.operator.tscmp import pypy_tscmp
class TestTimingSafeCompare:
- tostr = str
- tscmp = staticmethod(pypy_tscmp)
-
def test_tscmp_neq(self):
- assert not self.tscmp(self.tostr('asd'), self.tostr('qwe'), 3, 3)
+ assert not pypy_tscmp('asd', 'qwe', 3, 3)
def test_tscmp_eq(self):
- assert self.tscmp(self.tostr('asd'), self.tostr('asd'), 3, 3)
+ assert pypy_tscmp('asd', 'asd', 3, 3)
def test_tscmp_len(self):
- assert self.tscmp(self.tostr('asdp'), self.tostr('asdq'), 3, 3)
+ assert pypy_tscmp('asdp', 'asdq', 3, 3)
def test_tscmp_nlen(self):
- assert not self.tscmp(self.tostr('asd'), self.tostr('asd'), 2, 3)
-
-
-class TestTimingSafeCompareWide(TestTimingSafeCompare):
- tostr = unicode
- tscmp = staticmethod(pypy_tscmp_wide)
-
- def test_tscmp_wide_nonascii(self):
- a, b = u"\ud808\udf45", u"\ud808\udf45"
- assert self.tscmp(a, b, len(a), len(b))
- a, b = u"\ud808\udf45", u"\ud808\udf45 "
- assert not self.tscmp(a, b, len(a), len(b))
+ assert not pypy_tscmp('asd', 'asd', 2, 3)
diff --git a/pypy/module/operator/tscmp.c b/pypy/module/operator/tscmp.c
--- a/pypy/module/operator/tscmp.c
+++ b/pypy/module/operator/tscmp.c
@@ -2,7 +2,6 @@
*/
#include <stdlib.h>
-#include <wchar.h>
#include "tscmp.h"
int
@@ -41,40 +40,3 @@
return (result == 0);
}
-
-int
-pypy_tscmp_wide(const wchar_t *a, const wchar_t *b, long len_a, long len_b)
-{
- /* The volatile type declarations make sure that the compiler has no
- * chance to optimize and fold the code in any way that may change
- * the timing.
- */
- volatile long length;
- volatile const wchar_t *left;
- volatile const wchar_t *right;
- long i;
- wchar_t result;
-
- /* loop count depends on length of b */
- length = len_b;
- left = NULL;
- right = b;
-
- /* don't use else here to keep the amount of CPU instructions constant,
- * volatile forces re-evaluation
- * */
- if (len_a == length) {
- left = *((volatile const wchar_t**)&a);
- result = 0;
- }
- if (len_a != length) {
- left = b;
- result = 1;
- }
-
- for (i=0; i < length; i++) {
- result |= *left++ ^ *right++;
- }
-
- return (result == 0);
-}
diff --git a/pypy/module/operator/tscmp.h b/pypy/module/operator/tscmp.h
--- a/pypy/module/operator/tscmp.h
+++ b/pypy/module/operator/tscmp.h
@@ -1,2 +1,1 @@
int pypy_tscmp(const char *, const char *, long, long);
-int pypy_tscmp_wide(const wchar_t *, const wchar_t *, long, long);
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
@@ -7,14 +7,15 @@
from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.translator.tool.cbuild import ExternalCompilationInfo
-from pypy.interpreter.error import oefmt
+from pypy.interpreter.error import OperationError, oefmt
+from pypy.interpreter.unicodehelper import encode
cwd = py.path.local(__file__).dirpath()
eci = ExternalCompilationInfo(
includes=[cwd.join('tscmp.h')],
include_dirs=[str(cwd)],
separate_module_files=[cwd.join('tscmp.c')],
- export_symbols=['pypy_tscmp', 'pypy_tscmp_wide'])
+ export_symbols=['pypy_tscmp'])
def llexternal(*args, **kwargs):
@@ -27,10 +28,6 @@
'pypy_tscmp',
[rffi.CCHARP, rffi.CCHARP, rffi.LONG, rffi.LONG],
rffi.INT)
-pypy_tscmp_wide = llexternal(
- 'pypy_tscmp_wide',
- [rffi.CWCHARP, rffi.CWCHARP, rffi.LONG, rffi.LONG],
- rffi.INT)
def compare_digest(space, w_a, w_b):
@@ -47,26 +44,21 @@
"""
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.wrap(rffi.cast(lltype.Bool, result))
+ try:
+ w_a = encode(space, w_a, 'ascii')
+ w_b = encode(space, w_b, 'ascii')
+ except OperationError as e:
+ if not e.match(space, space.w_UnicodeEncodeError):
+ raise
+ raise oefmt(space.w_TypeError,
+ "comparing strings with non-ASCII characters is not "
+ "supported")
return compare_digest_buffer(space, w_a, w_b)
def compare_digest_buffer(space, w_a, w_b):
- try:
- a_buf = w_a.buffer_w(space, space.BUF_SIMPLE)
- b_buf = w_b.buffer_w(space, space.BUF_SIMPLE)
- except TypeError:
- raise oefmt(space.w_TypeError,
- "unsupported operand types(s) or combination of types: "
- "'%T' and '%T'", w_a, w_b)
-
- a = a_buf.as_str()
- b = b_buf.as_str()
+ a = space.bufferstr_w(w_a)
+ b = space.bufferstr_w(w_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))
More information about the pypy-commit
mailing list