Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b0a7873

Browse files
committed
Consistency:
"Unix" ==> "\UNIX{}" "C" ==> "\C{}" "C++" ==> "\Cpp{}"
1 parent 18f9f53 commit b0a7873

2 files changed

Lines changed: 76 additions & 76 deletions

File tree

Doc/api.tex

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
\begin{abstract}
2121

2222
\noindent
23-
This manual documents the API used by C (or C++) programmers who want
23+
This manual documents the API used by \C{} (or \Cpp{}) programmers who want
2424
to write extension modules or embed Python. It is a companion to
2525
``Extending and Embedding the Python Interpreter'', which describes
2626
the general principles of extension writing but does not document the
@@ -42,12 +42,12 @@
4242

4343
\chapter{Introduction}
4444

45-
The Application Programmer's Interface to Python gives C and C++
45+
The Application Programmer's Interface to Python gives \C{} and \Cpp{}
4646
programmers access to the Python interpreter at a variety of levels.
47-
The API is equally usable from C++, but for brevity it is generally
48-
referred to as the Python/C API. There are two fundamentally
49-
different reasons for using the Python/C API. The first reason is to
50-
write ``extension modules'' for specific purposes; these are C modules
47+
The API is equally usable from \Cpp{}, but for brevity it is generally
48+
referred to as the Python/\C{} API. There are two fundamentally
49+
different reasons for using the Python/\C{} API. The first reason is to
50+
write ``extension modules'' for specific purposes; these are \C{} modules
5151
that extend the Python interpreter. This is probably the most common
5252
use. The second reason is to use Python as a component in a larger
5353
application; this technique is generally referred to as ``embedding''
@@ -97,7 +97,7 @@ \section{Objects, Types and Reference Counts}
9797
object. Since all Python object types are treated the same way by the
9898
Python language in most situations (e.g., assignments, scope rules,
9999
and argument passing), it is only fitting that they should be
100-
represented by a single C type. All Python objects live on the heap:
100+
represented by a single \C{} type. All Python objects live on the heap:
101101
you never declare an automatic or static variable of type
102102
\code{PyObject}, only pointer variables of type \code{PyObject *} can
103103
be declared.
@@ -115,8 +115,8 @@ \subsection{Reference Counts}
115115
The reference count is important because today's computers have a
116116
finite (and often severly limited) memory size; it counts how many
117117
different places there are that have a reference to an object. Such a
118-
place could be another object, or a global (or static) C variable, or
119-
a local variable in some C function. When an object's reference count
118+
place could be another object, or a global (or static) \C{} variable, or
119+
a local variable in some \C{} function. When an object's reference count
120120
becomes zero, the object is deallocated. If it contains references to
121121
other objects, their reference count is decremented. Those other
122122
objects may be deallocated in turn, if this decrement makes their
@@ -150,7 +150,7 @@ \subsection{Reference Counts}
150150
least one other reference to the object that lives at least as long as
151151
our variable, there is no need to increment the reference count
152152
temporarily. An important situation where this arises is in objects
153-
that are passed as arguments to C functions in an extension module
153+
that are passed as arguments to \C{} functions in an extension module
154154
that are called from Python; the call mechanism guarantees to hold a
155155
reference to every argument for the duration of the call.
156156

@@ -228,7 +228,7 @@ \subsubsection{Reference Count Details}
228228
You might find it strange that the ``recommended'' approach takes more
229229
code. However, in practice, you will rarely use these ways of
230230
creating and populating a tuple or list. There's a generic function,
231-
\code{Py_BuildValue()}, that can create most common objects from C
231+
\code{Py_BuildValue()}, that can create most common objects from \C{}
232232
values, directed by a ``format string''. For example, the above two
233233
blocks of code could be replaced by the following (which also takes
234234
care of the error checking!):
@@ -328,7 +328,7 @@ \subsubsection{Reference Count Details}
328328
\subsection{Types}
329329

330330
There are few other data types that play a significant role in
331-
the Python/C API; most are simple C types such as \code{int},
331+
the Python/C API; most are simple \C{} types such as \code{int},
332332
\code{long}, \code{double} and \code{char *}. A few structure types
333333
are used to describe static tables used to list the functions exported
334334
by a module or the data attributes of a new object type. These will
@@ -342,7 +342,7 @@ \section{Exceptions}
342342
they reach the top-level interpreter, where they are reported to the
343343
user accompanied by a stack traceback.
344344

