D6631: rust-cpython: add macro for sharing references

kevincox (Kevin Cox) phabricator at mercurial-scm.org
Tue Jul 16 09:13:27 EDT 2019


kevincox added a comment.


  In D6631#97216 <https://phab.mercurial-scm.org/D6631#97216>, @kevincox wrote:
  
  > Is there any reason this can't be done using `Rc<RefCell<DirsMultiset>>`?  I have an example here: https://rust.godbolt.org/z/MNNR_F
  
  I see now that since python is managing the reference it does make some sense to do it this way.

INLINE COMMENTS

> macros.rs:55
> +        $data_member: ident,
> +        $leaked: ident
> +    ) => {

The terminology is weird here. You don't appear to be tracking leaks, just borrows.

> gracinet wrote in macros.rs:61
> Hi Kevin,
> 
> all that CPython's `del` does is decrement the reference count, and if it drops to 0, then the memory will be freed immediately. On the other hand, the `clone_ref()` at line 106 does increment it.
> 
> So, in your example, after `del c` the refcount of `c` is 1 and the memory shouldn't be freed.

Thanks. I missed that.

> macros.rs:85
> +                         immutable references in Python objects",
> +                    )),
> +                }

This catches a mutable borrow after other borrows, however I believe it fails to catch a mutable borrow followed by immutable borrows.

REPOSITORY
  rHG Mercurial

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

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

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


More information about the Mercurial-devel mailing list