Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
19633fac
Commit
19633fac
authored
Apr 09, 2002
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Started filling in the information about some of the basic types and macros
used to define Python objects.
parent
93dc45cf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
2 deletions
+69
-2
Doc/api/newtypes.tex
Doc/api/newtypes.tex
+69
-2
No files found.
Doc/api/newtypes.tex
View file @
19633fac
...
...
@@ -122,9 +122,71 @@ DL_IMPORT
\section
{
Common Object Structures
\label
{
common-structs
}}
PyObject, PyVarObject
There are a large number of structures which are used in the
definition of object types for Python. This section describes these
structures and how they are used.
All Python objects ultimately share a small number of fields at the
beginning of the object's representation in memory. These are
represented by the
\ctype
{
PyObject
}
and
\ctype
{
PyVarObject
}
types,
which are defined, in turn, by the expansions of some macros also
used, whether directly or indirectly, in the definition of all other
Python objects.
\begin{ctypedesc}
{
PyObject
}
All object types are extensions of this type. This is a type which
contains the information Python needs to treat a pointer to an
object as an object. In a normal ``release'' build, it contains
only the objects reference count and a pointer to the corresponding
type object. It corresponds to the fields defined by the
expansion of the
\code
{
PyObject
_
VAR
_
HEAD
}
macro.
\end{ctypedesc}
\begin{ctypedesc}
{
PyVarObject
}
This is an extension of
\ctype
{
PyObject
}
that adds the
\member
{
ob
_
size
}
field. This is only used for objects that have
some notion of
\emph
{
length
}
. This type does not often appear in
the Python/C API. It corresponds to the fields defined by the
expansion of the
\code
{
PyObject
_
VAR
_
HEAD
}
macro.
\end{ctypedesc}
PyObject
_
HEAD, PyObject
_
HEAD
_
INIT, PyObject
_
VAR
_
HEAD
These macros are used in the definition of
\ctype
{
PyObject
}
and
\ctype
{
PyVarObject
}
:
\begin{csimplemacrodesc}
{
PyObject
_
HEAD
}
This is a macro which expands to the declarations of the fields of
the
\ctype
{
PyObject
}
type; it is used when declaring new types which
represent objects without a varying length. The specific fields it
expands to depends on the definition of
\csimplemacro
{
Py
_
TRACE
_
REFS
}
. By default, that macro is not
defined, and
\csimplemacro
{
PyObject
_
HEAD
}
expands to:
\begin{verbatim}
int ob
_
refcnt;
PyTypeObject *ob
_
type;
\end{verbatim}
When
\csimplemacro
{
Py
_
TRACE
_
REFS
}
is defined, it expands to:
\begin{verbatim}
PyObject *
_
ob
_
next, *
_
ob
_
prev;
int ob
_
refcnt;
PyTypeObject *ob
_
type;
\end{verbatim}
\end{csimplemacrodesc}
\begin{csimplemacrodesc}
{
PyObject
_
VAR
_
HEAD
}
This is a macro which expands to the declarations of the fields of
the
\ctype
{
PyVarObject
}
type; it is used when declaring new types which
represent objects with a length that varies from instance to
instance. This macro always expands to:
\begin{verbatim}
PyObject
_
HEAD
int ob
_
size;
\end{verbatim}
Note that
\csimplemacro
{
PyObject
_
HEAD
}
is part of the expansion, and
that it's own expansion varies depending on the definition of
\csimplemacro
{
Py
_
TRACE
_
REFS
}
.
\end{csimplemacrodesc}
PyObject
_
HEAD
_
INIT
Typedefs:
unaryfunc, binaryfunc, ternaryfunc, inquiry, coercion, intargfunc,
...
...
@@ -134,6 +196,11 @@ setattrofunc, cmpfunc, reprfunc, hashfunc
\begin{ctypedesc}
{
PyCFunction
}
Type of the functions used to implement most Python callables in C.
Functions of this type take two
\ctype
{
PyObject*
}
parameters and
return one such value. If the return value is
\NULL
, an exception
shall have been set. If not
\NULL
, the return value is interpreted
as the return value of the function as exposed in Python. The
function must return a new reference.
\end{ctypedesc}
\begin{ctypedesc}
{
PyMethodDef
}
...
...
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