Skip to content

Commit 4c2b982

Browse files
committed
Reword more
1 parent 4d31b9a commit 4c2b982

File tree

3 files changed

+53
-41
lines changed

3 files changed

+53
-41
lines changed

Doc/extending/first-extension-module.rst

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
.. highlight:: c
22

33

4+
.. _first-extension-module:
5+
46
*********************************
57
Your first C API extension module
68
*********************************
79

810
This tutorial will take you, line by line, through creating a simple
911
Python extension module written in C or C++.
1012

11-
This document assumes basic knowledge about Python: you should be able to
12-
define functions in Python code before writing them in another language.
13+
The tutorial assumes basic knowledge about Python: you should be able to
14+
define functions in Python code before starting to write them in C.
1315
See :ref:`tutorial-index` for an introduction to Python itself.
1416

15-
It also assumes a working knowledge of the C language.
16-
We will use several concepts that a C beginner would not be expected to know,
17-
like ``static`` functions or linkage declarations, but the tutorial should
18-
be useful for anyone who can write a basic C library.
17+
The tutorial should be useful for anyone who can write a basic C library.
18+
While we will mention several concepts that a C beginner would not be expected
19+
to know, like ``static`` functions or linkage declarations, understanding these
20+
is not necessary for success.
1921

20-
As a word warning before we begin: the compilation of an extension module can
21-
be tricky, as it depends on how your system is set up, and on how your Python
22-
is installed.
22+
As a word warning before we begin: after the code is written, you will need to
23+
compile it with the right tools and settings for your system.
2324
It is generally best to use a third-party tool to handle the details.
24-
This is covered in later chapters.
25+
This is covered in later chapters, not in this tutorial.
2526

26-
The tutorial assumes that you use a Unix system (including macOS) or Windows.
27+
The tutorial assumes that you use a Unix-like system (including macOS and
28+
Linux) or Windows.
2729

2830
.. include:: ../includes/tutorial-new-api.rst
2931

@@ -338,8 +340,8 @@ This macro expands to a variable definition like
338340
``static PyABIInfo abi_info = { ... data ... };``
339341

340342

341-
The slot table and export hook
342-
==============================
343+
The slot table
344+
==============
343345

344346
Now, let's fit all the pieces of our module together.
345347

@@ -349,15 +351,19 @@ an array of :c:type:`PyModuleDef_Slot` structures.
349351
Like with the method table, a zero-filled *sentinel* marks the end.
350352

351353
Besides the method table, this "slot table" will contain the module's
352-
top-level information: the name, a docstring, and the
353-
ABI compatibility slot we defined earlier:
354+
top-level information: the name, a docstring, and the ABI compatibility
355+
information we've just defined:
354356

355357
.. literalinclude:: ../includes/capi-extension/spammodule-01.c
356358
:start-after: /// Module slot table
357359
:end-before: ///
358360

359-
This structure, in turn, must be passed to the interpreter in the module's
360-
:ref:`export hook <extension-export-hook>` function.
361+
362+
Module export hook
363+
==================
364+
365+
The :c:type:`PyModuleDef_Slot` array must be passed to the interpreter in the
366+
module's :ref:`export hook <extension-export-hook>` function.
361367
The hook must be named :c:func:`!PyModExport_name`, where *name* is the name
362368
of the module, and it should be the only non-\ ``static`` item defined in the
363369
module file.

Doc/extending/index.rst

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Extending and Embedding the Python Interpreter
55
##################################################
66

7-
This tutorial describes how to write modules in C or C++ to extend the Python
7+
This document describes how to write modules in C or C++ to extend the Python
88
interpreter with new modules. Those modules can do what Python code does --
99
define functions, object types and methods -- but also interact with native
1010
libraries or achieve better performance by avoiding the overhead of an
@@ -42,14 +42,32 @@ source file by including the header ``"Python.h"``.
4242
extension module.
4343

4444

45+
.. toctree::
46+
:maxdepth: 2
47+
:numbered:
48+
49+
first-extension-module.rst
50+
extending.rst
51+
newtypes_tutorial.rst
52+
newtypes.rst
53+
building.rst
54+
windows.rst
55+
embedding.rst
56+
57+
4558
Recommended third party tools
4659
=============================
4760

48-
This guide only covers the basic tools for creating extensions provided
61+
This document only covers the basic tools for creating extensions provided
4962
as part of this version of CPython. Some :ref:`third party tools
5063
<c-api-tools>` offer both simpler and more sophisticated approaches to creating
5164
C and C++ extensions for Python.
5265

66+
While this document is aimed at extension authors, it should also be helpful to
67+
the authors of such tools.
68+
For example, the tutorial module can serve as a simple test case for a build
69+
tool or sample expected output of a code generator.
70+
5371

5472
C API Tutorial
5573
==============
@@ -59,30 +77,22 @@ using the Python C API -- that is, using the basic tools provided
5977
as part of this version of CPython.
6078

6179

62-
.. toctree::
63-
:maxdepth: 2
64-
:numbered:
65-
66-
first-extension-module.rst
80+
#. :ref:`first-extension-module`
6781

6882

69-
Creating extensions without third party tools
70-
=============================================
83+
Guides for intermediate topics
84+
==============================
7185

7286
This section of the guide covers creating C and C++ extensions without
7387
assistance from third party tools. It is intended primarily for creators
7488
of those tools, rather than being a recommended way to create your own
7589
C extensions.
7690

77-
.. toctree::
78-
:maxdepth: 2
79-
:numbered:
80-
81-
extending.rst
82-
newtypes_tutorial.rst
83-
newtypes.rst
84-
building.rst
85-
windows.rst
91+
* :ref:`extending-intro`
92+
* :ref:`defining-new-types`
93+
* :ref:`new-types-topics`
94+
* :ref:`building`
95+
* :ref:`building-on-windows`
8696

8797
Embedding the CPython runtime in a larger application
8898
=====================================================
@@ -92,8 +102,4 @@ interpreter as the main application, it is desirable to instead embed
92102
the CPython runtime inside a larger application. This section covers
93103
some of the details involved in doing that successfully.
94104

95-
.. toctree::
96-
:maxdepth: 2
97-
:numbered:
98-
99-
embedding.rst
105+
* :ref:`embedding`

Doc/includes/capi-extension/spammodule-01.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static PyModuleDef_Slot spam_module[] = {
4242
{Py_mod_name, "spam"},
4343
{Py_mod_doc, PyDoc_STR("A wonderful module with an example function")},
4444
{Py_mod_methods, spam_methods},
45-
{0, NULL} /* Sentinel */
45+
{0, NULL}
4646
};
4747

4848

0 commit comments

Comments
 (0)