Author: Ronan Lamy <[email protected]>
Branch: unicode-utf8
Changeset: r93317:5677dc1909e9
Date: 2017-12-08 14:45 +0000
http://bitbucket.org/pypy/pypy/changeset/5677dc1909e9/
Log: fixes
diff --git a/pypy/module/cpyext/longobject.py b/pypy/module/cpyext/longobject.py
--- a/pypy/module/cpyext/longobject.py
+++ b/pypy/module/cpyext/longobject.py
@@ -4,6 +4,7 @@
CONST_STRING, ADDR, CANNOT_FAIL)
from pypy.objspace.std.longobject import W_LongObject
from pypy.interpreter.error import OperationError
+from pypy.interpreter.unicodehelper import wcharpsize2utf8
from pypy.module.cpyext.intobject import PyInt_AsUnsignedLongMask
from rpython.rlib.rbigint import rbigint
@@ -191,7 +192,7 @@
string, length gives the number of characters, and base is the radix
for the conversion. The radix must be in the range [2, 36]; if it is
out of range, ValueError will be raised."""
- w_value = space.newunicode(rffi.wcharpsize2unicode(u, length))
+ w_value = space.newutf8(wcharpsize2utf8(space, u, length), length)
w_base = space.newint(rffi.cast(lltype.Signed, base))
return space.call_function(space.w_long, w_value, w_base)
diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py
--- a/pypy/module/cpyext/object.py
+++ b/pypy/module/cpyext/object.py
@@ -246,7 +246,7 @@
the Python expression unicode(o). Called by the unicode() built-in
function."""
if w_obj is None:
- return space.newunicode(u"<NULL>")
+ return space.newutf8("<NULL>", 6)
return space.call_function(space.w_unicode, w_obj)
@cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
@@ -302,7 +302,7 @@
if opid == Py_EQ:
return 1
if opid == Py_NE:
- return 0
+ return 0
w_res = PyObject_RichCompare(space, w_o1, w_o2, opid_int)
return int(space.is_true(w_res))
diff --git a/pypy/module/cpyext/unicodeobject.py
b/pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py
+++ b/pypy/module/cpyext/unicodeobject.py
@@ -710,12 +710,17 @@
"""Return 1 if substr matches str[start:end] at the given tail end
(direction == -1 means to do a prefix match, direction == 1 a
suffix match), 0 otherwise. Return -1 if an error occurred."""
+ space.utf8_w(w_str) # type check
+ space.utf8_w(w_substr)
w_start = space.newint(start)
w_end = space.newint(end)
if rffi.cast(lltype.Signed, direction) <= 0:
- return space.call_method(w_str, "startswith", w_substr, w_start, w_end)
+ w_result = space.call_method(
+ w_str, "startswith", w_substr, w_start, w_end)
else:
- return space.call_method(w_str, "endswith", w_substr, w_start, w_end)
+ w_result = space.call_method(
+ w_str, "endswith", w_substr, w_start, w_end)
+ return space.int_w(w_result)
@cpython_api([PyObject, PyObject, Py_ssize_t, Py_ssize_t], Py_ssize_t,
error=-1)
def PyUnicode_Count(space, w_str, w_substr, start, end):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit