Skip to content
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

Trampoline Revamp #36

Merged
merged 28 commits into from
Sep 6, 2023
Merged

Trampoline Revamp #36

merged 28 commits into from
Sep 6, 2023

Conversation

gatesn
Copy link
Contributor

@gatesn gatesn commented Sep 6, 2023

Extends the functionality of the Trampoline to wrap/unwrap more Zig and Python types.

Notably, it includes the ability to wrap/unwrap pointers to Pydust class structs. That means e.g. returning a *Dog from a function.

It also replaces __init__ for __new__. This better aligns with what is actually happening. Previously with init, we needed to allocate some memory (which was entirely undefined), then call an init function on a class. At this point, it wasn't obvious that the class struct fields with default values were not yet assigned.

Whereas now, the class has the responsibility of constructing a full state struct, including defaults, that we can then assign during tp_new to the class state.

pydust/src/pydust.zig Outdated Show resolved Hide resolved
pydust/src/pytypes.zig Outdated Show resolved Hide resolved
Co-authored-by: Robert Kruszewski <[email protected]>
pydust/src/pytypes.zig Outdated Show resolved Hide resolved
test.build.zig Outdated Show resolved Hide resolved
Copy link
Member

@delta003 delta003 left a comment

Choose a reason for hiding this comment

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

LGTM but leaving to Rob to take a pass

test.build.zig Outdated Show resolved Hide resolved
pydust/src/types/buffer.zig Outdated Show resolved Hide resolved
}

pub fn __release_buffer__(self: *const Self, view: *py.PyBuffer) void {
py.allocator.free(self.values);
_ = self;
// FIXME(ngates): ref count the buffer
Copy link
Member

Choose a reason for hiding this comment

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

Not sure what reference you mean here. The view holds a reference to an obj, and https://docs.python.org/3/c-api/buffer.html#c.PyBuffer_Release decrefs that reference AND releases the view which calls this function. This function is optional so I think that means no decrefs need to happen here, and re incref - this was helpful https://jakevdp.github.io/blog/2014/05/05/introduction-to-the-python-buffer-protocol/#Exploring-the-Buffer-Protocol-Code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhhhhh perfect. So we don't need release_buffer at all in this case then, since it's covered by the python object's refcnt

Copy link
Member

Choose a reason for hiding this comment

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

Correct, but might be useful to have it empty given this is an example

@gatesn gatesn enabled auto-merge (squash) September 6, 2023 14:46
@gatesn gatesn merged commit 0ffa22e into develop Sep 6, 2023
1 check passed
@gatesn gatesn deleted the ngates/trampoline branch September 6, 2023 14:47
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