Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the return type of SharedMemory::data #5240

Merged
merged 1 commit into from
Nov 10, 2022

Commits on Nov 10, 2022

  1. Change the return type of SharedMemory::data

    This commit is an attempt at improving the safety of using the return
    value of the `SharedMemory::data` method. Previously this returned
    `*mut [u8]` which, while correct, is unwieldy and unsafe to work with.
    The new return value of `&[UnsafeCell<u8>]` has a few advantages:
    
    * The lifetime of the returned data is now connected to the
      `SharedMemory` itself, removing the possibility for a class of errors
      of accidentally using the prior `*mut [u8]` beyond its original lifetime.
    
    * It's not possibly to safely access `.len()` as opposed to requiring an
      `unsafe` dereference before.
    
    * The data internally within the slice is now what retains the `unsafe`
      bits, namely indicating that accessing any memory inside of the
      contents returned is `unsafe` but addressing it is safe.
    
    I was inspired by the `wiggle`-based discussion on bytecodealliance#5229 and felt it
    appropriate to apply a similar change here.
    alexcrichton committed Nov 10, 2022
    Configuration menu
    Copy the full SHA
    bafd260 View commit details
    Browse the repository at this point in the history