345-
For C programmers, however, error checking always has to be explicit.
345+
For \C{} programmers, however, error checking always has to be explicit.
346346
All functions in the Python/C API can raise exceptions, unless an
347347
explicit claim is made otherwise in a function's documentation. In
348348
general, when a function encounters an error, it sets an exception,
@@ -369,8 +369,8 @@ \section{Exceptions}
369369
object \code{sys.exc_type}, \code{sys.exc_value},
370370
\code{sys.exc_traceback}; however, they are not the same: the Python
371371
objects represent the last exception being handled by a Python
372-
\code{try...except} statement, while the C level exception state only
373-
exists while an exception is being passed on between C functions until
372+
\code{try...except} statement, while the \C{} level exception state only
373+
exists while an exception is being passed on between \C{} functions until
374374
it reaches the Python interpreter, which takes care of transferring it
375375
to \code{sys.exc_type} and friends.
376376

@@ -410,7 +410,7 @@ \section{Exceptions}
410410
return item + 1
411411
\end{verbatim}
412412

413-
Here is the corresponding C code, in all its glory:
413+
Here is the corresponding \C{} code, in all its glory:
414414

415415
\begin{verbatim}
416416
int incr_item(PyObject *dict, PyObject *key)
@@ -453,7 +453,7 @@ \section{Exceptions}
453453
\end{verbatim}
454454

