On Thu, Jun 19, 2025 at 11:49 AM Burak Emir <[email protected]> wrote:
>
> On Mon, Jun 16, 2025 at 12:49 PM Alice Ryhl <[email protected]> wrote:
> >
> > On Wed, Jun 11, 2025 at 9:48 PM Burak Emir <[email protected]> wrote:
> > > +impl core::ops::DerefMut for Bitmap {
> > > +    fn deref_mut(&mut self) -> &mut CBitmap {
> > > +        let ptr = if self.nbits <= bindings::BITS_PER_LONG as _ {
> > > +            // SAFETY: Bitmap is represented inline.
> > > +            unsafe { core::ptr::addr_of_mut!(self.repr.bitmap) }
> > > +        } else {
> > > +            // SAFETY: Bitmap is represented as array of `unsigned long`.
> > > +            unsafe { self.repr.ptr.as_mut() }
> >
> > Nit: You want NonNull::as_mut_ptr() here.
>
> Can you explain? That seems to be an unstable method that exists so
> one can get pointer to slice buffer.
>
> The repr.ptr case is NonNull<usize>, not a slice - though "morally",
> it is actually an owned C array.
> Are you suggesting we could/should represent it as a Rust one?
> However, we'd like it to use the C API to free etc.

Sorry I meant NonNull::as_ptr() which returns a mutable pointer:
https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.as_ptr

Alice

Reply via email to