[pypy-commit] pypy cpyext-ext: add test, passes -A, fails untranslated

mattip pypy.commits at gmail.com
Sun Feb 28 23:45:51 EST 2016


Author: mattip <matti.picus at gmail.com>
Branch: cpyext-ext
Changeset: r82609:22fa8dfd0a2d
Date: 2016-02-28 23:43 -0500
http://bitbucket.org/pypy/pypy/changeset/22fa8dfd0a2d/

Log:	add test, passes -A, fails untranslated

diff --git a/pypy/module/cpyext/test/test_stringobject.py b/pypy/module/cpyext/test/test_stringobject.py
--- a/pypy/module/cpyext/test/test_stringobject.py
+++ b/pypy/module/cpyext/test/test_stringobject.py
@@ -89,7 +89,26 @@
         assert len(s) == 4
         assert s == 'ab\x00c'
 
-
+    def test_string_tp_alloc(self):
+        module = self.import_extension('foo', [
+            ("getstring", "METH_NOARGS",
+             """
+                PyObject *base;
+                PyTypeObject * type;
+                PyStringObject *obj;
+                char * p_str;
+                base = PyString_FromString("test");
+                type = base->ob_type;
+                obj = (PyStringObject*)type->tp_alloc(type, 10);
+                if (PyString_GET_SIZE(obj) == 0)
+                    return PyLong_FromLong(-1);
+                memcpy(PyString_AS_STRING(obj), "works", 6);
+                Py_INCREF(obj);
+                return (PyObject*)obj;
+             """),
+            ])
+        s = module.getstring()
+        assert s == 'works\x00\x00\x00\x00\x00'
 
     def test_AsString(self):
         module = self.import_extension('foo', [


More information about the pypy-commit mailing list