Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
04707c03
Kaydet (Commit)
04707c03
authored
Ock 27, 2012
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix error handling in examples of C API use.
üst
84a0fbf6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
11 deletions
+25
-11
intro.rst
Doc/c-api/intro.rst
+25
-11
No files found.
Doc/c-api/intro.rst
Dosyayı görüntüle @
04707c03
...
...
@@ -246,17 +246,19 @@ sets all items of a list (actually, any mutable sequence) to a given item::
int
set_all(PyObject *target, PyObject *item)
{
in
t i, n;
Py_ssize_
t i, n;
n = PyObject_Length(target);
if (n < 0)
return -1;
for (i = 0; i < n; i++) {
PyObject *index = PyLong_From
Long
(i);
PyObject *index = PyLong_From
Ssize_t
(i);
if (!index)
return -1;
if (PyObject_SetItem(target, index, item) < 0)
if (PyObject_SetItem(target, index, item) < 0) {
Py_DECREF(index);
return -1;
}
Py_DECREF(index);
}
return 0;
...
...
@@ -292,8 +294,8 @@ using :c:func:`PySequence_GetItem`. ::
long
sum_list(PyObject *list)
{
in
t i, n;
long total = 0;
Py_ssize_
t i, n;
long total = 0
, value
;
PyObject *item;
n = PyList_Size(list);
...
...
@@ -302,7 +304,11 @@ using :c:func:`PySequence_GetItem`. ::
for (i = 0; i < n; i++) {
item = PyList_GetItem(list, i); /* Can't fail */
if (!PyLong_Check(item)) continue; /* Skip non-integers */
total += PyLong_AsLong(item);
value = PyLong_AsLong(item);
if (value == -1 && PyErr_Occurred())
/* Integer too big to fit in a C long, bail out */
return -1;
total += value;
}
return total;
}
...
...
@@ -314,8 +320,8 @@ using :c:func:`PySequence_GetItem`. ::
long
sum_sequence(PyObject *sequence)
{
in
t i, n;
long total = 0;
Py_ssize_
t i, n;
long total = 0
, value
;
PyObject *item;
n = PySequence_Length(sequence);
if (n < 0)
...
...
@@ -324,9 +330,17 @@ using :c:func:`PySequence_GetItem`. ::
item = PySequence_GetItem(sequence, i);
if (item == NULL)
return -1; /* Not a sequence, or other failure */
if (PyLong_Check(item))
total += PyLong_AsLong(item);
Py_DECREF(item); /* Discard reference ownership */
if (PyLong_Check(item)) {
value = PyLong_AsLong(item);
Py_DECREF(item);
if (value == -1 && PyErr_Occurred())
/* Integer too big to fit in a C long, bail out */
return -1;
total += value;
}
else {
Py_DECREF(item); /* Discard reference ownership */
}
}
return total;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment