Author: Devin Jeanpierre <[email protected]>
Branch: cpyext-werror
Changeset: r84033:2b6f392b8626
Date: 2016-04-29 10:25 -0700
http://bitbucket.org/pypy/pypy/changeset/2b6f392b8626/
Log: Compile with -Werror in cpyext tests.
Callers may build with -Werror and should not succeed with CPython
but fail with cpyext. This forces us to have the same API -- in
particular, to use the same pointer types and perform the same
casts. See, for example, the change to the API in ndarrayobject.py.
(This is an hg backout of changeset db306c552216 from when I
accidentally pushed this to pypy without code review... hee hee. :C)
diff --git a/pypy/module/cpyext/ndarrayobject.py
b/pypy/module/cpyext/ndarrayobject.py
--- a/pypy/module/cpyext/ndarrayobject.py
+++ b/pypy/module/cpyext/ndarrayobject.py
@@ -239,9 +239,7 @@
gufunctype = lltype.Ptr(ufuncs.GenericUfunc)
-# XXX single rffi.CArrayPtr(gufunctype) does not work, this does, is there
-# a problem with casting function pointers?
-@cpython_api([rffi.CArrayPtr(rffi.CArrayPtr(gufunctype)), rffi.VOIDP,
rffi.CCHARP, Py_ssize_t, Py_ssize_t,
+@cpython_api([rffi.CArrayPtr(gufunctype), rffi.VOIDP, rffi.CCHARP, Py_ssize_t,
Py_ssize_t,
Py_ssize_t, Py_ssize_t, rffi.CCHARP, rffi.CCHARP, Py_ssize_t,
rffi.CCHARP], PyObject, header=HEADER)
def PyUFunc_FromFuncAndDataAndSignature(space, funcs, data, types, ntypes,
@@ -249,14 +247,18 @@
w_signature = rffi.charp2str(signature)
return do_ufunc(space, funcs, data, types, ntypes, nin, nout, identity,
name, doc,
check_return, w_signature)
-
+
def do_ufunc(space, funcs, data, types, ntypes, nin, nout, identity, name, doc,
check_return, w_signature):
funcs_w = [None] * ntypes
dtypes_w = [None] * ntypes * (nin + nout)
+ # XXX For some reason funcs[i] segfaults, but this does not:
+ # cast(gufunctype, cast(CArrayPtr(CArrayPtr(gufunctype)), funcs)[i])
+ # Something is very wrong here.
+ funcs_wrong_type = rffi.cast(rffi.CArrayPtr(rffi.CArrayPtr(gufunctype)),
funcs)
for i in range(ntypes):
- funcs_w[i] = ufuncs.W_GenericUFuncCaller(rffi.cast(gufunctype,
funcs[i]), data)
+ funcs_w[i] = ufuncs.W_GenericUFuncCaller(rffi.cast(gufunctype,
funcs_wrong_type[i]), data)
for i in range(ntypes*(nin+nout)):
dtypes_w[i] = get_dtype_cache(space).dtypes_by_num[ord(types[i])]
w_funcs = space.newlist(funcs_w)
@@ -268,7 +270,7 @@
w_signature, w_identity, w_name, w_doc, stack_inputs=True)
return ufunc_generic
-@cpython_api([rffi.CArrayPtr(rffi.CArrayPtr(gufunctype)), rffi.VOIDP,
rffi.CCHARP, Py_ssize_t, Py_ssize_t,
+@cpython_api([rffi.CArrayPtr(gufunctype), rffi.VOIDP, rffi.CCHARP, Py_ssize_t,
Py_ssize_t,
Py_ssize_t, Py_ssize_t, rffi.CCHARP, rffi.CCHARP, Py_ssize_t],
PyObject, header=HEADER)
def PyUFunc_FromFuncAndData(space, funcs, data, types, ntypes,
nin, nout, identity, name, doc, check_return):
diff --git a/pypy/module/cpyext/test/test_borrow.py
b/pypy/module/cpyext/test/test_borrow.py
--- a/pypy/module/cpyext/test/test_borrow.py
+++ b/pypy/module/cpyext/test/test_borrow.py
@@ -12,13 +12,13 @@
PyObject *t = PyTuple_New(1);
PyObject *f = PyFloat_FromDouble(42.0);
PyObject *g = NULL;
- printf("Refcnt1: %i\\n", f->ob_refcnt);
+ printf("Refcnt1: %zd\\n", f->ob_refcnt);
PyTuple_SetItem(t, 0, f); // steals reference
- printf("Refcnt2: %i\\n", f->ob_refcnt);
+ printf("Refcnt2: %zd\\n", f->ob_refcnt);
f = PyTuple_GetItem(t, 0); // borrows reference
- printf("Refcnt3: %i\\n", f->ob_refcnt);
+ printf("Refcnt3: %zd\\n", f->ob_refcnt);
g = PyTuple_GetItem(t, 0); // borrows reference again
- printf("Refcnt4: %i\\n", f->ob_refcnt);
+ printf("Refcnt4: %zd\\n", f->ob_refcnt);
printf("COMPARE: %i\\n", f == g);
fflush(stdout);
Py_DECREF(t);
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
@@ -161,7 +161,10 @@
module = self.import_extension('foo', [
("string_None", "METH_VARARGS",
'''
- return PyString_AsString(Py_None);
+ if (PyString_AsString(Py_None)) {
+ Py_RETURN_NONE;
+ }
+ return NULL;
'''
)])
raises(TypeError, module.string_None)
diff --git a/pypy/module/cpyext/test/test_classobject.py
b/pypy/module/cpyext/test/test_classobject.py
--- a/pypy/module/cpyext/test/test_classobject.py
+++ b/pypy/module/cpyext/test/test_classobject.py
@@ -29,7 +29,6 @@
assert space.unwrap(space.getattr(w_instance, space.wrap('x'))) == 1
assert space.unwrap(space.getattr(w_instance, space.wrap('y'))) == 2
assert space.unwrap(space.getattr(w_instance, space.wrap('args'))) ==
(3,)
-
def test_lookup(self, space, api):
w_instance = space.appexec([], """():
@@ -68,7 +67,7 @@
("get_classtype", "METH_NOARGS",
"""
Py_INCREF(&PyClass_Type);
- return &PyClass_Type;
+ return (PyObject*)&PyClass_Type;
""")])
class C: pass
assert module.get_classtype() is type(C)
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
@@ -72,8 +72,7 @@
else:
kwds["link_files"] = [str(api_library + '.so')]
if sys.platform.startswith('linux'):
- kwds["compile_extra"]=["-Werror=implicit-function-declaration",
- "-g", "-O0"]
+ kwds["compile_extra"]=["-Werror", "-g", "-O0"]
kwds["link_extra"]=["-g"]
modname = modname.split('.')[-1]
@@ -747,7 +746,7 @@
refcnt_after = true_obj->ob_refcnt;
Py_DECREF(true_obj);
Py_DECREF(true_obj);
- fprintf(stderr, "REFCNT %i %i\\n", refcnt, refcnt_after);
+ fprintf(stderr, "REFCNT %zd %zd\\n", refcnt, refcnt_after);
return PyBool_FromLong(refcnt_after == refcnt + 2);
}
static PyObject* foo_bar(PyObject* self, PyObject *args)
@@ -763,7 +762,7 @@
return NULL;
refcnt_after = true_obj->ob_refcnt;
Py_DECREF(tup);
- fprintf(stderr, "REFCNT2 %i %i %i\\n", refcnt, refcnt_after,
+ fprintf(stderr, "REFCNT2 %zd %zd %zd\\n", refcnt, refcnt_after,
true_obj->ob_refcnt);
return PyBool_FromLong(refcnt_after == refcnt + 1 &&
refcnt == true_obj->ob_refcnt);
diff --git a/pypy/module/cpyext/test/test_longobject.py
b/pypy/module/cpyext/test/test_longobject.py
--- a/pypy/module/cpyext/test/test_longobject.py
+++ b/pypy/module/cpyext/test/test_longobject.py
@@ -171,7 +171,7 @@
int little_endian, is_signed;
if (!PyArg_ParseTuple(args, "ii", &little_endian, &is_signed))
return NULL;
- return _PyLong_FromByteArray("\x9A\xBC", 2,
+ return _PyLong_FromByteArray((unsigned char*)"\x9A\xBC", 2,
little_endian, is_signed);
"""),
])
@@ -187,7 +187,7 @@
int little_endian, is_signed;
if (!PyArg_ParseTuple(args, "ii", &little_endian, &is_signed))
return NULL;
- return _PyLong_FromByteArray("\x9A\xBC\x41", 3,
+ return _PyLong_FromByteArray((unsigned char*)"\x9A\xBC\x41",
3,
little_endian, is_signed);
"""),
])
diff --git a/pypy/module/cpyext/test/test_pyerrors.py
b/pypy/module/cpyext/test/test_pyerrors.py
--- a/pypy/module/cpyext/test/test_pyerrors.py
+++ b/pypy/module/cpyext/test/test_pyerrors.py
@@ -168,14 +168,14 @@
PyErr_NormalizeException(&type, &val, &tb);
if (type != PyExc_TypeError)
Py_RETURN_FALSE;
- if (val->ob_type != PyExc_TypeError)
+ if ((PyObject*)Py_TYPE(val) != PyExc_TypeError)
Py_RETURN_FALSE;
/* Normalize again */
PyErr_NormalizeException(&type, &val, &tb);
if (type != PyExc_TypeError)
Py_RETURN_FALSE;
- if (val->ob_type != PyExc_TypeError)
+ if ((PyObject*)Py_TYPE(val) != PyExc_TypeError)
Py_RETURN_FALSE;
PyErr_Restore(type, val, tb);
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
@@ -437,14 +437,14 @@
("test_tp_getattro", "METH_VARARGS",
'''
PyObject *name, *obj = PyTuple_GET_ITEM(args, 0);
- PyIntObject *attr, *value = PyTuple_GET_ITEM(args, 1);
+ PyIntObject *attr, *value = (PyIntObject*)
PyTuple_GET_ITEM(args, 1);
if (!obj->ob_type->tp_getattro)
{
PyErr_SetString(PyExc_ValueError, "missing tp_getattro");
return NULL;
}
name = PyString_FromString("attr1");
- attr = obj->ob_type->tp_getattro(obj, name);
+ attr = (PyIntObject*) obj->ob_type->tp_getattro(obj, name);
if (attr->ob_ival != value->ob_ival)
{
PyErr_SetString(PyExc_ValueError,
@@ -454,7 +454,7 @@
Py_DECREF(name);
Py_DECREF(attr);
name = PyString_FromString("attr2");
- attr = obj->ob_type->tp_getattro(obj, name);
+ attr = (PyIntObject*) obj->ob_type->tp_getattro(obj, name);
if (attr == NULL &&
PyErr_ExceptionMatches(PyExc_AttributeError))
{
PyErr_Clear();
@@ -758,8 +758,9 @@
} IntLikeObject;
static int
- intlike_nb_nonzero(IntLikeObject *v)
+ intlike_nb_nonzero(PyObject *o)
{
+ IntLikeObject *v = (IntLikeObject*)o;
if (v->value == -42) {
PyErr_SetNone(PyExc_ValueError);
return -1;
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit