Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
bd9d5132
Kaydet (Commit)
bd9d5132
authored
Mar 21, 2007
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Patch #1684834: document some utility C API functions.
(backport from rev. 54483)
üst
8a10ea46
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
0 deletions
+91
-0
utilities.tex
Doc/api/utilities.tex
+91
-0
No files found.
Doc/api/utilities.tex
Dosyayı görüntüle @
bd9d5132
...
...
@@ -930,3 +930,94 @@ PyArg_ParseTuple(args, "O|O:ref", &object, &callback)
If there is an error in the format string, the
\exception
{
SystemError
}
exception is set and
\NULL
{}
returned.
\end{cfuncdesc}
\section
{
String conversion and formatting
\label
{
string-formatting
}}
Functions for number conversion and formatted string output.
\begin{cfuncdesc}
{
int
}{
PyOS
_
snprintf
}{
char *str, size
_
t size,
const char *format,
\moreargs
}
Output not more than
\var
{
size
}
bytes to
\var
{
str
}
according to the format
string
\var
{
format
}
and the extra arguments. See the
\UNIX
{}
man
page
\manpage
{
snprintf
}{
2
}
.
\end{cfuncdesc}
\begin{cfuncdesc}
{
int
}{
PyOS
_
vsnprintf
}{
char *str, size
_
t size,
const char *format, va
_
list va
}
Output not more than
\var
{
size
}
bytes to
\var
{
str
}
according to the format
string
\var
{
format
}
and the variable argument list
\var
{
va
}
.
\UNIX
{}
man page
\manpage
{
vsnprintf
}{
2
}
.
\end{cfuncdesc}
\cfunction
{
PyOS
_
snprintf
}
and
\cfunction
{
PyOS
_
vsnprintf
}
wrap the
Standard C library functions
\cfunction
{
snprintf()
}
and
\cfunction
{
vsnprintf()
}
. Their purpose is to guarantee consistent
behavior in corner cases, which the Standard C functions do not.
The wrappers ensure that
\var
{
str
}
[
\var
{
size
}
-1] is always
\character
{
\textbackslash
0
}
upon return. They never write more than
\var
{
size
}
bytes (including the trailing
\character
{
\textbackslash
0
}
into str. Both functions require that
\code
{
\var
{
str
}
!= NULL
}
,
\code
{
\var
{
size
}
> 0
}
and
\code
{
\var
{
format
}
!= NULL
}
.
If the platform doesn't have
\cfunction
{
vsnprintf()
}
and the buffer
size needed to avoid truncation exceeds
\var
{
size
}
by more than 512
bytes, Python aborts with a
\var
{
Py
_
FatalError
}
.
The return value (
\var
{
rv
}
) for these functions should be interpreted
as follows:
\begin{itemize}
\item
When
\code
{
0 <=
\var
{
rv
}
<
\var
{
size
}}
, the output conversion
was successful and
\var
{
rv
}
characters were written to
\var
{
str
}
(excluding the trailing
\character
{
\textbackslash
0
}
byte at
\var
{
str
}
[
\var
{
rv
}
]).
\item
When
\code
{
\var
{
rv
}
>=
\var
{
size
}}
, the output conversion was
truncated and a buffer with
\code
{
\var
{
rv
}
+ 1
}
bytes would have
been needed to succeed.
\var
{
str
}
[
\var
{
size
}
-1] is
\character
{
\textbackslash
0
}
in this case.
\item
When
\code
{
\var
{
rv
}
< 0
}
, ``something bad happened.''
\var
{
str
}
[
\var
{
size
}
-1] is
\character
{
\textbackslash
0
}
in this case
too, but the rest of
\var
{
str
}
is undefined. The exact cause of the
error depends on the underlying platform.
\end{itemize}
The following functions provide locale-independent string to number
conversions.
\begin{cfuncdesc}
{
double
}{
PyOS
_
ascii
_
strtod
}{
const char *nptr, char **endptr
}
Convert a string to a
\ctype
{
double
}
. This function behaves like the
Standard C function
\cfunction
{
strtod()
}
does in the C locale. It does
this without changing the current locale, since that would not be
thread-safe.
\cfunction
{
PyOS
_
ascii
_
strtod
}
should typically be used for reading
configuration files or other non-user input that should be locale
independent.
\versionadded
{
2.4
}
See the
\UNIX
{}
man page
\manpage
{
strtod
}{
2
}
for details.
\end{cfuncdesc}
\begin{cfuncdesc}
{
char *
}{
PyOS
_
ascii
_
formatd
}{
char *buffer, size
_
t buf
_
len,
const char *format, double d
}
Convert a
\ctype
{
double
}
to a string using the
\character
{
.
}
as the
decimal separator.
\var
{
format
}
is a
\cfunction
{
printf()
}
-style format
string specifying the number format. Allowed conversion characters are
\character
{
e
}
,
\character
{
E
}
,
\character
{
f
}
,
\character
{
F
}
,
\character
{
g
}
and
\character
{
G
}
.
The return value is a pointer to
\var
{
buffer
}
with the converted
string or NULL if the conversion failed.
\versionadded
{
2.4
}
\end{cfuncdesc}
\begin{cfuncdesc}
{
double
}{
PyOS
_
ascii
_
atof
}{
const char *nptr
}
Convert a string to a
\ctype
{
double
}
in a locale-independent
way.
\versionadded
{
2.4
}
See the
\UNIX
{}
man page
\manpage
{
atof
}{
2
}
for details.
\end{cfuncdesc}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment