Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(40589)

#21233: Add *Calloc functions to CPython memory allocation API

Can't Edit
Can't Publish+Mail
Start Review
Created:
5 years, 5 months ago by njs
Modified:
5 years, 4 months ago
Reviewers:
stefan-usenet, shadowranger+python, victor.stinner, cf.natali
CC:
AntoinePitrou, haypo, njs, skrah, Charles-François Natali, devnull_psf.upfronthosting.co.za, jtaylor, Josh.R
Visibility:
Public.

Patch Set 1 #

Patch Set 2 #

Total comments: 4

Patch Set 3 #

Patch Set 4 #

Total comments: 8

Patch Set 5 #

Patch Set 6 #

Total comments: 4

Patch Set 7 #

Unified diffs Side-by-side diffs Delta from patch set Stats Patch
Doc/c-api/memory.rst View 1 2 3 4 5 6 5 chunks +32 lines, -4 lines 0 comments Download
Include/objimpl.h View 1 2 3 4 5 6 2 chunks +3 lines, -1 line 0 comments Download
Include/pymem.h View 1 2 3 4 5 6 3 chunks +5 lines, -0 lines 0 comments Download
Modules/gcmodule.c View 1 2 3 4 5 6 2 chunks +20 lines, -4 lines 0 comments Download
Modules/_testcapimodule.c View 1 2 3 4 5 6 7 chunks +68 lines, -5 lines 0 comments Download
Modules/_tracemalloc.c View 1 2 3 4 5 6 9 chunks +47 lines, -10 lines 0 comments Download
Objects/bytearrayobject.c View 1 2 3 4 5 6 1 chunk +14 lines, -2 lines 0 comments Download
Objects/bytesobject.c View 1 2 3 4 5 6 5 chunks +47 lines, -29 lines 0 comments Download
Objects/obmalloc.c View 1 2 3 4 5 6 26 chunks +109 lines, -17 lines 0 comments Download

Messages

Total messages: 9
stefan-usenet_bytereef.org
Even more technically, setting ints with memset is also UB, but I guess we're already ...
5 years, 5 months ago #1
Josh.R
http://bugs.python.org/review/21233/diff/11630/Objects/obmalloc.c File Objects/obmalloc.c (right): http://bugs.python.org/review/21233/diff/11630/Objects/obmalloc.c#newcode249 Objects/obmalloc.c:249: memset(allocator, 0, sizeof(*allocator)); On 2014/04/16 11:49:44, skrah wrote: > ...
5 years, 5 months ago #2
victor.stinner_gmail.com
http://bugs.python.org/review/21233/diff/11630/Objects/obmalloc.c File Objects/obmalloc.c (right): http://bugs.python.org/review/21233/diff/11630/Objects/obmalloc.c#newcode249 Objects/obmalloc.c:249: memset(allocator, 0, sizeof(*allocator)); On 2014/04/16 11:49:44, skrah wrote: > ...
5 years, 5 months ago #3
stefan-usenet_bytereef.org
> Can you elaborate? Why would it be undefined? It sets all fields to NULL. ...
5 years, 5 months ago #4
stefan-usenet_bytereef.org
You're right, memset() is used for initializing pointers in structs to NULL in other places ...
5 years, 5 months ago #5
Charles-François Natali
http://bugs.python.org/review/21233/diff/11731/Modules/_tracemalloc.c File Modules/_tracemalloc.c (right): http://bugs.python.org/review/21233/diff/11731/Modules/_tracemalloc.c#newcode479 Modules/_tracemalloc.c:479: tracemalloc_alloc(void *ctx, size_t nelem, size_t elsize, int zero) Instead ...
5 years, 4 months ago #6
stefan-usenet_bytereef.org
http://bugs.python.org/review/21233/diff/11738/Objects/obmalloc.c File Objects/obmalloc.c (right): http://bugs.python.org/review/21233/diff/11738/Objects/obmalloc.c#newcode1373 Objects/obmalloc.c:1373: result = PyMem_RawMalloc(elsize); Are nelem and elsize switched here? ...
5 years, 4 months ago #7
victor.stinner_gmail.com
http://bugs.python.org/review/21233/diff/11731/Modules/_tracemalloc.c File Modules/_tracemalloc.c (right): http://bugs.python.org/review/21233/diff/11731/Modules/_tracemalloc.c#newcode479 Modules/_tracemalloc.c:479: tracemalloc_alloc(void *ctx, size_t nelem, size_t elsize, int zero) IMO ...
5 years, 4 months ago #8
victor.stinner_gmail.com
5 years, 4 months ago #9
http://bugs.python.org/review/21233/diff/11738/Objects/obmalloc.c
File Objects/obmalloc.c (right):

http://bugs.python.org/review/21233/diff/11738/Objects/obmalloc.c#newcode1373
Objects/obmalloc.c:1373: result = PyMem_RawMalloc(elsize);
On 2014/04/28 12:34:18, skrah wrote:
> Are nelem and elsize switched here?

The caller is _PyObject_Malloc(ctx, size) which calls PyObject_Alloc(ctx, 1,
size, 1). So nelem can be ignored (but it is checked by the assertion).

Or maybe I didn't understand your comment.

http://bugs.python.org/review/21233/diff/11738/Objects/obmalloc.c#newcode1636
Objects/obmalloc.c:1636: return _PyObject_Alloc(ctx, 1, nbytes, 0);
On 2014/04/28 12:34:18, skrah wrote:
> nbytes are in the position of elsize (also in other places).

Yes. Is it a problem?
Sign in to reply to this message.

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+