-
-
Notifications
You must be signed in to change notification settings - Fork 180
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
base: develop
Are you sure you want to change the base?
Add support to process null
in attributes
#3190
Conversation
- Checking for sentinel value in string ID creating a null string instance.
WalkthroughThe update modifies the Changes
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
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this 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
📒 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)
// 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)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Clarify handling of the 0xFFFF
“null-string” sentinel
Nice addition, but two details are worth revisiting:
- Semantics –
CLR_RT_HeapBlock_String::CreateInstance(*value, nullptr, …)
will still allocate aSystem.String
object (of length 0) rather than leaving theHeapBlock
as anull
reference. In C# terms this gives""
, notnull
.
If the intent is a truenull
, 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).
- Magic number – Introduce a named constant (e.g.
c_STRING_TOKEN_NULL
) instead of the raw0xFFFF
; 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.
// 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.
Description
Motivation and Context
null
.How Has This Been Tested?
[DataRow(999, null)]
.[build with MDP buildId 56307]
Screenshots
Types of changes
Checklist
Summary by CodeRabbit