Replace unsafe C functions Proposal

There are three things here:

Why test for nullptr

Existing callers can pass nullptr; we need to guard against that.

why do you need to do an implicit conversion

So that the member can be automatically managed instead of being manual (with macro support)

Why use vtkStdString at all?

Because we need to preserve const char* access to the getter (it is currently char*, but actually modifying it bypasses Modified() calls to everyone’s great enjoyment I’m sure; anyone actually doing that is just setting themselves up for failure). Making the return type vtkStdString const& preserves that conversion (auto* s = obj->GetString(); is messed up though…but there’s an easy compatible way to write it too with an explicit const char*).

Because char* management is finicky. Common faults:

  • not releasing the buffer before reuse
  • using the wrong allocation mechanism (vtkSetGet uses new[], so delete[] is needed)
  • forgetting to set it back to nullptr in the destructor

In order to remove our use of C string library functions, not using char* for strings is basically required unless we’re going to pay for a strlen per string_view constructed from one for further manipulations. You may as well just bundle the allocation and length memorization in std::string (of which, vtkStdString is a better compatibility story).