Fix IntArray class and a few math classes with memory management and code style improvements#7112
Open
mohanchen wants to merge 12 commits intodeepmodeling:developfrom
Open
Fix IntArray class and a few math classes with memory management and code style improvements#7112mohanchen wants to merge 12 commits intodeepmodeling:developfrom
mohanchen wants to merge 12 commits intodeepmodeling:developfrom
Conversation
Changes: 1. Fix memory management issues: - Add exception handling for memory allocation failures - Use two-stage memory allocation in create() methods to avoid memory leaks - Add null pointer checks in zero_out() and operator=(int) 2. Improve class design: - Implement copy constructor to avoid shallow copy issues - Implement move constructor and move assignment operator for better performance - Add comprehensive boundary checks for negative indices 3. Code style improvements: - Change braces to be on separate lines - Replace tabs with spaces - Change Chinese comments to English 4. Ensure code robustness: - Add error messages for memory allocation failures - Maintain object validity even when memory allocation fails This fix ensures the IntArray class is more robust, secure, and efficient, while following consistent code style guidelines.
added 2 commits
March 23, 2026 10:37
Changes: 1. Add memory allocation failure test using custom operator new override 2. Fix move constructor and move assignment operator to properly reset all member variables 3. Improve test class initialization by moving member initialization to constructor 4. Ensure all tests pass with the new functionality This commit enhances the robustness of the IntArray class by ensuring it properly handles memory allocation failures and correctly implements move semantics.
ErjieWu
reviewed
Mar 23, 2026
| assert(ptr != nullptr);zero_out(); | ||
| size = d1 * d2 * d3;assert(size>0); | ||
| dim = 3; | ||
| bound1 = d1;bound2 = d2;bound3 = d3;bound4 = 1; |
Collaborator
There was a problem hiding this comment.
It seems bound4 is useless in 3d IntArray, bound3 and bound4 are useless in 2d IntArray.
ErjieWu
reviewed
Mar 23, 2026
Collaborator
There was a problem hiding this comment.
The name of this document is "basic_types_class.md", but the content is entirely focused on IntArray. I noticed that "index.rst" is also created for developers to read. Should the file name be adjusted, or should other contents be added to this document later?
Collaborator
Author
There was a problem hiding this comment.
I have updated the document, the document is intended for tool classes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes:
Fix memory management issues:
Improve class design:
Code style improvements:
Ensure code robustness:
This fix ensures the IntArray class is more robust, secure, and efficient, while following consistent code style guidelines.
Reminder
Linked Issue
Fix #...
Unit Tests and/or Case Tests for my changes
What's changed?
Any changes of core modules? (ignore if not applicable)