Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r54858:c346a55c6258
Date: 2012-04-30 23:01 +0200
http://bitbucket.org/pypy/pypy/changeset/c346a55c6258/

Log:    Various fixes to cpyext, until the test suite executes all tests.
        (103 failures, 227 passed)

diff --git a/pypy/module/cpyext/dictobject.py b/pypy/module/cpyext/dictobject.py
--- a/pypy/module/cpyext/dictobject.py
+++ b/pypy/module/cpyext/dictobject.py
@@ -215,3 +215,11 @@
     w_frozendict = make_frozendict(space)
     return space.call_function(w_frozendict, w_dict)
 
+@cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
+def _PyDict_HasOnlyStringKeys(space, w_dict):
+    keys_w = space.unpackiterable(w_dict)
+    for w_key in keys_w:
+        if not space.isinstance_w(w_key, space.w_unicode):
+            return 0
+    return 1
+
diff --git a/pypy/module/cpyext/include/bytesobject.h 
b/pypy/module/cpyext/include/bytesobject.h
--- a/pypy/module/cpyext/include/bytesobject.h
+++ b/pypy/module/cpyext/include/bytesobject.h
@@ -25,3 +25,6 @@
 #define _PyBytes_Join _PyString_Join
 #define PyBytes_AsStringAndSize PyString_AsStringAndSize
 #define _PyBytes_InsertThousandsGrouping _PyString_InsertThousandsGrouping
+
+#define PyByteArray_Check(obj) \
+    PyObject_IsInstance(obj, (PyObject *)&PyByteArray_Type)
diff --git a/pypy/module/cpyext/include/modsupport.h 
b/pypy/module/cpyext/include/modsupport.h
--- a/pypy/module/cpyext/include/modsupport.h
+++ b/pypy/module/cpyext/include/modsupport.h
@@ -7,6 +7,8 @@
 extern "C" {
 #endif
 
+#define Py_CLEANUP_SUPPORTED 0x20000
+
 #define PYTHON_API_VERSION 1013
 #define PYTHON_API_STRING "1013"
 
diff --git a/pypy/module/cpyext/include/object.h 
b/pypy/module/cpyext/include/object.h
--- a/pypy/module/cpyext/include/object.h
+++ b/pypy/module/cpyext/include/object.h
@@ -529,6 +529,8 @@
 
 #define PyObject_GC_New(type, typeobj) \
                 ( (type *) _PyObject_GC_New(typeobj) )
+#define PyObject_GC_NewVar(type, typeobj, size) \
+                ( (type *) _PyObject_GC_NewVar(typeobj, size) )
 
 /* A dummy PyGC_Head, just to please some tests. Don't use it! */
 typedef union _gc_head {
diff --git a/pypy/module/cpyext/include/structseq.h 
b/pypy/module/cpyext/include/structseq.h
--- a/pypy/module/cpyext/include/structseq.h
+++ b/pypy/module/cpyext/include/structseq.h
@@ -8,21 +8,21 @@
 #endif
 
 typedef struct PyStructSequence_Field {
-       char *name;
-       char *doc;
+    char *name;
+    char *doc;
 } PyStructSequence_Field;
 
 typedef struct PyStructSequence_Desc {
-       char *name;
-       char *doc;
-       struct PyStructSequence_Field *fields;
-       int n_in_sequence;
+    char *name;
+    char *doc;
+    struct PyStructSequence_Field *fields;
+    int n_in_sequence;
 } PyStructSequence_Desc;
 
 extern char* PyStructSequence_UnnamedField;
 
 PyAPI_FUNC(void) PyStructSequence_InitType(PyTypeObject *type,
-                                          PyStructSequence_Desc *desc);
+                                           PyStructSequence_Desc *desc);
 
 PyAPI_FUNC(PyObject *) PyStructSequence_New(PyTypeObject* type);
 
@@ -32,8 +32,9 @@
 } PyStructSequence;
 
 /* Macro, *only* to be used to fill in brand new objects */
-#define PyStructSequence_SET_ITEM(op, i, v) \
-       (((PyStructSequence *)(op))->ob_item[i] = v)
+#define PyStructSequence_SET_ITEM(op, i, v) PyTuple_SET_ITEM(op, i, v)
+
+#define PyStructSequence_GET_ITEM(op, i) PyTuple_GET_ITEM(op, i)
 
 #ifdef __cplusplus
 }
diff --git a/pypy/module/cpyext/include/unicodeobject.h 
b/pypy/module/cpyext/include/unicodeobject.h
--- a/pypy/module/cpyext/include/unicodeobject.h
+++ b/pypy/module/cpyext/include/unicodeobject.h
@@ -29,6 +29,16 @@
 PyObject *PyUnicode_FromFormatV(const char *format, va_list vargs);
 PyObject *PyUnicode_FromFormat(const char *format, ...);
 
