[pypy-commit] pypy testing-cleanup: Use DistutilsPlatform as a stepping stone to removing the dependency on rpython.platform
rlamy
pypy.commits at gmail.com
Tue Jun 14 14:07:26 EDT 2016
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: testing-cleanup
Changeset: r85167:670eb478dec3
Date: 2016-06-14 19:06 +0100
http://bitbucket.org/pypy/pypy/changeset/670eb478dec3/
Log: Use DistutilsPlatform as a stepping stone to removing the dependency
on rpython.platform
As a side-effect, this enables -Werror for C modules defined in
test_*.py files, so fix some of the warnings.
diff --git a/pypy/module/cpyext/test/test_bytearrayobject.py b/pypy/module/cpyext/test/test_bytearrayobject.py
--- a/pypy/module/cpyext/test/test_bytearrayobject.py
+++ b/pypy/module/cpyext/test/test_bytearrayobject.py
@@ -31,7 +31,7 @@
if(s->ob_type->tp_basicsize != expected_size)
{
printf("tp_basicsize==%ld\\n",
- (long)s->ob_type->tp_basicsize);
+ (long)s->ob_type->tp_basicsize);
result = 0;
}
Py_DECREF(s);
@@ -53,7 +53,6 @@
"""
PyObject *s, *t;
char* c;
- Py_ssize_t len;
s = PyByteArray_FromStringAndSize(NULL, 4);
if (s == NULL)
@@ -84,11 +83,10 @@
("mutable", "METH_NOARGS",
"""
PyObject *base;
- char * p_str;
base = PyByteArray_FromStringAndSize("test", 10);
if (PyByteArray_GET_SIZE(base) != 10)
return PyLong_FromLong(-PyByteArray_GET_SIZE(base));
- memcpy(PyByteArray_AS_STRING(base), "works", 6);
+ memcpy(PyByteArray_AS_STRING(base), "works", 6);
Py_INCREF(base);
return base;
"""),
@@ -141,9 +139,9 @@
("concat", "METH_VARARGS",
"""
PyObject * ret, *right, *left;
- PyObject *ba1, *ba2;
+ PyObject *ba1, *ba2;
if (!PyArg_ParseTuple(args, "OO", &left, &right)) {
- return PyString_FromString("parse failed");
+ return PyString_FromString("parse failed");
}
ba1 = PyByteArray_FromObject(left);
ba2 = PyByteArray_FromObject(right);
@@ -171,9 +169,9 @@
PyObject *obj, *ba;
int newsize, oldsize, ret;
if (!PyArg_ParseTuple(args, "Oi", &obj, &newsize)) {
- return PyString_FromString("parse failed");
+ return PyString_FromString("parse failed");
}
-
+
ba = PyByteArray_FromObject(obj);
if (ba == NULL)
return NULL;
@@ -187,7 +185,7 @@
{
printf("ret, oldsize, newsize= %d, %d, %d\\n", ret, oldsize, newsize);
return NULL;
- }
+ }
return ba;
'''
)])
diff --git a/pypy/module/cpyext/test/test_bytesobject.py b/pypy/module/cpyext/test/test_bytesobject.py
--- a/pypy/module/cpyext/test/test_bytesobject.py
+++ b/pypy/module/cpyext/test/test_bytesobject.py
@@ -40,7 +40,7 @@
#endif
if(s->ob_type->tp_basicsize != expected_size)
{
- printf("tp_basicsize==%zd\\n", s->ob_type->tp_basicsize);
+ printf("tp_basicsize==%zd\\n", s->ob_type->tp_basicsize);
result = 0;
}
Py_DECREF(s);
@@ -49,7 +49,7 @@
("test_Size_exception", "METH_NOARGS",
"""
PyObject* f = PyFloat_FromDouble(1.0);
- Py_ssize_t size = PyString_Size(f);
+ PyString_Size(f);
Py_DECREF(f);
return NULL;
@@ -72,7 +72,6 @@
"""
PyObject *s, *t;
char* c;
- Py_ssize_t len;
s = PyString_FromStringAndSize(NULL, 4);
if (s == NULL)
@@ -100,7 +99,6 @@
PyObject *base;
PyTypeObject * type;
PyStringObject *obj;
- char * p_str;
base = PyString_FromString("test");
if (PyString_GET_SIZE(base) != 4)
return PyLong_FromLong(-PyString_GET_SIZE(base));
@@ -312,17 +310,17 @@
'''
PyObject* obj = (PyTuple_GetItem(args, 0));
long hash = ((PyStringObject*)obj)->ob_shash;
- return PyLong_FromLong(hash);
+ return PyLong_FromLong(hash);
'''
),
("test_sstate", "METH_NOARGS",
'''
PyObject *s = PyString_FromString("xyz");
- int sstate = ((PyStringObject*)s)->ob_sstate;
- /*printf("sstate now %d\\n", sstate);*/
+ /*int sstate = ((PyStringObject*)s)->ob_sstate;
+ printf("sstate now %d\\n", sstate);*/
PyString_InternInPlace(&s);
- sstate = ((PyStringObject*)s)->ob_sstate;
- /*printf("sstate now %d\\n", sstate);*/
+ /*sstate = ((PyStringObject*)s)->ob_sstate;
+ printf("sstate now %d\\n", sstate);*/
Py_DECREF(s);
return PyBool_FromLong(1);
'''),
diff --git a/pypy/module/cpyext/test/test_cpyext.py b/pypy/module/cpyext/test/test_cpyext.py
--- a/pypy/module/cpyext/test/test_cpyext.py
+++ b/pypy/module/cpyext/test/test_cpyext.py
@@ -8,7 +8,7 @@
from pypy.interpreter import gateway
from rpython.rtyper.lltypesystem import lltype, ll2ctypes
from rpython.translator.tool.cbuild import ExternalCompilationInfo
-from rpython.translator import platform
+from rpython.translator.platform.distutils_platform import DistutilsPlatform
from rpython.translator.gensupp import uniquemodulename
from rpython.tool.udir import udir
from pypy.module.cpyext import api
@@ -18,6 +18,8 @@
from rpython.tool import leakfinder
from rpython.rlib import rawrefcount
+rpy_platform = DistutilsPlatform()
+
@api.cpython_api([], api.PyObject)
def PyPy_Crash1(space):
1/0
@@ -50,7 +52,7 @@
files = convert_sources_to_files(source_strings, dirname)
source_files = files
eci = ExternalCompilationInfo(include_dirs=include_dirs, **kwds)
- soname = platform.platform.compile(source_files, eci,
+ soname = rpy_platform.compile(source_files, eci,
outputfilename=str(dirname/modname),
standalone=False)
return soname
@@ -83,7 +85,7 @@
else:
kwds["link_files"] = [str(api_library + '.so')]
if sys.platform.startswith('linux'):
- kwds["compile_extra"] = ["-Werror", "-g", "-O0"]
+ kwds["compile_extra"] = ["-Werror", "-g", "-O0", "-fPIC"]
kwds["link_extra"] = ["-g"]
modname = modname.split('.')[-1]
@@ -116,7 +118,8 @@
elif sys.platform == 'darwin':
pass
elif sys.platform.startswith('linux'):
- kwds["compile_extra"] = ["-O0", "-g","-Werror=implicit-function-declaration"]
+ kwds["compile_extra"] = [
+ "-O0", "-g", "-Werror=implicit-function-declaration", "-fPIC"]
modname = modname.split('.')[-1]
soname = create_so(modname,
diff --git a/pypy/module/cpyext/test/test_frameobject.py b/pypy/module/cpyext/test/test_frameobject.py
--- a/pypy/module/cpyext/test/test_frameobject.py
+++ b/pypy/module/cpyext/test/test_frameobject.py
@@ -13,7 +13,7 @@
PyObject *empty_string = PyString_FromString("");
PyObject *empty_tuple = PyTuple_New(0);
PyCodeObject *py_code;
- PyFrameObject *py_frame;
+ PyFrameObject *py_frame = NULL;
py_code = PyCode_New(
0, /*int argcount,*/
@@ -75,7 +75,7 @@
"""
int check;
PyObject *type, *value, *tb;
- PyObject *ret = PyRun_String("XXX", Py_eval_input,
+ PyObject *ret = PyRun_String("XXX", Py_eval_input,
Py_None, Py_None);
if (ret) {
Py_DECREF(ret);
diff --git a/pypy/module/cpyext/test/test_getargs.py b/pypy/module/cpyext/test/test_getargs.py
--- a/pypy/module/cpyext/test/test_getargs.py
+++ b/pypy/module/cpyext/test/test_getargs.py
@@ -149,7 +149,6 @@
pybuffer = self.import_parser(
'''
Py_buffer buf1, buf2, buf3;
- PyObject *result;
if (!PyArg_ParseTuple(args, "s*s*s*", &buf1, &buf2, &buf3)) {
return NULL;
}
diff --git a/pypy/module/cpyext/test/test_object.py b/pypy/module/cpyext/test/test_object.py
--- a/pypy/module/cpyext/test/test_object.py
+++ b/pypy/module/cpyext/test/test_object.py
@@ -127,12 +127,12 @@
test_compare(1, 2)
test_compare(2, 2)
test_compare('2', '1')
-
+
w_i = space.wrap(1)
assert api.PyObject_RichCompareBool(w_i, w_i, 123456) == -1
assert api.PyErr_Occurred() is space.w_SystemError
api.PyErr_Clear()
-
+
def test_IsInstance(self, space, api):
assert api.PyObject_IsInstance(space.wrap(1), space.w_int) == 1
assert api.PyObject_IsInstance(space.wrap(1), space.w_float) == 0
@@ -165,7 +165,7 @@
return File""")
w_f = space.call_function(w_File)
assert api.PyObject_AsFileDescriptor(w_f) == 42
-
+
def test_hash(self, space, api):
assert api.PyObject_Hash(space.wrap(72)) == 72
assert api.PyObject_Hash(space.wrap(-1)) == -1
@@ -250,7 +250,7 @@
if (copy != orig)
PyObject_Free(copy);
PyObject_Free(orig);
- return ret;
+ return ret;
""")])
x = module.realloctest()
assert x == 'hello world\x00'
@@ -425,7 +425,6 @@
"""
Py_buffer buf;
PyObject *str = PyString_FromString("hello, world.");
- PyObject *result;
if (PyBuffer_FillInfo(&buf, str, PyString_AsString(str), 13,
1, PyBUF_WRITABLE)) {
diff --git a/pypy/module/cpyext/test/test_tupleobject.py b/pypy/module/cpyext/test/test_tupleobject.py
--- a/pypy/module/cpyext/test/test_tupleobject.py
+++ b/pypy/module/cpyext/test/test_tupleobject.py
@@ -130,7 +130,7 @@
module = self.import_extension('foo', [
("run", "METH_NOARGS",
"""
- long prev, next;
+ long prev;
PyObject *t = PyTuple_New(1);
prev = Py_True->ob_refcnt;
Py_INCREF(Py_True);
diff --git a/pypy/module/cpyext/test/test_typeobject.py b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -737,7 +737,6 @@
"""
IntLikeObject *intObj;
int intval;
- PyObject *name;
if (!PyArg_ParseTuple(args, "i", &intval))
return NULL;
@@ -1058,7 +1057,6 @@
module = self.import_extension('foo', [
("getMetaClass", "METH_NOARGS",
'''
- PyObject *obj;
FooType_Type.tp_flags = Py_TPFLAGS_DEFAULT;
FooType_Type.tp_base = &PyType_Type;
if (PyType_Ready(&FooType_Type) < 0) return NULL;
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
@@ -35,7 +35,7 @@
("test_GetSize_exception", "METH_NOARGS",
"""
PyObject* f = PyFloat_FromDouble(1.0);
- Py_ssize_t size = PyUnicode_GetSize(f);
+ PyUnicode_GetSize(f);
Py_DECREF(f);
return NULL;
@@ -57,7 +57,6 @@
"""
PyObject *s, *t;
Py_UNICODE* c;
- Py_ssize_t len;
s = PyUnicode_FromUnicode(NULL, 4);
if (s == NULL)
@@ -84,7 +83,7 @@
'''
PyObject* obj = (PyTuple_GetItem(args, 0));
long hash = ((PyUnicodeObject*)obj)->hash;
- return PyLong_FromLong(hash);
+ return PyLong_FromLong(hash);
'''
),
])
@@ -234,13 +233,13 @@
w_res = api.PyUnicode_AsUTF8String(w_u)
assert space.type(w_res) is space.w_str
assert space.unwrap(w_res) == 'sp\tm'
-
+
def test_decode_utf8(self, space, api):
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\x134m'
-
+
w_u = api.PyUnicode_DecodeUTF8(u, 2, None)
assert space.type(w_u) is space.w_unicode
assert space.unwrap(w_u) == 'sp'
@@ -405,7 +404,7 @@
ustr = "abcdef"
w_ustr = space.wrap(ustr.decode("ascii"))
result = api.PyUnicode_AsASCIIString(w_ustr)
-
+
assert space.eq_w(space.wrap(ustr), result)
w_ustr = space.wrap(u"abcd\xe9f")
More information about the pypy-commit
mailing list