[pypy-commit] cffi sirtom67/float_complex: all but two tests in c/test_c.py:test_complex_types() pass.
sirtom67
pypy.commits at gmail.com
Sun Feb 12 20:17:28 EST 2017
Author: Tom Krauss <thomas.p.krauss at gmail.com>
Branch: sirtom67/float_complex
Changeset: r2889:82ad2ada5811
Date: 2017-02-12 19:16 -0600
http://bitbucket.org/cffi/cffi/changeset/82ad2ada5811/
Log: all but two tests in c/test_c.py:test_complex_types() pass.
1) assert repr(complex(cast(p, -0j))) == '-0j' 2) assert
complex(cast(p, '\x09')) == 9.0
I haven't looked at 2) yet but 1) is failing due to python's
behavior: the answer should be -0j, it is returning 0j instead.
The issue is in complexobject.c: complex_new, at the end where it
does this: if (cr_is_complex) { ci.real += cr.imag; } return
complex_subtype_from_doubles(type, cr.real, ci.real);
cr.imag is appropriately "-0" still, but after this statement,
ci.real is just 0. The resulting returned object is just 0j, not
-0j.
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -2842,7 +2842,10 @@
if (cd->c_type->ct_flags & CT_PRIMITIVE_COMPLEX) {
Py_complex value = read_raw_complex_data(cd->c_data, cd->c_type->ct_size);
- return PyComplex_FromCComplex(value);
+ PyObject *op = PyComplex_FromCComplex(value);
+ PyComplexObject *opc = (PyComplexObject *) op;
+ printf("%f %f\n",opc->cval.real,opc->cval.imag);
+ return op;
}
PyErr_Format(PyExc_TypeError, "complex() not supported on cdata '%s'",
cd->c_type->ct_name);
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -211,8 +211,8 @@
assert complex(cast(p, True)) == 1.0
py.test.raises(TypeError, cast, p, None)
#
- py.test.raises(cast, new_primitive_type(name), 1+2j)
- py.test.raises(cast, new_primitive_type("int"), 1+2j)
+ py.test.raises(TypeError, cast, new_primitive_type(name), 1+2j)
+ py.test.raises(TypeError, cast, new_primitive_type("int"), 1+2j)
def test_character_type():
p = new_primitive_type("char")
More information about the pypy-commit
mailing list