Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aea763b

Browse files
author
Jim Fulton
committed
Removed reference to the out-of-date (and not very useful)
Objects/xxobject.c example. Updated the discussion of type checking to refer to PyObject_TypeCheck.
1 parent ac826aa commit aea763b

1 file changed

Lines changed: 9 additions & 23 deletions

File tree

Doc/ext/newtypes.tex

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,17 +1334,10 @@ \subsection{Supporting the Cycle Collector
13341334
\subsection{More Suggestions}
13351335

13361336
Remember 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

13491342
In order to learn how to implement any specific method for your new
13501343
datatype, do the following: Download and unpack the Python source
@@ -1353,20 +1346,13 @@ \subsection{More Suggestions}
13531346
example, \code{tp_print} or \code{tp_compare}). You will find
13541347
examples 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

Comments
 (0)