@@ -51,23 +51,17 @@ \chapter*{Front Matter\label{front}}
5151the language its wide application range.
5252
5353For a detailed description of the whole Python/C API, see the separate
54- \emph {Python/C API Reference Manual }. \strong {Note:} While that
55- manual is still in a state of flux, it is safe to say that it is much
56- more up to date than the manual you're reading currently (which has
57- been in need for an upgrade for some time now).
54+ \emph {Python/C API Reference Manual }.
5855
5956
6057\end {abstract }
6158
6259\tableofcontents
6360
6461
65- \chapter {Extending Python with C or \Cpp {} code }
62+ \chapter {Extending Python with C or \Cpp {} \label { intro } }
6663
6764
68- % \section{Introduction}
69- \label {intro }
70-
7165It is quite easy to add new built-in modules to Python, if you know
7266how to program in C. Such \dfn {extension modules} can do two things
7367that can't be done directly in Python: they can implement new built-in
@@ -753,9 +747,7 @@ \section{Format Strings for \cfunction{PyArg_ParseTuple()}
753747 long k, l;
754748 char *s;
755749 int size;
756- \end {verbatim }
757750
758- \begin {verbatim }
759751 ok = PyArg_ParseTuple(args, ""); /* No arguments */
760752 /* Python call: f() */
761753\end {verbatim }
@@ -1016,11 +1008,10 @@ \section{The \cfunction{Py_BuildValue()} Function
10161008 1, 2, 3, 4, 5, 6) (((1, 2), (3, 4)), (5, 6))
10171009\end {verbatim }
10181010
1011+
10191012\section {Reference Counts
10201013 \label {refcounts } }
10211014
1022- % \subsection{Introduction}
1023-
10241015In languages like C or \Cpp {}, the programmer is responsible for
10251016dynamic allocation and deallocation of memory on the heap. In C,
10261017this is done using the functions \cfunction {malloc()} and
@@ -1129,6 +1120,7 @@ \subsection{Reference Counting in Python
11291120and gives full owner responsibilities (i.e., the new owner must
11301121dispose of the reference properly, as well as the previous owner).
11311122
1123+
11321124\subsection {Ownership Rules
11331125 \label {ownershipRules } }
11341126
@@ -1179,6 +1171,7 @@ \subsection{Ownership Rules
11791171Python must be an owned reference --- ownership is tranferred from the
11801172function to its caller.
11811173
1174+
11821175\subsection {Thin Ice
11831176 \label {thinIce } }
11841177
@@ -1261,6 +1254,7 @@ \subsection{Thin Ice
12611254}
12621255\end {verbatim }
12631256
1257+
12641258\subsection {NULL Pointers
12651259 \label {nullPointers } }
12661260
@@ -1413,10 +1407,13 @@ \section{Providing a C API for an Extension Module
14131407\end {verbatim }
14141408
14151409In the beginning of the module, right after the line
1410+
14161411\begin {verbatim }
14171412#include "Python.h"
14181413\end {verbatim }
1414+
14191415two more lines must be added:
1416+
14201417\begin {verbatim }
14211418#define SPAM_MODULE
14221419#include "spammodule.h"
@@ -1426,6 +1423,7 @@ \section{Providing a C API for an Extension Module
14261423included in the exporting module, not a client module. Finally,
14271424the module's initialization function must take care of initializing
14281425the C API pointer array:
1426+
14291427\begin {verbatim }
14301428void
14311429initspam()
@@ -1580,15 +1578,16 @@ \chapter{Building C and \Cpp{} Extensions on \UNIX{}
15801578\end {verbatim }
15811579
15821580This is the simplest form of a module definition line. It defines a
1583- dule , \module {ExtensionClass}, which has a single source file,
1581+ module , \module {ExtensionClass}, which has a single source file,
15841582\file {ExtensionClass.c}.
15851583
1586- Here is a slightly more complex example that uses an \strong {-I}
1587- option to specify an include directory:
1584+ This slightly more complex example uses an \strong {-I} option to
1585+ specify an include directory:
15881586
15891587\begin {verbatim }
1588+ EC=/projects/ExtensionClass
15901589cPersistence cPersistence.c -I$(EC)
1591- \end {verbatim }
1590+ \end {verbatim } % $ <-- bow to font lock
15921591
15931592This example also illustrates the format for variable references.
15941593
@@ -1614,7 +1613,7 @@ \chapter{Building C and \Cpp{} Extensions on \UNIX{}
16141613# include file.
16151614EC=/projects/ExtensionClass
16161615cPersistence cPersistence.c -I$(EC)
1617- \end {verbatim }
1616+ \end {verbatim } % $ <-- bow to font lock
16181617
16191618After the \file {Setup} file has been created, \file {Makefile.pre.in}
16201619is run with the \samp {boot} target to create a make file:
@@ -1634,7 +1633,8 @@ \chapter{Building C and \Cpp{} Extensions on \UNIX{}
16341633\file {Setup} file is changed. The make file automatically rebuilds
16351634itself if the \file {Setup} file changes.
16361635
1637- \section {Building Custom Interpreters }
1636+
1637+ \section {Building Custom Interpreters \label {custom-interps } }
16381638
16391639The make file built by \file {Makefile.pre.in} can be run with the
16401640\samp {static} target to build an interpreter:
@@ -1648,7 +1648,8 @@ \section{Building Custom Interpreters}
16481648\samp {*shared*} line is omitted from the Setup file when a custom
16491649interpreter is desired.
16501650
1651- \section {Module Definition Options }
1651+
1652+ \section {Module Definition Options \label {module-defn-options } }
16521653
16531654Several compiler options are supported:
16541655
@@ -1666,13 +1667,13 @@ \section{Module Definition Options}
16661667in variable variables.
16671668
16681669Source files can include files with \file {.c}, \file {.C}, \file {.cc},
1669- and \file {.c++} extensions.
1670+ \file {.cpp}, \file {.cxx}, and \file {.c++} extensions.
16701671
1671- Other input files include files with \file {.o} or \file {.a}
1672- extensions.
1672+ Other input files include files with \file {.a}, \file {.o}, \file {.sl},
1673+ and \file {.so} extensions.
16731674
16741675
1675- \section {Example }
1676+ \section {Example \label { module-defn-example } }
16761677
16771678Here is a more complicated example from \file {Modules/Setup.in}:
16781679
@@ -1703,7 +1704,9 @@ \section{Distributing your extension modules
17031704people who do not have a source distribution of Python.
17041705
17051706Do not distribute a make file. People building your modules
1706- should use \file {Makefile.pre.in} to build their own make file.
1707+ should use \file {Makefile.pre.in} to build their own make file. A
1708+ \file {README} file included in the package should provide simple
1709+ instructions to perform the build.
17071710
17081711Work is being done to make building and installing Python extensions
17091712easier for all platforms; this work in likely to supplant the current
@@ -1724,6 +1727,7 @@ \chapter{Building C and \Cpp{} Extensions on Windows
17241727Python extensions and the \UNIX {} programming interested in producing
17251728software which can be successfully built on both \UNIX {} and Windows.
17261729
1730+
17271731\section {A Cookbook Approach \label {win-cookbook } }
17281732
17291733\sectionauthor {Neil Schemenauer}{
[email protected] }
0 commit comments