+Py_LOCAL_INLINE(size_t) Py_UNICODE_strlen(const Py_UNICODE *u)
+{
+    int res = 0;
+    while(*u++)
+        res++;
+    return res;
+}
+
+
+
 #ifdef __cplusplus
 }
 #endif
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
@@ -57,6 +57,10 @@
 def _PyObject_GC_New(space, type):
     return _PyObject_New(space, type)
 
+@cpython_api([PyTypeObjectPtr, Py_ssize_t], PyObject)
+def _PyObject_GC_NewVar(space, type, itemcount):
+    return _PyObject_NewVar(space, type, itemcount)
+
 @cpython_api([rffi.VOIDP], lltype.Void)
 def PyObject_GC_Del(space, obj):
     PyObject_Del(space, obj)
diff --git a/pypy/module/cpyext/test/test_classobject.py 
b/pypy/module/cpyext/test/test_classobject.py
deleted file mode 100644
--- a/pypy/module/cpyext/test/test_classobject.py
+++ /dev/null
@@ -1,65 +0,0 @@
-from pypy.module.cpyext.test.test_api import BaseApiTest
-from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
-from pypy.interpreter.function import Function, Method
-
-class TestClassObject(BaseApiTest):
-    def test_newinstance(self, space, api):
-        w_class = space.appexec([], """():
-            class C:
-                x = None
-                def __init__(self):
-                    self.x = 1
-            return C
-        """)
-
-        assert api.PyClass_Check(w_class)
-
-        w_instance = api.PyInstance_NewRaw(w_class, None)
-        assert api.PyInstance_Check(w_instance)
-        assert space.getattr(w_instance, space.wrap('x')) is space.w_None
-
-        w_instance = api.PyInstance_NewRaw(w_class, space.wrap(dict(a=3)))
-        assert space.getattr(w_instance, space.wrap('x')) is space.w_None
-        assert space.unwrap(space.getattr(w_instance, space.wrap('a'))) == 3
-
-    def test_lookup(self, space, api):
-        w_instance = space.appexec([], """():
-            class C:
-                def __init__(self):
-                    self.x = None
-                def f(self): pass
-            return C()
-        """)
-
-        assert api.PyInstance_Check(w_instance)
-        assert api.PyObject_GetAttr(w_instance, space.wrap('x')) is 
space.w_None
-        assert api._PyInstance_Lookup(w_instance, space.wrap('x')) is 
space.w_None
-        assert api._PyInstance_Lookup(w_instance, space.wrap('y')) is None
-        assert not api.PyErr_Occurred()
-
-        # getattr returns a bound method
-        assert not isinstance(api.PyObject_GetAttr(w_instance, 
space.wrap('f')), Function)
-        # _PyInstance_Lookup returns the raw descriptor
-        assert isinstance(api._PyInstance_Lookup(w_instance, space.wrap('f')), 
Function)
-
-    def test_pyclass_new(self, space, api):
-        w_bases = space.newtuple([])
-        w_dict = space.newdict()
-        w_name = space.wrap("C")
-        w_class = api.PyClass_New(w_bases, w_dict, w_name)
-        assert not space.isinstance_w(w_class, space.w_type)
-        w_instance = space.call_function(w_class)
-        assert api.PyInstance_Check(w_instance)
-        assert space.is_true(space.call_method(space.builtin, "isinstance",
-                                               w_instance, w_class))
-
-class AppTestStringObject(AppTestCpythonExtensionBase):
-    def test_class_type(self):
-        module = self.import_extension('foo', [
-            ("get_classtype", "METH_NOARGS",
-             """
-                 Py_INCREF(&PyClass_Type);
-                 return &PyClass_Type;
-             """)])
-        class C: pass
-        assert module.get_classtype() is type(C)
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
@@ -139,42 +139,6 @@
             ])
         module.getstring()
 
-    def test_format_v(self):
-        module = self.import_extension('foo', [
-            ("test_string_format_v", "METH_VARARGS",
-             '''
-                 return helper("bla %d ble %s\\n",
-                        PyInt_AsLong(PyTuple_GetItem(args, 0)),
-                        PyString_AsString(PyTuple_GetItem(args, 1)));
-             '''
-             )
-            ], prologue='''
-            PyObject* helper(char* fmt, ...)
-            {
-              va_list va;
-              PyObject* res;
-              va_start(va, fmt);
-              res = PyString_FromFormatV(fmt, va);
-              va_end(va);
-              return res;
-            }
-            ''')
-        res = module.test_string_format_v(1, "xyz")
-        assert res == "bla 1 ble xyz\n"
-
-    def test_format(self):
-        module = self.import_extension('foo', [
-            ("test_string_format", "METH_VARARGS",
-             '''
-                 return PyString_FromFormat("bla %d ble %s\\n",
-                        PyInt_AsLong(PyTuple_GetItem(args, 0)),
-                        PyString_AsString(PyTuple_GetItem(args, 1)));
-             '''
-             )
-            ])
-        res = module.test_string_format(1, "xyz")
-        assert res == "bla 1 ble xyz\n"
-
     def test_intern_inplace(self):
         module = self.import_extension('foo', [
             ("test_intern_inplace", "METH_O",
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to