Author: Amaury Forgeot d'Arc <[email protected]>
Branch: cpyext-int
Changeset: r67469:152c8a84b76d
Date: 2013-10-18 01:19 +0200
http://bitbucket.org/pypy/pypy/changeset/152c8a84b76d/
Log: Fix tests around PyIntObject:
- Revert the changes made to signature, to match CPython again.
- Fix the test
- Really fill the PyIntObject::ob_ival member (with an "attach"
descriptor)
diff --git a/pypy/module/cpyext/intobject.py b/pypy/module/cpyext/intobject.py
--- a/pypy/module/cpyext/intobject.py
+++ b/pypy/module/cpyext/intobject.py
@@ -21,8 +21,17 @@
"Type description of PyIntObject"
make_typedescr(space.w_int.instancetypedef,
basestruct=PyIntObject.TO,
+ attach=int_attach,
realize=int_realize)
+def int_attach(space, py_obj, w_obj):
+ """
+ Fills a newly allocated PyIntObject with the given int object. The
+ value must not be modified.
+ """
+ py_int = rffi.cast(PyIntObject, py_obj)
+ py_int.c_ob_ival = space.int_w(w_obj)
+
def int_realize(space, obj):
intval = rffi.cast(lltype.Signed, rffi.cast(PyIntObject, obj).c_ob_ival)
w_type = from_ref(space, rffi.cast(PyObject, obj.c_ob_type))
@@ -41,10 +50,10 @@
as defined in the system header files)."""
return sys.maxint
-@cpython_api([lltype.Signed], PyIntObject)
+@cpython_api([lltype.Signed], PyObject)
def PyInt_FromLong(space, ival):
"""Create a new integer object with a value of ival.
-
+
"""
return space.wrap(ival)
@@ -117,7 +126,7 @@
LONG_MAX = int(LONG_TEST - 1)
-@cpython_api([rffi.SIZE_T], PyIntObject)
+@cpython_api([rffi.SIZE_T], PyObject)
def PyInt_FromSize_t(space, ival):
"""Create a new integer object with a value of ival. If the value exceeds
LONG_MAX, a long integer object is returned.
@@ -126,7 +135,7 @@
return space.wrap(intmask(ival))
return space.wrap(ival)
-@cpython_api([Py_ssize_t], PyIntObject)
+@cpython_api([Py_ssize_t], PyObject)
def PyInt_FromSsize_t(space, ival):
"""Create a new integer object with a value of ival. If the value is larger
than LONG_MAX or smaller than LONG_MIN, a long integer object is
@@ -134,7 +143,7 @@
"""
return space.wrap(ival)
-@cpython_api([CONST_STRING, rffi.CCHARPP, rffi.INT_real], PyIntObject)
+@cpython_api([CONST_STRING, rffi.CCHARPP, rffi.INT_real], PyObject)
def PyInt_FromString(space, str, pend, base):
"""Return a new PyIntObject or PyLongObject based on the string
value in str, which is interpreted according to the radix in base. If
diff --git a/pypy/module/cpyext/test/test_ndarrayobject.py
b/pypy/module/cpyext/test/test_ndarrayobject.py
--- a/pypy/module/cpyext/test/test_ndarrayobject.py
+++ b/pypy/module/cpyext/test/test_ndarrayobject.py
@@ -292,10 +292,13 @@
#prove it works for ints
("test_int", "METH_NOARGS",
"""
- PyIntObject * obj = PyInt_FromLong(42);
- if ( PyInt_Check(obj))
- return obj;
- PyObject * val = PyInt_FromLong(obj->ob_ival);
+ PyObject * obj = PyInt_FromLong(42);
+ if (!PyInt_Check(obj)) {
+ Py_DECREF(obj);
+ PyErr_SetNone(PyExc_ValueError);
+ return NULL;
+ }
+ PyObject * val = PyInt_FromLong(((PyIntObject *)obj)->ob_ival);
Py_DECREF(obj);
return val;
"""
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit