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

set nil as the initial value of the struct reference type fields #192

Merged
merged 1 commit into from
Nov 21, 2023

Conversation

shove70
Copy link
Contributor

@shove70 shove70 commented Nov 21, 2023

for green CI:
vlang/v#19944

Summary by CodeRabbit

  • Refactor

    • Default initializations for various data structures have been set to nil for improved safety and consistency.
  • Chores

    • Internal code adjustments to ensure proper default values across different modules.

Note: These changes should not directly affect end-user functionality but may enhance overall system stability and reliability.

Copy link

coderabbitai bot commented Nov 21, 2023

Walkthrough

The overarching change across multiple files is the introduction of default nil initializations for various struct fields, using unsafe blocks. This modification ensures that fields within structs have a defined starting state, potentially altering the behavior of instances upon creation.

Changes

Files Change Summary
gm/basicgm.v, ml/..., vcl/... Struct fields in various modules (gm, ml, vcl) are now initialized to nil using unsafe blocks.

🌟 In the code's quiet gleam,
🐇 A rabbit sets nil as the default dream.
As autumn leaves swirl in a lively dance,
Our structs are given a safer chance.


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

@shove70 shove70 merged commit 2cdb2dc into vlang:main Nov 21, 2023
7 of 9 checks passed
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 8

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f49719c and e39bbb5.
Files selected for processing (11)
  • gm/basicgm.v (1 hunks)
  • ml/data.v (1 hunks)
  • ml/kmeans.v (1 hunks)
  • ml/knn.v (1 hunks)
  • ml/linreg.v (1 hunks)
  • ml/workspace.v (1 hunks)
  • vcl/buffer.c.v (1 hunks)
  • vcl/bytes.c.v (1 hunks)
  • vcl/image.c.v (1 hunks)
  • vcl/kernel.c.v (3 hunks)
  • vcl/vector.c.v (1 hunks)
Files skipped from review due to trivial changes (1)
  • ml/kmeans.v
Additional comments: 4
vcl/bytes.c.v (1)
  • 5-5: The initialization of buf to nil within an unsafe block is a significant change that ensures the Bytes struct starts with a nil reference for buf. This change is consistent with the pull request's goal to initialize reference type fields to nil. However, it is important to ensure that all methods that interact with buf properly handle the nil case to prevent null reference errors.
ml/data.v (1)
  • 25-30: The x field in the Data struct is now initialized to nil within an unsafe block. This change is consistent with the pull request's goal to initialize reference type fields to nil. However, it is important to ensure that all methods and functions that interact with the Data struct are updated to handle the possibility of x being nil. This includes checking for nil before dereferencing x and providing appropriate error handling or fallback logic.
vcl/image.c.v (1)
  • 22-27: The Image struct now initializes the desc field to nil within an unsafe block. This change is consistent with the pull request's goal to initialize reference type fields to nil to pass CI checks. However, it's important to ensure that any code that interacts with the desc field of Image instances properly handles the nil value to avoid null reference errors. Additionally, since the change is made within an unsafe block, it bypasses the language's safety checks, which should be done with caution and only when necessary.
vcl/buffer.c.v (1)
  • 3-9: The change to initialize the device field to nil using unsafe code is a significant alteration to the Buffer struct. This change ensures that the device field is explicitly set to a known state (nil) rather than being uninitialized, which could lead to undefined behavior. However, it is important to ensure that all parts of the code that interact with the Buffer struct are updated to handle the nil value appropriately. This includes checking for nil before dereferencing the device field to avoid null pointer dereferences.

vcl/vector.c.v Show resolved Hide resolved
gm/basicgm.v Show resolved Hide resolved
ml/linreg.v Show resolved Hide resolved
ml/knn.v Show resolved Hide resolved
ml/workspace.v Show resolved Hide resolved
vcl/kernel.c.v Show resolved Hide resolved
vcl/kernel.c.v Show resolved Hide resolved
vcl/kernel.c.v Show resolved Hide resolved
@shove70 shove70 deleted the ref_init branch November 21, 2023 04:14
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.

1 participant