Commit 0f9a34da authored by Fred Drake's avatar Fred Drake

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

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