455455
This example represents an endorsed use of the \code{goto} statement
456-
in C! It illustrates the use of \code{PyErr_ExceptionMatches()} and
456+
in \C{}! It illustrates the use of \code{PyErr_ExceptionMatches()} and
457457
\code{PyErr_Clear()} to handle specific exceptions, and the use of
458458
\code{Py_XDECREF()} to dispose of owned references that may be
459459
\NULL{} (note the `X' in the name; \code{Py_DECREF()} would crash
@@ -483,7 +483,7 @@ \section{Embedding Python}
483483
\code{PySys_SetArgv(\var{argc}, \var{argv})} subsequent to the call
484484
to \code{Py_Initialize()}.
485485

486-
On most systems (in particular, on Unix and Windows, although the
486+
On most systems (in particular, on \UNIX{} and Windows, although the
487487
details are slightly different), \code{Py_Initialize()} calculates the
488488
module search path based upon its best guess for the location of the
489489
standard Python interpreter executable, assuming that the Python
@@ -532,13 +532,13 @@ \chapter{Basic Utilities}
532532
performed. This function should only be invoked when a condition is
533533
detected that would make it dangerous to continue using the Python
534534
interpreter; e.g., when the object administration appears to be
535-
corrupted. On Unix, the standard C library function \code{abort()} is
535+
corrupted. On \UNIX{}, the standard \C{} library function \code{abort()} is
536536
called which will attempt to produce a \file{core} file.
537537
\end{cfuncdesc}
538538

539539
\begin{cfuncdesc}{void}{Py_Exit}{int status}
540540
Exit the current process. This calls \code{Py_Finalize()} and then
541-
calls the standard C library function \code{exit(0)}.
541+
calls the standard \C{} library function \code{exit(0)}.
542542
\end{cfuncdesc}
543543

544544
\begin{cfuncdesc}{int}{Py_AtExit}{void (*func) ()}
@@ -605,7 +605,7 @@ \chapter{Exception Handling}
605605

606606
The functions in this chapter will let you handle and raise Python
607607
exceptions. It is important to understand some of the basics of
608-
Python exception handling. It works somewhat like the Unix
608+
Python exception handling. It works somewhat like the \UNIX{}
609609
\code{errno} variable: there is a global indicator (per thread) of the
610610
last error that occurred. Most functions don't clear this on success,
611611
but will set it to indicate the cause of the error on failure. Most
@@ -729,8 +729,8 @@ \chapter{Exception Handling}
729729
\end{cfuncdesc}
730730

731731
\begin{cfuncdesc}{PyObject *}{PyErr_SetFromErrno}{PyObject *type}
732-
This is a convenience function to raise an exception when a C library
733-
function has returned an error and set the C variable \code{errno}.
732+
This is a convenience function to raise an exception when a \C{} library
733+
function has returned an error and set the \C{} variable \code{errno}.
734734
It constructs a tuple object whose first item is the integer
735735
\code{errno} value and whose second item is the corresponding error
736736
message (gotten from \code{strerror()}), and then calls
@@ -772,11 +772,11 @@ \chapter{Exception Handling}
772772
PyObject *base, PyObject *dict}
773773
\strong{(NEW in 1.5a4!)}
774774
This utility function creates and returns a new exception object. The
775-
\var{name} argument must be the name of the new exception, a C string
775+
\var{name} argument must be the name of the new exception, a \C{} string
776776
of the form \code{module.class}. The \var{base} and \var{dict}
777777
arguments are normally \NULL{}. Normally, this creates a class
778778
object derived from the root for all exceptions, the built-in name
779-
\code{Exception} (accessible in C as \code{PyExc_Exception}). In this
779+
\code{Exception} (accessible in \C{} as \code{PyExc_Exception}). In this
780780
case the \code{__module__} attribute of the new class is set to the
781781
first part (up to the last dot) of the \var{name} argument, and the
782782
class name is set to the last part (after the last dot). When the
@@ -825,7 +825,7 @@ \section{Standard Exceptions}
825825
\chapter{Utilities}
826826

827827
The functions in this chapter perform various utility tasks, such as
828-
parsing function arguments and constructing Python values from C
828+
parsing function arguments and constructing Python values from \C{}
829829
values.
830830

831831
\section{OS Utilities}
@@ -842,7 +842,7 @@ \section{OS Utilities}
842842
\begin{cfuncdesc}{long}{PyOS_GetLastModificationTime}{char *filename}
843843
Return the time of last modification of the file \code{filename}.
844844
The result is encoded in the same way as the timestamp returned by
845-
the standard C library function \code{time()}.
845+
the standard \C{} library function \code{time()}.
846846
\end{cfuncdesc}
847847
848848
@@ -1142,7 +1142,7 @@ \section{Object Protocol}
11421142
11431143
\begin{cfuncdesc}{PyObject*}{PyObject_CallFunction}{PyObject *callable_object, char *format, ...}
11441144
Call a callable Python object \code{callable_object}, with a
1145-
variable number of C arguments. The C arguments are described
1145+
variable number of \C{} arguments. The \C{} arguments are described
11461146
using a mkvalue-style format string. The format may be \NULL{},
11471147
indicating that no arguments are provided. Returns the
11481148
result of the call on success, or \NULL{} on failure. This is
@@ -1152,7 +1152,7 @@ \section{Object Protocol}
11521152
11531153
\begin{cfuncdesc}{PyObject*}{PyObject_CallMethod}{PyObject *o, char *m, char *format, ...}
11541154
Call the method named \code{m} of object \code{o} with a variable number of
1155-
C arguments. The C arguments are described by a mkvalue
1155+
C arguments. The \C{} arguments are described by a mkvalue
11561156
format string. The format may be \NULL{}, indicating that no
11571157
arguments are provided. Returns the result of the call on
11581158
success, or \NULL{} on failure. This is the equivalent of the
@@ -1541,12 +1541,12 @@ \section{Constructors}
15411541
\begin{cfuncdesc}{PyObject*}{PyFile_FromString}{char *file_name, char *mode}
15421542
On success, returns a new file object that is opened on the
15431543
file given by \code{file_name}, with a file mode given by \code{mode},
1544-
where \code{mode} has the same semantics as the standard C routine,
1544+
where \code{mode} has the same semantics as the standard \C{} routine,
15451545
fopen. On failure, return -1.
15461546
\end{cfuncdesc}
15471547
15481548
\begin{cfuncdesc}{PyObject*}{PyFile_FromFile}{FILE *fp, char *file_name, char *mode, int close_on_del}
1549-
Return a new file object for an already opened standard C
1549+
Return a new file object for an already opened standard \C{}
15501550
file pointer, \code{fp}. A file name, \code{file_name}, and open mode,
15511551
\code{mode}, must be provided as well as a flag, \code{close_on_del}, that
15521552
indicates whether the file is to be closed when the file
@@ -1691,7 +1691,7 @@ \chapter{Initialization, Finalization, and Threads}
16911691
also separate. The new environment has no \code{sys.argv} variable.
16921692
It has new standard I/O stream file objects \code{sys.stdin},
16931693
\code{sys.stdout} and \code{sys.stderr} (however these refer to the
1694-
same underlying \code{FILE} structures in the C library).
1694+
same underlying \code{FILE} structures in the \C{} library).
16951695
16961696
The return value points to the first thread state created in the new
16971697
sub-interpreter. This thread state is made the current thread state.
@@ -1775,7 +1775,7 @@ \chapter{Initialization, Finalization, and Threads}
17751775
corresponds to the \code{prefix} variable in the top-level
17761776
\code{Makefile} and the \code{--prefix} argument to the
17771777
\code{configure} script at build time. The value is available to
1778-
Python code as \code{sys.prefix}. It is only useful on Unix. See
1778+
Python code as \code{sys.prefix}. It is only useful on \UNIX{}. See
17791779
also the next function.
17801780
\end{cfuncdesc}
17811781
@@ -1790,7 +1790,7 @@ \chapter{Initialization, Finalization, and Threads}
17901790
\code{exec_prefix} variable in the top-level \code{Makefile} and the
17911791
\code{--exec_prefix} argument to the \code{configure} script at build
17921792
time. The value is available to Python code as
1793-
\code{sys.exec_prefix}. It is only useful on Unix.
1793+
\code{sys.exec_prefix}. It is only useful on \UNIX{}.
17941794
17951795
Background: The exec-prefix differs from the prefix when platform
17961796
dependent files (such as executables and shared libraries) are
@@ -1804,7 +1804,7 @@ \chapter{Initialization, Finalization, and Threads}
18041804
operating system are considered the same platform, but Intel machines
18051805
running Solaris 2.x are another platform, and Intel machines running
18061806
Linux are yet another platform. Different major revisions of the same
1807-
operating system generally also form different platforms. Non-Unix
1807+
operating system generally also form different platforms. Non-\UNIX{}
18081808
operating systems are a different story; the installation strategies
18091809
on those systems are so different that the prefix and exec-prefix are
18101810
meaningless, and set to the empty string. Note that compiled Python
@@ -1832,7 +1832,7 @@ \chapter{Initialization, Finalization, and Threads}
18321832
program name (set by \code{Py_SetProgramName()} above) and some
18331833
environment variables. The returned string consists of a series of
18341834
directory names separated by a platform dependent delimiter character.
1835-
The delimiter character is \code{':'} on Unix, \code{';'} on
1835+
The delimiter character is \code{':'} on \UNIX{}, \code{';'} on
18361836
DOS/Windows, and \code{'\\n'} (the ASCII newline character) on
18371837
Macintosh. The returned string points into static storage; the caller
18381838
should not modify its value. The value is available to Python code
@@ -1858,7 +1858,7 @@ \chapter{Initialization, Finalization, and Threads}
18581858
\end{cfuncdesc}
18591859
18601860
\begin{cfuncdesc}{const char *}{Py_GetPlatform}{}
1861-
Return the platform identifier for the current platform. On Unix,
1861+
Return the platform identifier for the current platform. On \UNIX{},
18621862
this is formed from the ``official'' name of the operating system,
18631863
converted to lower case, followed by the major revision number; e.g.,
18641864
for Solaris 2.x, which is also known as SunOS 5.x, the value is
@@ -2014,7 +2014,7 @@ \section{Thread State and the Global Interpreter Lock}
20142014
lock must be acquired before storing the thread state pointer.
20152015
20162016
Why am I going on with so much detail about this? Because when
2017-
threads are created from C, they don't have the global interpreter
2017+
threads are created from \C{}, they don't have the global interpreter
20182018
lock, nor is there a thread state data structure for them. Such
20192019
threads must bootstrap themselves into existence, by first creating a
20202020
thread state data structure, then acquiring the lock, and finally

0 commit comments

Comments
 (0)