Skip to content

Make PyObject.typ a Rc<PyObject<PyClass>> #1811

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 3 commits into from
Apr 3, 2020

Conversation

coolreader18
Copy link
Member

@coolreader18 coolreader18 commented Mar 12, 2020

The main motivator for this is to make the type hierarchy creation simpler and less error prone; this removes the trait object hack, including a few questionable transmutes.

@coolreader18 coolreader18 force-pushed the coolreader18/typ-generic-pyobj branch from 3f771cc to c16a257 Compare March 12, 2020 22:43
@coolreader18 coolreader18 marked this pull request as ready for review April 2, 2020 23:02
@coolreader18
Copy link
Member Author

Whoops, I forgot about this; I think it was actually fine when I first opened it.

@coolreader18 coolreader18 requested a review from youknowone April 2, 2020 23:02
Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

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

Because I am not understanding this part very well, please check this is correct description of this patch:

We were using PyRef as shared pointer for PyObject::typ before, but now using Rust Rc instead of it.

Co-Authored-By: Jeong YunWon <youknowone@users.noreply.github.com>
@coolreader18
Copy link
Member Author

coolreader18 commented Apr 3, 2020

Yeah; PyRef<T> is really just a wrapper around a PyObjectRef, which has a trait object inside of it and is therefore a "fat pointer" with a vtable pointer. In order to properly initialize a PyClassRef, then, we need to provide it with a vtable pointer to the correct vtable, which is pretty unsafe and requires some hacks to get the vpointer in the first place. With Rc<PyObject<PyClass>> (instead of Rc<PyObject<dyn PyObjectPayload>>), the inner type is just a plain struct, PyClass, and so it doesn't require any vtable pointers or anything like that.

@coolreader18 coolreader18 merged commit a104d43 into master Apr 3, 2020
@coolreader18 coolreader18 deleted the coolreader18/typ-generic-pyobj branch April 3, 2020 17:20
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.

2 participants