@@ -1334,17 +1334,10 @@ \subsection{Supporting the Cycle Collector
13341334\subsection {More Suggestions }
13351335
13361336Remember that you can omit most of these functions, in which case you
1337- provide \code {0} as a value.
1338-
1339- In the \file {Objects} directory of the Python source distribution,
1340- there is a file \file {xxobject.c}, which is intended to be used as a
1341- template for the implementation of new types. One useful strategy
1342- for implementing a new type is to copy and rename this file, then
1343- read the instructions at the top of it.
1344-
1345- There are type definitions for each of the functions you must
1346- provide. They are in \file {object.h} in the Python include
1347- directory that comes with the source distribution of Python.
1337+ provide \code {0} as a value. There are type definitions for each of
1338+ the functions you must provide. They are in \file {object.h} in the
1339+ Python include directory that comes with the source distribution of
1340+ Python.
13481341
13491342In order to learn how to implement any specific method for your new
13501343datatype, do the following: Download and unpack the Python source
@@ -1353,20 +1346,13 @@ \subsection{More Suggestions}
13531346example, \code {tp_print} or \code {tp_compare}). You will find
13541347examples of the function you want to implement.
13551348
1356- When you need to verify that the type of an object is indeed the
1357- object you are implementing and if you use xxobject.c as an starting
1358- template for your implementation, then there is a macro defined for
1359- this purpose. The macro definition will look something like this:
1360-
1361- \begin {verbatim }
1362- #define is_newdatatypeobject(v) ((v)->ob_type == &Newdatatypetype)
1363- \end {verbatim }
1364-
1365- And, a sample of its use might be something like the following:
1349+ When you need to verify that an object is an instance of the type
1350+ you are implementing, use the \cfunction {PyObject_TypeCheck} function.
1351+ A sample of its use might be something like the following:
13661352
13671353\begin {verbatim }
1368- if (!is_newdatatypeobject(objp1 ) {
1369- PyErr_SetString(PyExc_TypeError, "arg #1 not a newdatatype ");
1354+ if (! PyObject_TypeCheck(some_object, &MyType ) {
1355+ PyErr_SetString(PyExc_TypeError, "arg #1 not a mything ");
13701356 return NULL;
13711357 }
13721358\end {verbatim }
0 commit comments