mirror of
https://github.com/python/cpython.git
synced 2024-12-01 05:45:40 +08:00
Replace all remaining occurrences of PyInt_.
This commit is contained in:
parent
0aa93cda79
commit
d019fe295e
@ -374,15 +374,6 @@ All integers are implemented as "long" integer objects of arbitrary size.
|
||||
:cfunc:`PyLong_FromVoidPtr`.
|
||||
|
||||
|
||||
.. XXX name?
|
||||
.. cfunction:: long PyInt_GetMax()
|
||||
|
||||
.. index:: single: LONG_MAX
|
||||
|
||||
Return the system's idea of the largest integer it can handle
|
||||
(:const:`LONG_MAX`, as defined in the system header files).
|
||||
|
||||
|
||||
.. _floatobjects:
|
||||
|
||||
Floating Point Objects
|
||||
@ -2275,8 +2266,11 @@ Dictionary Objects
|
||||
Py_ssize_t pos = 0;
|
||||
|
||||
while (PyDict_Next(self->dict, &pos, &key, &value)) {
|
||||
int i = PyInt_AS_LONG(value) + 1;
|
||||
PyObject *o = PyInt_FromLong(i);
|
||||
long i = PyLong_AsLong(value);
|
||||
if (i == -1 && PyErr_Occurred()) {
|
||||
return -1;
|
||||
}
|
||||
PyObject *o = PyLong_FromLong(i + 1);
|
||||
if (o == NULL)
|
||||
return -1;
|
||||
if (PyDict_SetItem(self->dict, key, o) < 0) {
|
||||
|
@ -208,11 +208,11 @@ error handling for the moment; a better way to code this is shown below)::
|
||||
PyObject *t;
|
||||
|
||||
t = PyTuple_New(3);
|
||||
PyTuple_SetItem(t, 0, PyInt_FromLong(1L));
|
||||
PyTuple_SetItem(t, 1, PyInt_FromLong(2L));
|
||||
PyTuple_SetItem(t, 0, PyLong_FromLong(1L));
|
||||
PyTuple_SetItem(t, 1, PyLong_FromLong(2L));
|
||||
PyTuple_SetItem(t, 2, PyString_FromString("three"));
|
||||
|
||||
Here, :cfunc:`PyInt_FromLong` returns a new reference which is immediately
|
||||
Here, :cfunc:`PyLong_FromLong` returns a new reference which is immediately
|
||||
stolen by :cfunc:`PyTuple_SetItem`. When you want to keep using an object
|
||||
although the reference to it will be stolen, use :cfunc:`Py_INCREF` to grab
|
||||
another reference before calling the reference-stealing function.
|
||||
@ -252,7 +252,7 @@ sets all items of a list (actually, any mutable sequence) to a given item::
|
||||
if (n < 0)
|
||||
return -1;
|
||||
for (i = 0; i < n; i++) {
|
||||
PyObject *index = PyInt_FromLong(i);
|
||||
PyObject *index = PyLong_FromLong(i);
|
||||
if (!index)
|
||||
return -1;
|
||||
if (PyObject_SetItem(target, index, item) < 0)
|
||||
@ -301,8 +301,8 @@ using :cfunc:`PySequence_GetItem`. ::
|
||||
return -1; /* Not a list */
|
||||
for (i = 0; i < n; i++) {
|
||||
item = PyList_GetItem(list, i); /* Can't fail */
|
||||
if (!PyInt_Check(item)) continue; /* Skip non-integers */
|
||||
total += PyInt_AsLong(item);
|
||||
if (!PyLong_Check(item)) continue; /* Skip non-integers */
|
||||
total += PyLong_AsLong(item);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
@ -324,8 +324,8 @@ using :cfunc:`PySequence_GetItem`. ::
|
||||
item = PySequence_GetItem(sequence, i);
|
||||
if (item == NULL)
|
||||
return -1; /* Not a sequence, or other failure */
|
||||
if (PyInt_Check(item))
|
||||
total += PyInt_AsLong(item);
|
||||
if (PyLong_Check(item))
|
||||
total += PyLong_AsLong(item);
|
||||
Py_DECREF(item); /* Discard reference ownership */
|
||||
}
|
||||
return total;
|
||||
@ -449,11 +449,11 @@ Here is the corresponding C code, in all its glory::
|
||||
|
||||
/* Clear the error and use zero: */
|
||||
PyErr_Clear();
|
||||
item = PyInt_FromLong(0L);
|
||||
item = PyLong_FromLong(0L);
|
||||
if (item == NULL)
|
||||
goto error;
|
||||
}
|
||||
const_one = PyInt_FromLong(1L);
|
||||
const_one = PyLong_FromLong(1L);
|
||||
if (const_one == NULL)
|
||||
goto error;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user