Skip to content

add g_src analysis notes - #6020

Open
ab9rf wants to merge 2 commits into
DFHack:developfrom
ab9rf:df-internal-docs
Open

ab9rf wants to merge 2 commits into
DFHack:developfrom
ab9rf:df-internal-docs

Conversation

@ab9rf

@ab9rf ab9rf commented Oct 20, 2026

Copy link
Copy Markdown
Member

some dev-facing notes on g_src as it relates to DFHack

Comment thread docs/dev/g_src-notes.rst Outdated
- ``renderer_curses`` (PRINT_MODE:TEXT)
- ``df.g_src.renderer_2d.xml``
* - ``renderer_offscreen.cpp``
- offscreen renderer for benchmarking

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

From what I recall, renderer_offscreen is used for things like map exports (or at least it was used for them in older versions)

Comment thread docs/dev/g_src-notes.rst Outdated
``trandom_twist``.
- ``filest``/``stringvectst``/``textlinesst`` — path resolution across DF
dirs (``canon_location``/``both_locations``/
``with_flags(FILE_FLAG_*)``), manual ``char*`` string vector, raw-file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

stringvectst is svector<std::string *> (actually svector<pstringst *>, where class pstringst { public: string dat; };), not char*.

Comment thread docs/dev/g_src-notes.rst Outdated
- **[stale]** ``endian.h`` byteswaps only under ``__ppc__``/
``__ppc64__`` — dead on all modern targets.
- **[bug-ish]** ``stringvectst`` (``files.h``/``basics.h``) manually owns
``char*`` strings, erases from the front, and leaks if methods are used

@quietust quietust Oct 21, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As noted earlier, it actually owns std::string pointers (pointlessly wrapped inside a pstringst class) - all strings are added as copies of the input parameter (whether const char * or const string &) via std::string::operator=, so as long as you never touch the str vector itself (which is unfortunately marked public) and never try to do read_file on a non-empty list, I wouldn't expect it to leak.

@ab9rf ab9rf Oct 21, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It'll leak if something reaches into the (public) vector and removes or modifies elements without properly deleting them. The problem is that this container should own its strings, but it doesn't actually own them, and instead requires its consumers to manage the lifetimes of the string objects it holds. It's, at best, fragile; it is certainly not a good example of RAII in action.

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.

2 participants