11.. highlight :: c
22
33
4+ .. _first-extension-module :
5+
46*********************************
57Your first C API extension module
68*********************************
79
810This tutorial will take you, line by line, through creating a simple
911Python 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 .
1315See :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.
2324It 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
344346Now, let's fit all the pieces of our module together.
345347
@@ -349,15 +351,19 @@ an array of :c:type:`PyModuleDef_Slot` structures.
349351Like with the method table, a zero-filled *sentinel * marks the end.
350352
351353Besides 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.
361367The hook must be named :c:func: `!PyModExport_name `, where *name * is the name
362368of the module, and it should be the only non-\ ``static `` item defined in the
363369module file.
0 commit comments