Amaury Forgeot d'Arc  committed 152c8a8

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)

  • Participants
  • Parent commits 2027437
  • Branches cpyext-int

Comments (0)

Files changed (2)

File pypy/module/cpyext/

     "Type description of PyIntObject"
+                   attach=int_attach,
+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))
     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)
 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.
         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
     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

File pypy/module/cpyext/test/

                 #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);
                 return val;