Author: mattip <matti.pi...@gmail.com>
Branch: cpyext-ext
Changeset: r82360:74587c2585fe
Date: 2016-02-20 23:03 +0100
http://bitbucket.org/pypy/pypy/changeset/74587c2585fe/

Log:    unicode tests pass

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -473,7 +473,7 @@
         "PyUnicode_Type": "space.w_unicode",
         "PyBaseString_Type": "space.w_basestring",
         "PyDict_Type": "space.w_dict",
-        "PyDictProxy_Type": "space.type(space.w_NotImplemented)",
+        #"PyDictProxy_Type": "space.type(space.w_NotImplemented)",
         "PyTuple_Type": "space.w_tuple",
         "PyList_Type": "space.w_list",
         "PySet_Type": "space.w_set",
diff --git a/pypy/module/cpyext/floatobject.py 
b/pypy/module/cpyext/floatobject.py
--- a/pypy/module/cpyext/floatobject.py
+++ b/pypy/module/cpyext/floatobject.py
@@ -3,7 +3,7 @@
     cpython_struct,
     CANNOT_FAIL, cpython_api, PyObject, build_type_checkers, CONST_STRING)
 from pypy.module.cpyext.pyobject import (
-    make_typedescr, track_reference, RefcountState, from_ref)
+    make_typedescr, track_reference, from_ref)
 from pypy.interpreter.error import OperationError
 from rpython.rlib.rstruct import runpack
 from pypy.objspace.std.floatobject import W_FloatObject
@@ -36,8 +36,6 @@
     w_obj = space.allocate_instance(W_FloatObject, w_type)
     w_obj.__init__(floatval)
     track_reference(space, obj, w_obj)
-    state = space.fromcache(RefcountState)
-    state.set_lifeline(w_obj, obj)
     return w_obj
 
 PyFloat_Check, PyFloat_CheckExact = build_type_checkers("Float")
