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
55cdc88c
Kaydet (Commit)
55cdc88c
authored
Agu 30, 2001
tarafından
Neil Schemenauer
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Update documentation for GC API. Closes SF patch #421893.
üst
60250e28
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
29 deletions
+48
-29
api.tex
Doc/api/api.tex
+48
-29
No files found.
Doc/api/api.tex
Dosyayı görüntüle @
55cdc88c
...
@@ -5508,36 +5508,45 @@ references to atomic types (such as numbers or strings), do not need
...
@@ -5508,36 +5508,45 @@ references to atomic types (such as numbers or strings), do not need
to provide any explicit support for garbage collection.
to provide any explicit support for garbage collection.
To create a container type, the
\member
{
tp
_
flags
}
field of the type
To create a container type, the
\member
{
tp
_
flags
}
field of the type
object must include the
\constant
{
Py
_
TPFLAGS
_
GC
}
and provide an
object must include the
\constant
{
Py
_
TPFLAGS
_
HAVE
_
GC
}
and provide an
implementation of the
\member
{
tp
_
traverse
}
handler. The computed
implementation of the
\member
{
tp
_
traverse
}
handler. If instances of the
value of the
\member
{
tp
_
basicsize
}
field must include
type are mutable, a
\member
{
tp
_
clear
}
implementation must also be
\constant
{
PyGC
_
HEAD
_
SIZE
}
as well. If instances of the type are
provided.
mutable, a
\member
{
tp
_
clear
}
implementation must also be provided.
\begin{datadesc}
{
Py
_
TPFLAGS
_
GC
}
\begin{datadesc}
{
Py
_
TPFLAGS
_
HAVE
_
GC
}
Objects with a type with this flag set must conform with the rules
Objects with a type with this flag set must conform with the rules
documented here. For convenience these objects will be referred to
documented here. For convenience these objects will be referred to
as container objects.
as container objects.
\end{datadesc}
\end{datadesc}
\begin{datadesc}
{
PyGC
_
HEAD
_
SIZE
}
Extra memory needed for the garbage collector. Container objects
must include this in the calculation of their tp
_
basicsize. If the
collector is disabled at compile time then this is
\code
{
0
}
.
\end{datadesc}
Constructors for container types must conform to two rules:
Constructors for container types must conform to two rules:
\begin{enumerate}
\begin{enumerate}
\item
The memory for the object must be allocated using
\item
The memory for the object must be allocated using
\cfunction
{
PyObject
_
New()
}
or
\cfunction
{
PyObject
_
VarNew()
}
.
\cfunction
{
PyObject
_
GC
_
New()
}
or
\cfunction
{
PyObject
_
GC
_
VarNew()
}
.
\item
Once all the fields which may contain references to other
\item
Once all the fields which may contain references to other
containers are initialized, it must call
containers are initialized, it must call
\cfunction
{
PyObject
_
GC
_
Init
()
}
.
\cfunction
{
PyObject
_
GC
_
Track
()
}
.
\end{enumerate}
\end{enumerate}
\begin{cfuncdesc}
{
void
}{
PyObject
_
GC
_
Init
}{
PyObject *op
}
\begin{cfuncdesc}
{
\var
{
TYPE
}
*
}{
PyObject
_
GC
_
New
}{
TYPE, PyTypeObject *type
}
Analogous to
\cfunction
{
PyObject
_
New()
}
but for container objects with
the
\constant
{
Py
_
TPFLAGS
_
HAVE
_
GC
}
flag set.
\end{cfuncdesc}
\begin{cfuncdesc}
{
\var
{
TYPE
}
*
}{
PyObject
_
GC
_
NewVar
}{
TYPE, PyTypeObject *type,
int size
}
Analogous to
\cfunction
{
PyObject
_
NewVar()
}
but for container objects
with the
\constant
{
Py
_
TPFLAGS
_
HAVE
_
GC
}
flag set.
\end{cfuncdesc}
\begin{cfuncdesc}
{
PyVarObject *
}{
PyObject
_
GC
_
Resize
}{
PyVarObject *op, int
}
Resize an object allocated by
\cfunction
{
PyObject
_
NewVar()
}
. Returns
the resized object or
\NULL
{}
on failure.
\end{cfuncdesc}
\begin{cfuncdesc}
{
void
}{
PyObject
_
GC
_
Track
}{
PyObject *op
}
Adds the object
\var
{
op
}
to the set of container objects tracked by
Adds the object
\var
{
op
}
to the set of container objects tracked by
the collector. The collector can run at unexpected times so objects
the collector. The collector can run at unexpected times so objects
must be valid while being tracked. This should be called once all
must be valid while being tracked. This should be called once all
...
@@ -5545,29 +5554,39 @@ Constructors for container types must conform to two rules:
...
@@ -5545,29 +5554,39 @@ Constructors for container types must conform to two rules:
usually near the end of the constructor.
usually near the end of the constructor.
\end{cfuncdesc}
\end{cfuncdesc}
\begin{cfuncdesc}
{
void
}{_
PyObject
_
GC
_
TRACK
}{
PyObject *op
}
A macro version of
\cfunction
{
PyObject
_
GC
_
Track()
}
. It should not be
used for extension modules.
\end{cfuncdesc}
Similarly, the deallocator for the object must conform to a similar
Similarly, the deallocator for the object must conform to a similar
pair of rules:
pair of rules:
\begin{enumerate}
\begin{enumerate}
\item
Before fields which refer to other containers are invalidated,
\item
Before fields which refer to other containers are invalidated,
\cfunction
{
PyObject
_
GC
_
Fini
()
}
must be called.
\cfunction
{
PyObject
_
GC
_
UnTrack
()
}
must be called.
\item
The object's memory must be deallocated using
\item
The object's memory must be deallocated using
\cfunction
{
PyObject
_
Del()
}
.
\cfunction
{
PyObject
_
GC
_
Del()
}
.
\end{enumerate}
\end{enumerate}
\begin{cfuncdesc}
{
void
}{
PyObject
_
GC
_
Fini
}{
PyObject *op
}
\begin{cfuncdesc}
{
void
}{
PyObject
_
GC
_
Del
}{
PyObject *op
}
Releases memory allocated to an object using
\cfunction
{
PyObject
_
GC
_
New()
}
or
\cfunction
{
PyObject
_
GC
_
NewVar()
}
.
\end{cfuncdesc}
\begin{cfuncdesc}
{
void
}{
PyObject
_
GC
_
UnTrack
}{
PyObject *op
}
Remove the object
\var
{
op
}
from the set of container objects tracked
Remove the object
\var
{
op
}
from the set of container objects tracked
by the collector. Note that
\cfunction
{
PyObject
_
GC
_
Init
()
}
can be
by the collector. Note that
\cfunction
{
PyObject
_
GC
_
Track
()
}
can be
called again on this object to add it back to the set of tracked
called again on this object to add it back to the set of tracked
objects. The deallocator (
\member
{
tp
_
dealloc
}
handler) should call
objects. The deallocator (
\member
{
tp
_
dealloc
}
handler) should call
this for the object before any of the fields used by the
this for the object before any of the fields used by the
\member
{
tp
_
traverse
}
handler become invalid.
\member
{
tp
_
traverse
}
handler become invalid.
\end{cfuncdesc}
\strong
{
Note:
}
Any container which may be referenced from another
\begin{cfuncdesc}
{
void
}{_
PyObject
_
GC
_
UNTRACK
}{
PyObject *op
}
object reachable by the collector must itself be tracked by the
A macro version of
\cfunction
{
PyObject
_
GC
_
UnTrack()
}
. It should not be
collector, so it is generally not safe to call this function
used for extension modules.
anywhere but in the object's deallocator.
\end{cfuncdesc}
\end{cfuncdesc}
The
\member
{
tp
_
traverse
}
handler accepts a function parameter of this
The
\member
{
tp
_
traverse
}
handler accepts a function parameter of this
...
@@ -5650,9 +5669,9 @@ my_clear(MyObject *self)
...
@@ -5650,9 +5669,9 @@ my_clear(MyObject *self)
static void
static void
my
_
dealloc(MyObject *self)
my
_
dealloc(MyObject *self)
{
{
PyObject
_
GC
_
Fini
((PyObject *) self);
PyObject
_
GC
_
UnTrack
((PyObject *) self);
Py
_
XDECREF(self->container);
Py
_
XDECREF(self->container);
PyObject
_
Del(self);
PyObject
_
GC
_
Del(self);
}
}
\end{verbatim}
\end{verbatim}
...
@@ -5662,7 +5681,7 @@ MyObject_Type = {
...
@@ -5662,7 +5681,7 @@ MyObject_Type = {
PyObject
_
HEAD
_
INIT(NULL)
PyObject
_
HEAD
_
INIT(NULL)
0,
0,
"MyObject",
"MyObject",
sizeof(MyObject)
+ PyGC
_
HEAD
_
SIZE
,
sizeof(MyObject),
0,
0,
(destructor)my
_
dealloc, /* tp
_
dealloc */
(destructor)my
_
dealloc, /* tp
_
dealloc */
0, /* tp
_
print */
0, /* tp
_
print */
...
@@ -5679,7 +5698,7 @@ MyObject_Type = {
...
@@ -5679,7 +5698,7 @@ MyObject_Type = {
0, /* tp
_
getattro */
0, /* tp
_
getattro */
0, /* tp
_
setattro */
0, /* tp
_
setattro */
0, /* tp
_
as
_
buffer */
0, /* tp
_
as
_
buffer */
Py
_
TPFLAGS
_
DEFAULT | Py
_
TPFLAGS
_
GC,
Py
_
TPFLAGS
_
DEFAULT | Py
_
TPFLAGS
_
HAVE
_
GC,
0, /* tp
_
doc */
0, /* tp
_
doc */
(traverseproc)my
_
traverse, /* tp
_
traverse */
(traverseproc)my
_
traverse, /* tp
_
traverse */
(inquiry)my
_
clear, /* tp
_
clear */
(inquiry)my
_
clear, /* tp
_
clear */
...
@@ -5695,10 +5714,10 @@ new_object(PyObject *unused, PyObject *args)
...
@@ -5695,10 +5714,10 @@ new_object(PyObject *unused, PyObject *args)
MyObject *result = NULL;
MyObject *result = NULL;
if (PyArg
_
ParseTuple(args, "|O:new
_
object",
&
container))
{
if (PyArg
_
ParseTuple(args, "|O:new
_
object",
&
container))
{
result = PyObject
_
New(MyObject,
&
MyObject
_
Type);
result = PyObject
_
GC
_
New(MyObject,
&
MyObject
_
Type);
if (result != NULL)
{
if (result != NULL)
{
result->container = container;
result->container = container;
PyObject
_
GC
_
Init(
);
PyObject
_
GC
_
Track(result
);
}
}
}
}
return (PyObject *) result;
return (PyObject *) result;
...
...
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