Added comments for more entries of the type structure in the example

type implementation.
This commit is contained in:
Fred Drake 2002-03-28 23:45:22 +00:00
parent 2ab0a10913
commit 0f9a34da2c

View File

@ -152,20 +152,20 @@ Moving on, we come to the crunch --- the type object.
\begin{verbatim}
static PyTypeObject noddy_NoddyType = {
PyObject_HEAD_INIT(NULL)
0,
"Noddy",
sizeof(noddy_NoddyObject),
0,
noddy_noddy_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /* ob_size */
"Noddy", /* tp_name */
sizeof(noddy_NoddyObject), /* tp_basicsize */
0, /* tp_itemsize */
noddy_noddy_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
};
\end{verbatim}
@ -194,7 +194,7 @@ conforming C and some compilers complain. So instead we fill in the
oppourtunity --- in \cfunction{initnoddy()}.
\begin{verbatim}
0,
0, /* ob_size */
\end{verbatim}
The \member{ob_size} field of the header is not used; it's presence in
@ -203,7 +203,7 @@ binary compatibility with extension modules compiled for older
versions of Python. Always set this field to zero.
\begin{verbatim}
"Noddy",
"Noddy", /* tp_name */
\end{verbatim}
The name of our type. This will appear in the default textual
@ -217,14 +217,14 @@ TypeError: cannot add type "Noddy" to string
\end{verbatim}
\begin{verbatim}
sizeof(noddy_NoddyObject),
sizeof(noddy_NoddyObject), /* tp_basicsize */
\end{verbatim}
This is so that Python knows how much memory to allocate when you call
\cfunction{PyObject_New}.
\begin{verbatim}
0,
0, /* tp_itemsize */
\end{verbatim}
This has to do with variable length objects like lists and strings.
@ -236,7 +236,7 @@ implement many of these, but as mentioned above you have to implement
the deallocation function.
\begin{verbatim}
noddy_noddy_dealloc, /*tp_dealloc*/
noddy_noddy_dealloc, /* tp_dealloc */
\end{verbatim}
From here, all the type methods are \NULL, so I won't go over them yet