diff --git a/pypy/module/cpyext/test/test_unicodeobject.py 
b/pypy/module/cpyext/test/test_unicodeobject.py
--- a/pypy/module/cpyext/test/test_unicodeobject.py
+++ b/pypy/module/cpyext/test/test_unicodeobject.py
@@ -1,4 +1,4 @@
-# encoding: iso-8859-15
+# encoding: utf-8
 from pypy.module.cpyext.test.test_api import BaseApiTest
 from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
 from pypy.module.cpyext.unicodeobject import (
@@ -21,13 +21,13 @@
                  PyObject* s = PyUnicode_FromString("Hello world");
                  int result = 0;
 
-                 if(PyUnicode_GetSize(s) == 11) {
-                     result = 1;
+                 if(PyUnicode_GetSize(s) != 11) {
+                     result = -PyUnicode_GetSize(s);
                  }
-                 if(s->ob_type->tp_basicsize != sizeof(void*)*6)
-                     result = 0;
+                 if(s->ob_type->tp_basicsize != sizeof(void*)*7)
+                     result = s->ob_type->tp_basicsize;
                  Py_DECREF(s);
-                 return PyBool_FromLong(result);
+                 return PyLong_FromLong(result);
              """),
             ("test_GetSize_exception", "METH_NOARGS",
              """
@@ -42,7 +42,7 @@
                 return PyBool_FromLong(PyUnicode_Check(PyTuple_GetItem(args, 
0)));
              """)])
         assert module.get_hello1() == u'Hello world'
-        assert module.test_GetSize()
+        assert module.test_GetSize() == 0
         raises(TypeError, module.test_GetSize_exception)
 
         assert module.test_is_unicode(u"")
@@ -73,7 +73,8 @@
             ])
         s = module.getunicode()
         assert len(s) == 4
-        assert s == u'a&#65533;\x00c'
+        assert s == u'a\xe9\x00c'
+
 
     def test_hash(self):
         module = self.import_extension('foo', [
@@ -130,7 +131,7 @@
         utf_8 = rffi.str2charp('utf-8')
         encoded = api.PyUnicode_AsEncodedString(space.wrap(u'sp&#65533;m'),
                                                 utf_8, None)
-        assert space.unwrap(encoded) == 'sp\xc3\xa4m'
+        assert space.unwrap(encoded) == 'sp\xef\xbf\xbdm'
         encoded_obj = api.PyUnicode_AsEncodedObject(space.wrap(u'sp&#65533;m'),
                                                 utf_8, None)
         assert space.eq_w(encoded, encoded_obj)
@@ -155,14 +156,14 @@
         rffi.free_wcharp(buf)
 
     def test_fromstring(self, space, api):
-        s = rffi.str2charp(u'sp&#65533;m'.encode("utf-8"))
+        s = rffi.str2charp(u'sp\x09m'.encode("utf-8"))
         w_res = api.PyUnicode_FromString(s)
-        assert space.unwrap(w_res) == u'sp&#65533;m'
+        assert space.unwrap(w_res) == u'sp\x09m'
 
         res = api.PyUnicode_FromStringAndSize(s, 4)
         w_res = from_ref(space, res)
         api.Py_DecRef(res)
-        assert space.unwrap(w_res) == u'sp&#65533;'
+        assert space.unwrap(w_res) == u'sp\x09m'
         rffi.free_charp(s)
 
     def test_unicode_resize(self, space, api):
@@ -188,16 +189,16 @@
         lltype.free(ar, flavor='raw')
 
     def test_AsUTF8String(self, space, api):
-        w_u = space.wrap(u'sp&#65533;m')
+        w_u = space.wrap(u'sp\x09m')
         w_res = api.PyUnicode_AsUTF8String(w_u)
         assert space.type(w_res) is space.w_str
-        assert space.unwrap(w_res) == 'sp\xc3\xa4m'
+        assert space.unwrap(w_res) == 'sp\tm'
     
     def test_decode_utf8(self, space, api):
-        u = rffi.str2charp(u'sp&#65533;m'.encode("utf-8"))
+        u = rffi.str2charp(u'sp\x134m'.encode("utf-8"))
         w_u = api.PyUnicode_DecodeUTF8(u, 5, None)
         assert space.type(w_u) is space.w_unicode
-        assert space.unwrap(w_u) == u'sp&#65533;m'
+        assert space.unwrap(w_u) == u'sp\x134m'
         
         w_u = api.PyUnicode_DecodeUTF8(u, 2, None)
         assert space.type(w_u) is space.w_unicode
@@ -205,9 +206,9 @@
         rffi.free_charp(u)
 
     def test_encode_utf8(self, space, api):
-        u = rffi.unicode2wcharp(u'sp&#65533;m')
+        u = rffi.unicode2wcharp(u'sp\x09m')
         w_s = api.PyUnicode_EncodeUTF8(u, 4, None)
-        assert space.unwrap(w_s) == u'sp&#65533;m'.encode('utf-8')
+        assert space.unwrap(w_s) == u'sp\x09m'.encode('utf-8')
         rffi.free_wcharp(u)
 
     def test_encode_decimal(self, space, api):
@@ -269,13 +270,11 @@
         for char in [0x0a, 0x0d, 0x1c, 0x1d, 0x1e, 0x85, 0x2028, 0x2029]:
             assert api.Py_UNICODE_ISLINEBREAK(unichr(char))
 
-        assert api.Py_UNICODE_ISLOWER(u'&#65533;')
-        assert not api.Py_UNICODE_ISUPPER(u'&#65533;')
+        assert api.Py_UNICODE_ISLOWER(u'\xdf') # sharp s
+        assert api.Py_UNICODE_ISUPPER(u'\xde') # capital thorn
         assert api.Py_UNICODE_ISLOWER(u'a')
         assert not api.Py_UNICODE_ISUPPER(u'a')
-        assert not api.Py_UNICODE_ISLOWER(u'&#65533;')
-        assert api.Py_UNICODE_ISUPPER(u'&#65533;')
-        assert not api.Py_UNICODE_ISTITLE(u'A')
+        assert not api.Py_UNICODE_ISTITLE(u'\xce')
         assert api.Py_UNICODE_ISTITLE(
             u'\N{LATIN CAPITAL LETTER L WITH SMALL LETTER J}')
 
diff --git a/pypy/module/cpyext/tupleobject.py 
b/pypy/module/cpyext/tupleobject.py
--- a/pypy/module/cpyext/tupleobject.py
+++ b/pypy/module/cpyext/tupleobject.py
@@ -101,7 +101,7 @@
     track_reference(space, py_obj, w_obj)
     return w_obj
 
-@cpython_api([PyObject], lltype.Void, external=False)
+@cpython_api([PyObject], lltype.Void, header=None)
 def tuple_dealloc(space, py_obj):
     """Frees allocated PyTupleObject resources.
     """
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -16,7 +16,8 @@
     cpython_api, cpython_struct, bootstrap_function, Py_ssize_t, Py_ssize_tP,
     generic_cpy_call, Py_TPFLAGS_READY, Py_TPFLAGS_READYING,
     Py_TPFLAGS_HEAPTYPE, METH_VARARGS, METH_KEYWORDS, CANNOT_FAIL,
-    Py_TPFLAGS_HAVE_GETCHARBUFFER, build_type_checkers, StaticObjectBuilder)
+    Py_TPFLAGS_HAVE_GETCHARBUFFER, build_type_checkers, StaticObjectBuilder,
+    PyObjectFields)
 from pypy.module.cpyext.methodobject import (
     PyDescr_NewWrapper, PyCFunction_NewEx, PyCFunction_typedef)
 from pypy.module.cpyext.modsupport import convert_method_defs
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to