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

Skip to content

Commit 87bbdd3

Browse files
committed
Minor clarification about what's actually promised for PyMem_Malloc(0).
I probably didn't do a correct thing for the LaTeX spelling of the integer 1.
1 parent 303d05d commit 87bbdd3

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

Doc/api/memory.tex

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ \section{Overview \label{memoryOverview}}
2626

2727
It is important to understand that the management of the Python heap
2828
is performed by the interpreter itself and that the user has no
29-
control on it, even if she regularly manipulates object pointers to
29+
control over it, even if she regularly manipulates object pointers to
3030
memory blocks inside that heap. The allocation of heap space for
3131
Python objects and other internal buffers is performed on demand by
3232
the Python memory manager through the Python/C API functions listed in
@@ -79,22 +79,24 @@ \section{Overview \label{memoryOverview}}
7979

8080
\section{Memory Interface \label{memoryInterface}}
8181

82-
The following function sets, modeled after the ANSI C standard, are
83-
available for allocating and releasing memory from the Python heap:
82+
The following function sets, modeled after the ANSI C standard,
83+
but specifying behavior when requesting zero bytes,
84+
are available for allocating and releasing memory from the Python heap:
8485

8586

8687
\begin{cfuncdesc}{void*}{PyMem_Malloc}{size_t n}
8788
Allocates \var{n} bytes and returns a pointer of type \ctype{void*}
8889
to the allocated memory, or \NULL{} if the request fails.
89-
Requesting zero bytes returns a non-\NULL{} pointer.
90+
Requesting zero bytes returns a distinct non-\NULL{} pointer if
91+
possible, as if \cfunction{PyMem_Malloc(1)} had been called instead.
9092
The memory will not have been initialized in any way.
9193
\end{cfuncdesc}
9294

9395
\begin{cfuncdesc}{void*}{PyMem_Realloc}{void *p, size_t n}
9496
Resizes the memory block pointed to by \var{p} to \var{n} bytes.
9597
The contents will be unchanged to the minimum of the old and the new
9698
sizes. If \var{p} is \NULL, the call is equivalent to
97-
\cfunction{PyMem_Malloc(\var{n})}; if \var{n} is equal to zero, the
99+
\cfunction{PyMem_Malloc(\var{n})}; else if \var{n} is equal to zero, the
98100
memory block is resized but is not freed, and the returned pointer
99101
is non-\NULL. Unless \var{p} is \NULL, it must have been
100102
returned by a previous call to \cfunction{PyMem_Malloc()} or
@@ -106,7 +108,7 @@ \section{Memory Interface \label{memoryInterface}}
106108
returned by a previous call to \cfunction{PyMem_Malloc()} or
107109
\cfunction{PyMem_Realloc()}. Otherwise, or if
108110
\cfunction{PyMem_Free(p)} has been called before, undefined
109-
behaviour occurs. If \var{p} is \NULL, no operation is performed.
111+
behavior occurs. If \var{p} is \NULL, no operation is performed.
110112
\end{cfuncdesc}
111113

112114
The following type-oriented macros are provided for convenience. Note

0 commit comments

Comments
 (0)