Skip to content

Add support to process null in attributes #3190

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

josesimoes
Copy link
Member

@josesimoes josesimoes commented Jun 25, 2025

Description

  • Checking for sentinel value in string ID creating a null string instance.

Motivation and Context

How Has This Been Tested?

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dev Containers (changes related with Dev Containers, has no impact on code or features)
  • Dependencies/declarations (update dependencies or assembly declarations and changes associated, has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).

Summary by CodeRabbit

  • Bug Fixes
    • Improved attribute parsing to correctly handle special cases where a string token represents a null value, ensuring more accurate processing of attribute data.

- Checking for sentinel value in string ID creating a null string instance.
@josesimoes josesimoes added the Area: Interpreter Everything related with the interpreter, execution engine and such label Jun 25, 2025
Copy link

coderabbitai bot commented Jun 25, 2025

Walkthrough

The update modifies the CLR_RT_AttributeParser::ReadString method to recognize a special string token value (0xFFFF) as representing a null string. When this value is encountered, the method now creates a null string instance instead of a normal string, before boxing the value as previously.

Changes

File(s) Change Summary
src/CLR/Core/TypeSystem.cpp Updated ReadString to handle 0xFFFF token as a null string, creating a null string instance.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant AttributeParser
    participant StringInstance

    Caller->>AttributeParser: ReadString(blob)
    AttributeParser->>AttributeParser: Read token from blob
    alt token == 0xFFFF
        AttributeParser->>StringInstance: Create null string instance
    else token != 0xFFFF
        AttributeParser->>StringInstance: Create string instance from token
    end
    AttributeParser->>AttributeParser: Box string value
    AttributeParser-->>Caller: Return boxed string
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@josesimoes
Copy link
Member Author

@coderabbitai review

Copy link

coderabbitai bot commented Jun 25, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 38faac2 and 4870075.

📒 Files selected for processing (1)
  • src/CLR/Core/TypeSystem.cpp (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ORGPAL_PALX)
  • GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ORGPAL_PALTHREE)
  • GitHub Check: nf-interpreter (Check_Code_Style)
  • GitHub Check: nf-interpreter (Nightly build) (Check_Build_Options)
  • GitHub Check: nf-interpreter (Check_Build_Options)

Comment on lines +7186 to +7195
// check for invalid string ID: "null" string
if (tk == 0xFFFF)
{
// create a null string
NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance(*value, nullptr, m_assm));
}
else
{
NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance(*value, CLR_TkFromType(TBL_Strings, tk), m_assm));
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Clarify handling of the 0xFFFF “null-string” sentinel

Nice addition, but two details are worth revisiting:

  1. Semantics – CLR_RT_HeapBlock_String::CreateInstance(*value, nullptr, …) will still allocate a System.String object (of length 0) rather than leaving the HeapBlock as a null reference. In C# terms this gives "", not null.
    If the intent is a true null, consider:
-        NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance(*value, nullptr, m_assm));
+        value->SetObjectReference(nullptr);            // real null
+        // boxing a null reference is a no-op, so skip PerformBoxing
+        return S_OK;   // early-exit, nothing more to do

(or update CreateInstance to return a null object explicitly).

  1. Magic number – Introduce a named constant (e.g. c_STRING_TOKEN_NULL) instead of the raw 0xFFFF; it documents intent and prevents accidental reuse.
+static constexpr CLR_UINT16 c_STRING_TOKEN_NULL = 0xFFFF;
 ...
-    if (tk == 0xFFFF)
+    if (tk == c_STRING_TOKEN_NULL)

These tweaks make the behaviour unambiguous and future-proof.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// check for invalid string ID: "null" string
if (tk == 0xFFFF)
{
// create a null string
NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance(*value, nullptr, m_assm));
}
else
{
NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance(*value, CLR_TkFromType(TBL_Strings, tk), m_assm));
}
static constexpr CLR_UINT16 c_STRING_TOKEN_NULL = 0xFFFF;
// check for invalid string ID: "null" string
if (tk == c_STRING_TOKEN_NULL)
{
value->SetObjectReference(nullptr); // real null
// boxing a null reference is a no-op, so skip PerformBoxing
return S_OK; // early-exit, nothing more to do
}
else
{
NANOCLR_CHECK_HRESULT(
CLR_RT_HeapBlock_String::CreateInstance(
*value,
CLR_TkFromType(TBL_Strings, tk),
m_assm
)
);
}
🤖 Prompt for AI Agents
In src/CLR/Core/TypeSystem.cpp around lines 7186 to 7195, the handling of the
0xFFFF sentinel for a "null" string currently creates an empty string instance
instead of a true null reference. To fix this, modify the code to set the
HeapBlock to a null reference explicitly when tk equals 0xFFFF, avoiding
allocation of an empty string. Additionally, replace the magic number 0xFFFF
with a clearly named constant like c_STRING_TOKEN_NULL to improve code clarity
and maintainability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Interpreter Everything related with the interpreter, execution engine and such Type: enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants