Skip to content

PyObjectRc: thin wrapper for PyObjectRef inner Rc #2155

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

Merged
merged 6 commits into from
Sep 14, 2020

Conversation

youknowone
Copy link
Member

@youknowone youknowone commented Aug 27, 2020

Split __del__ unrelated part from #2128

this patch will be base of any kind of drop implementation

@youknowone youknowone force-pushed the pyobjectrc branch 4 times, most recently from e2df7d4 to 454d132 Compare August 27, 2020 23:30
Copy link

@BenLewis-Seequent BenLewis-Seequent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good. I think we should be able to hide the fact that PyObjectRc is a thin wrapper around Rc/Arc pretty well, and have PyObjectRc offer all the interface that is needed instead of using .rc()/PyObjectRc::into_rc().

@@ -472,9 +475,9 @@ impl PyObject<dyn PyObjectPayload> {
self: PyRc<Self>,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be changed to take self: PyObjectRc<Self> instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope -- blocked on the arbitrary_self_types feature

@youknowone youknowone force-pushed the pyobjectrc branch 2 times, most recently from 4bf87fd to 4a29357 Compare September 5, 2020 15:10
@youknowone
Copy link
Member Author

this generic way seems not fit for drop implementation 🤦

@coolreader18
Copy link
Member

What if you make it generic over the payload for PyObject? e.g. inner: PyRc<PyObject<T>>

@coolreader18
Copy link
Member

coolreader18 commented Sep 5, 2020

I think that would make the name make more sense as well; PyObjectRc is a wrapper around Rc<PyObject>

@youknowone youknowone force-pushed the pyobjectrc branch 4 times, most recently from fd705bd to 099ce1d Compare September 12, 2020 17:55
@youknowone
Copy link
Member Author

@coolreader18 @Skinny121 thanks for the reviews! I think this is finally done

@youknowone youknowone force-pushed the pyobjectrc branch 6 times, most recently from cc1c9a7 to 273fcb2 Compare September 13, 2020 01:04
@youknowone
Copy link
Member Author

after converting to embed PyObject, it was possible to move some parts back to pyobject.rs

T: ?Sized + PyObjectPayload,
PyRc<PyObject<T>>: AsPyObjectRef,
{
type Target = PyRc<PyObject<T>>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're making it unsafe to access the inner PyRc, we should probably make the target PyObject<T>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think trying to make target PyObject<T> is a good idea. But accessing to inner PyRc is safe. into_rc is unsafe because it skips dropping of PyObjectRc. This is borrowing, so there is no reason to be unsafe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, it can be a problem when it is cloned from the ref, got it.

inner: PyRc<PyObject<T>>,
}

pub type PyObjectWeak<T = dyn PyObjectPayload> = PyWeak<PyObject<T>>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be a newtype as well 😬 still the issue of downgrade->upgrade to Arc->drop original PyObjectRc->drop Arc without __del__. It would also let you add the upgrade() method to PyObjectWeak and have it return a PyObjectRc

@youknowone youknowone merged commit 637adb5 into RustPython:master Sep 14, 2020
@youknowone youknowone deleted the pyobjectrc branch September 14, 2020 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants