Skip to content

Coding - Replace function-local new[]/delete[] with std::vector in TKernel(For CI testing) - #2

Closed
jijinbei wants to merge 2 commits into
masterfrom
modernize-raii-array-new
Closed

Coding - Replace function-local new[]/delete[] with std::vector in TKernel(For CI testing)#2
jijinbei wants to merge 2 commits into
masterfrom
modernize-raii-array-new

Conversation

@jijinbei

@jijinbei jijinbei commented Apr 19, 2026

Copy link
Copy Markdown
Owner

Scope

  • 7 sites across 5 files in TKernel
  • Only function-local arrays where Handle<> is not involved and the buffer never escapes the function (or escapes through a copy)
  • Net diff: -1 LOC plus implicit exception-safety win

Pattern

- char* p = new char[N];
- ... use p ...
- delete[] p;
+ std::vector<char> p(N);
+ ... use p.data() ...

Where the OCCT API takes Standard_PCharacter& (lvalue ref to pointer), data() is bound to a named lvalue first.

Files touched

File Sites Notes
TKernel/Message/Message_Msg.cxx 1 char[] for Sprintf
TKernel/NCollection/NCollection_BaseMap.cxx 1 int[] for stats
TKernel/OSD/OSD_Process.cxx 1 wchar_t[], Windows only
TKernel/OSD/OSD_Environment.cxx 1 wchar_t[], Windows only
TKernel/GTests/TCollection_ExtendedString_Test.cxx 3 char[]

Skipped (later steps)

  • OSD_SharedLibrary.cxxmyName is a class member (PIMPL-style refactor needed)
  • NCollection_UtfString.cxxmyWideBuffer is a class member
  • math_ComputeKronrodPointsAndWeights.cxx — heavy s++ / pointer-swap arithmetic

…ernel

Step 1 of MODERNIZATION_NOTES.md item Open-Cascade-SAS#10 (raw new/delete -> RAII).
Targets only function-local arrays where Handle<> is not involved and
the buffer never escapes the function (or its caller's scope through
a copy). Total: 7 sites across 5 files; net diff -1 LOC plus implicit
exception safety win.

Files touched:
  TKernel/Message/Message_Msg.cxx        (1 site, char[] for Sprintf)
  TKernel/NCollection/NCollection_BaseMap.cxx (1 site, int[] for stats)
  TKernel/OSD/OSD_Process.cxx            (1 site, wchar_t[], Windows only)
  TKernel/OSD/OSD_Environment.cxx        (1 site, wchar_t[], Windows only)
  TKernel/GTests/TCollection_ExtendedString_Test.cxx (3 sites, char[])

Pattern applied:
    char* p = new char[N]; ... delete[] p;
becomes
    std::vector<char> p(N); ... use p.data() ...

Where the OCCT API takes Standard_PCharacter& (lvalue ref to pointer),
the data() pointer is bound to a named lvalue first.

Skipped for later steps (member raw pointers, heavy pointer arithmetic):
  TKernel/OSD/OSD_SharedLibrary.cxx          (myName is a class member)
  TKernel/NCollection/NCollection_UtfString.cxx (myWideBuffer member)
  TKMath/math/math_ComputeKronrodPointsAndWeights.cxx
                                             (s++/swap pointer arithmetic)

Verified by running the full OpenCascadeGTest suite on Linux:
  6717 PASS / 4 SKIP (unrelated zero-magnitude exception tests).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jijinbei
jijinbei force-pushed the modernize-raii-array-new branch from b8f27d3 to 8ea9a8d Compare April 19, 2026 19:50
Single-line collapse of std::vector<char> ctor argument; matched
the OCCT clang-format style.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jijinbei

Copy link
Copy Markdown
Owner Author

For CI testing

@jijinbei jijinbei changed the title Coding - Replace function-local new[]/delete[] with std::vector in TKernel Coding - Replace function-local new[]/delete[] with std::vector in TKernel(For CI testing) Apr 20, 2026
@jijinbei jijinbei closed this May 4, 2026
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