Skip to content

py: modify object struct to empty#22

Merged
xushiwei merged 1 commit into
goplus:mainfrom
toaction:py_empty_object
Nov 11, 2025
Merged

py: modify object struct to empty#22
xushiwei merged 1 commit into
goplus:mainfrom
toaction:py_empty_object

Conversation

@toaction
Copy link
Copy Markdown

@toaction toaction commented Oct 3, 2025

Overview

This PR changes the py.Object structure definition to an empty structure. which clarifies that LLGo treats Python objects managed by the C runtime as references, rather than storing the specific memory address of Python object in actual structure field.

This definition change supports multiple inheritance via structure embedding in LLGo. The design can be found at goplus/llpyg#21, and the implementation can be found at xgo-dev/llgo#1289.

Major Changes

source code:

// Object represents a Python object.
type Object struct {
	Unused [8]byte
}

target code:

// Object represents a Python object.
type Object struct {
	Unused [0]byte
}

Changing the field size to 0 is more clear than deleting the field and is consistent with the established pattern of the warehouse, such as c/os/dir.go:

type DIR struct {
	Unused [0]byte
}

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @toaction, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request streamlines the definition of the Object struct within py/object.go by removing an Unused field. This change simplifies the struct's structure, potentially optimizing memory usage and clarifying its core purpose by eliminating unnecessary components.

Highlights

  • Object Struct Modification: The Unused [8]byte field has been removed from the Object struct definition in py/object.go.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the py.Object struct to be an empty struct by removing the Unused field. This is a good change as it makes py.Object an opaque type, which is idiomatic in Go for representing C pointers like PyObject*. The change correctly reflects that *Object is used as a handle to a Python object managed by the C runtime, and its Go definition does not need to match the C layout. The change is clean and has no apparent side effects based on the usage in the provided files.

Comment thread py/object.go
@niupilot
Copy link
Copy Markdown

niupilot Bot commented Oct 3, 2025

Review Summary

This change is functionally safe with no security, performance, or compatibility issues. The empty struct correctly represents an opaque handle to Python's PyObject*.

One noteworthy observation: The codebase predominantly uses Unused [0]byte for opaque C types (18+ instances). Consider aligning with this convention for consistency, though the current empty struct is also valid.

@xushiwei xushiwei merged commit 98171ec into goplus:main Nov 11, 2025
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