D7796: rust-nodemap: input/output primitives

kevincox (Kevin Cox) phabricator at mercurial-scm.org
Thu Jan 16 07:10:31 EST 2020


kevincox added inline comments.

INLINE COMMENTS

> kevincox wrote in nodemap.rs:268
> This makes me uncomfortable. There is really no guarantee that there is no padding around `Block` or `RawElement`. If there is any padding this is UB. I would much prefer one of:
> 
> 1. Store growable as a set of bytes and convert on get/set.
> 2. Add a method that outputs the bytes to any `Write`. In theory this will be slower but it is probably immaterial (especially if there is no padding).

I thought about this more and I think I am okay doing it this way. It seems like this should be well defined as long as there is no padding. However on that note I would want to add a check that there is no padding as expected. I would also like to ensure that this fails to compile if there is ever padding, even in release mode. I think this can be accomplished by something like:

  let _: [u8; 4 * BLOCK_SIZE] = std::mem::transmute([Block::new(); 4]);

I would probably want to repeat this check near any code that is relying on this invariant.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7796/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7796

To: gracinet, #hg-reviewers, kevincox
Cc: durin42, kevincox, mercurial-devel


More information about the Mercurial-devel mailing list