Branch: refs/heads/perl_alloc_using-simplification
  Home:   https://github.com/Perl/perl5
  Commit: c3c34c10a438edbfff32a4274b1a8de4306d535c
      
https://github.com/Perl/perl5/commit/c3c34c10a438edbfff32a4274b1a8de4306d535c
  Author: Nicholas Clark <n...@ccl4.org>
  Date:   2021-09-22 (Wed, 22 Sep 2021)

  Changed paths:
    M perl.c

  Log Message:
  -----------
  perl_alloc() wants zeroed memory so should use calloc()

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.


  Commit: 7845680176b590258093de5b7c8110855b823889
      
https://github.com/Perl/perl5/commit/7845680176b590258093de5b7c8110855b823889
  Author: Nicholas Clark <n...@ccl4.org>
  Date:   2021-09-22 (Wed, 22 Sep 2021)

  Changed paths:
    M perl.c

  Log Message:
  -----------
  No need to wrap INIT_TRACK_MEMPOOL with #ifdef PERL_TRACK_MEMPOOL

`INIT_TRACK_MEMPOOL` is defined as a no-op if `PERL_TRACK_MEMPOOL` is not
defined, so no need to wrap it in `#ifdef`.

Spotted by Ilmari.


  Commit: e026325d705c76f8fd2fc2cb1c957980c01ab7fa
      
https://github.com/Perl/perl5/commit/e026325d705c76f8fd2fc2cb1c957980c01ab7fa
  Author: Nicholas Clark <n...@ccl4.org>
  Date:   2021-09-22 (Wed, 22 Sep 2021)

  Changed paths:
    M perl.c

  Log Message:
  -----------
  perl_alloc_using() should use ->pCalloc

Use ->pCalloc  instead of ->pMalloc followed by Zero()

This commit is analogous to the change in perl_alloc() in the previous
commit - the order of S_init_tls_and_interp() and Zero() can be swapped,
at which point the change to use "calloc" is obvious.


Compare: https://github.com/Perl/perl5/compare/c3c34c10a438%5E...e026325d705c

Reply via email to