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
4caeff98
Kaydet (Commit)
4caeff98
authored
Şub 18, 2006
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Patch #1415507: clarify docs on reference stealing
üst
f4f4415a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
3 deletions
+13
-3
intro.tex
Doc/api/intro.tex
+13
-3
No files found.
Doc/api/intro.tex
Dosyayı görüntüle @
4caeff98
...
@@ -179,7 +179,7 @@ calling Py_DECREF on it when the reference is no longer needed.
...
@@ -179,7 +179,7 @@ calling Py_DECREF on it when the reference is no longer needed.
Ownership can also be transferred, meaning that the code that receives
Ownership can also be transferred, meaning that the code that receives
ownership of the reference then becomes responsible for eventually
ownership of the reference then becomes responsible for eventually
decref'ing it by calling
\cfunction
{
Py
_
DECREF()
}
or
decref'ing it by calling
\cfunction
{
Py
_
DECREF()
}
or
\cfunction
{
Py
_
XDECREF()
}
when it's no longer needed
--or passing on
\cfunction
{
Py
_
XDECREF()
}
when it's no longer needed
-
--or passing on
this responsibility (usually to its caller).
this responsibility (usually to its caller).
When a function passes ownership of a reference on to its caller, the
When a function passes ownership of a reference on to its caller, the
caller is said to receive a
\emph
{
new
}
reference. When no ownership
caller is said to receive a
\emph
{
new
}
reference. When no ownership
...
@@ -188,8 +188,12 @@ Nothing needs to be done for a borrowed reference.
...
@@ -188,8 +188,12 @@ Nothing needs to be done for a borrowed reference.
Conversely, when a calling function passes it a reference to an
Conversely, when a calling function passes it a reference to an
object, there are two possibilities: the function
\emph
{
steals
}
a
object, there are two possibilities: the function
\emph
{
steals
}
a
reference to the object, or it does not. Few functions steal
reference to the object, or it does not.
\emph
{
Stealing a reference
}
references; the two notable exceptions are
means that when you pass a reference to a function, that function
assumes that it now owns that reference, and you are not responsible
for it any longer.
Few functions steal references; the two notable exceptions are
\cfunction
{
PyList
_
SetItem()
}
\ttindex
{
PyList
_
SetItem()
}
and
\cfunction
{
PyList
_
SetItem()
}
\ttindex
{
PyList
_
SetItem()
}
and
\cfunction
{
PyTuple
_
SetItem()
}
\ttindex
{
PyTuple
_
SetItem()
}
, which
\cfunction
{
PyTuple
_
SetItem()
}
\ttindex
{
PyTuple
_
SetItem()
}
, which
steal a reference to the item (but not to the tuple or list into which
steal a reference to the item (but not to the tuple or list into which
...
@@ -208,6 +212,12 @@ PyTuple_SetItem(t, 1, PyInt_FromLong(2L));
...
@@ -208,6 +212,12 @@ PyTuple_SetItem(t, 1, PyInt_FromLong(2L));
PyTuple
_
SetItem(t, 2, PyString
_
FromString("three"));
PyTuple
_
SetItem(t, 2, PyString
_
FromString("three"));
\end{verbatim}
\end{verbatim}
Here,
\cfunction
{
PyInt
_
FromLong()
}
returns a new reference which is
immediately stolen by
\cfunction
{
PyTuple
_
SetItem()
}
. When you want to
keep using an object although the reference to it will be stolen,
use
\cfunction
{
Py
_
INCREF()
}
to grab another reference before calling the
reference-stealing function.
Incidentally,
\cfunction
{
PyTuple
_
SetItem()
}
is the
\emph
{
only
}
way to
Incidentally,
\cfunction
{
PyTuple
_
SetItem()
}
is the
\emph
{
only
}
way to
set tuple items;
\cfunction
{
PySequence
_
SetItem()
}
and
set tuple items;
\cfunction
{
PySequence
_
SetItem()
}
and
\cfunction
{
PyObject
_
SetItem()
}
refuse to do this since tuples are an
\cfunction
{
PyObject
_
SetItem()
}
refuse to do this since tuples are an
...
...
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