Skip to content

Commit 72fd39f

Browse files
Apply suggestions from code review
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
1 parent 772152c commit 72fd39f

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

Doc/extending/first-extension-module.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Linux), or Windows.
3333
On other systems, you might need to adjust some details -- for example,
3434
a system command name.
3535

36-
You need to have suitable C compiler and Python development headers installed.
36+
You need to have a suitable C compiler and Python development headers installed.
3737
On Linux, headers are often in a package like ``python3-dev``
3838
or ``python3-devel``.
3939

@@ -95,7 +95,7 @@ Start with the headers
9595
======================
9696

9797
Begin by creating a directory for this tutorial, and switching to it
98-
on command line.
98+
on the command line.
9999
Then, create a file named :file:`spammodule.c` in your directory.
100100
[#why-spammodule]_
101101

@@ -254,9 +254,9 @@ The slot table
254254

255255
Rather than ``NULL``, the export hook should return the information needed to
256256
create a module.
257-
Let's with the basics: the name and docstring.
257+
Let's start with the basics: the name and docstring.
258258

259-
The information should de defined in as ``static`` array of
259+
The information should be defined in a ``static`` array of
260260
:c:type:`PyModuleDef_Slot` entries, which are essentially key-value pairs.
261261
Define this array just before your export hook:
262262

@@ -269,12 +269,12 @@ Define this array just before your export hook:
269269
};
270270
271271
For both :c:data:`Py_mod_name` and :c:data:`Py_mod_doc`, the values are C
272-
strings -- that is, NUL-terminated UTF-8 encoded byte arrays.
272+
strings -- that is, NUL-terminated, UTF-8 encoded byte arrays.
273273

274274
Note the zero-filled sentinel entry at the end.
275275
If you forget it, you'll trigger undefined behavior.
276276

277-
The array is defined as ``static`` -- not visible outside this ``.c`` file.
277+
The array is defined as ``static`` -- that is, not visible outside this ``.c`` file.
278278
This will be a common theme.
279279
CPython only needs to access the export hook; all global variables
280280
and all other functions should generally be ``static``, so that they don't
@@ -299,7 +299,7 @@ Now, recompile and try it out:
299299
>>> print(spam)
300300
<module 'spam' from '/home/encukou/dev/cpython/spam.so'>
301301
302-
You have a extension module!
302+
You have an extension module!
303303
Try ``help(spam)`` to see the docstring.
304304

305305
The next step will be adding a function.
@@ -317,7 +317,7 @@ objects to C values, and the C return value back to Python.
317317
One of the simplest ways to write glue code is a ":c:data:`METH_O`" function,
318318
which takes two Python objects and returns one.
319319
All Python objects -- regardless of the Python type -- are represented in C
320-
as pointers to the ``PyObject`` structure.
320+
as pointers to the :c:type:`PyObject` structure.
321321

322322
Add such a function above the slots array::
323323

@@ -363,7 +363,7 @@ Add this array just below the ``spam_system`` function:
363363
As with module slots, a zero-filled sentinel marks the end of the array.
364364

365365
Next, we'll add the method to the module.
366-
Add a :c:data:`Py_mod_methods` slot to your a :c:type:`PyMethodDef` array:
366+
Add a :c:data:`Py_mod_methods` slot to your :c:type:`PyMethodDef` array:
367367

368368
.. literalinclude:: ../includes/capi-extension/spammodule-01.c
369369
:start-after: /// Module slot table
@@ -408,7 +408,7 @@ Eventually this will be the exit code of a system command,
408408
but let's start with a fixed value, say, ``3``.
409409

410410
The Python C API provides a function to create a Python :py:type:`int` object
411-
from a C ``int`` values: :c:func:`PyLong_FromLong`. [#why-pylongfromlong]_
411+
from a C ``int`` value: :c:func:`PyLong_FromLong`. [#why-pylongfromlong]_
412412

413413
To call it, replace the ``Py_RETURN_NONE`` with the following 3 lines:
414414

@@ -513,7 +513,7 @@ Add an ``if`` block for this:
513513
}
514514
515515
That's it for the setup.
516-
Now, all that is left is calling C library function :c:func:`system` with
516+
Now, all that is left is calling the C library function :c:func:`system` with
517517
the ``char *`` buffer, and using its result instead of the ``3``:
518518

519519
.. code-block:: c

0 commit comments

Comments
 (0)