This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl_alloc() wants zeroed memory so should use calloc()
authorNicholas Clark <nick@ccl4.org>
Fri, 17 Sep 2021 19:43:51 +0000 (19:43 +0000)
committerNicholas Clark <nick@ccl4.org>
Tue, 28 Sep 2021 06:12:27 +0000 (06:12 +0000)
The previous code

1) allocated memory with PerlMem_malloc()
2) passed the pointer to S_init_tls_and_interp()
3) called Zero() or ZeroD()
4) optionally invoked INIT_TRACK_MEMPOOL()
5) returned the pointer

ZeroD() and Zero() are equivalent, apart from the return value of the
expression.

The layers of functions and macros obscured what what was actually
happening, and what the ordering dependencies are:

* S_init_tls_and_interp() uses only the address of the pointer
* Zero() zeros the memory
* Only INIT_TRACK_MEMPOOL() touches the contents
* all the "memory wrap" macros inside the other macros can't "trigger"

Hence the order of Zero() and S_init_tls_and_interp() can be swapped,
at which point Zero() immediately follows malloc(), meaning that the two
should be be replaced with calloc().

This simplifies the function considerably.


No differences found