Skip to content

PyObjectPtr: no RC even through function pointers#3307

Merged
youknowone merged 14 commits into
RustPython:mainfrom
youknowone:pyptr
Oct 21, 2021
Merged

PyObjectPtr: no RC even through function pointers#3307
youknowone merged 14 commits into
RustPython:mainfrom
youknowone:pyptr

Conversation

@youknowone

@youknowone youknowone commented Oct 14, 2021

Copy link
Copy Markdown
Member

it will enhance performance for type slots by removing double dereference, hopefully.

it also can be used like deferred rc in limited cases

@coolreader18

Copy link
Copy Markdown
Member

I'd prefer a lifetime to be attached to the type, to avoid use after free. Is there any reason there can't be one?

@coolreader18

Copy link
Copy Markdown
Member

Alternatively, my vision for single-indirection borrowed pyobject was a that PyObjectRef implements Deref<Target=PyObject>, so that instead of PyObjectPtr it'd be &PyObject and the with_ptr would just be implicit from Deref coercion

@youknowone youknowone force-pushed the pyptr branch 2 times, most recently from d8a9c34 to 770ef8e Compare October 17, 2021 19:57
@youknowone

Copy link
Copy Markdown
Member Author

@coolreader18 Thanks! lifetime is really helpful advice. I didn't understand the &PyObject idea that much. If PyObjectRef deref to &PyObject<Erased>, how do we get PyObjectRef back again?

@coolreader18

Copy link
Copy Markdown
Member

Just PyObjectRef::from_raw. Like to_owned for it could look like let m = ManuallyDrop::new(PyObjectRef::from_raw(self as *const _ as *const PyObjectRaw)); m.clone(). Should I make a branch of what I was thinking?

@youknowone

Copy link
Copy Markdown
Member Author

@coolreader18 yes, that sounds great

@coolreader18

coolreader18 commented Oct 18, 2021

Copy link
Copy Markdown
Member

@youknowone see borrowed-pyobj

@youknowone

Copy link
Copy Markdown
Member Author

@coolreader18 looks good

@youknowone

Copy link
Copy Markdown
Member Author

mm, it has problem

@youknowone

Copy link
Copy Markdown
Member Author

@coolreader18 could you help it please?

@coolreader18

Copy link
Copy Markdown
Member

@youknowone ok! I think the main issue was the downcast_ref(&&self) -> &PyRef<T> casting, or at the very least switching to &Py<T> fixed whatever was causing the segfault. I think it'd be best to merge asap, since merge conflicts are probably likely with this kind of mass edit.

@DimitrisJim

Copy link
Copy Markdown
Member

Could we remember to document these central types? The PR includes two additional public facing types that will inevitably confuse folks trying to contribute/understand to the/the codebase.

@youknowone

Copy link
Copy Markdown
Member Author

incref is not a rust concept. So removed it and replaced it with to_owned. The name Py is too much generic. Any suggestion? It must be used only as reference.

@youknowone

Copy link
Copy Markdown
Member Author

Renamed a few types not to expose PyObj and Py. Not sure about the name PyObjectView but at least it could be renamed easier than Py.

@youknowone youknowone merged commit dc4d269 into RustPython:main Oct 21, 2021
@youknowone youknowone deleted the pyptr branch October 21, 2021 09:36
@youknowone

Copy link
Copy Markdown
Member Author

@DimitrisJim I agree they must be documented better.

@coolreader18

Copy link
Copy Markdown
Member

Yea, I'm planning on making some follow-up PRs

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