Skip to content

refactor: move utility functions out of the global namespace#1012

Closed
wbruna wants to merge 1 commit into
leejet:masterfrom
wbruna:sd_util_name_conflict
Closed

refactor: move utility functions out of the global namespace#1012
wbruna wants to merge 1 commit into
leejet:masterfrom
wbruna:sd_util_name_conflict

Conversation

@wbruna

@wbruna wbruna commented Nov 26, 2025

Copy link
Copy Markdown
Contributor

Many utility functions have generic names that may conflict with symbols from other libraries, causing linkage issues.

The 'inline namespace' approach seems ideal for this case, since it's automatically added by any source code that includes util.h. Moving the whole library to its own namespace would also work, of course.

I kept the functions in place to avoid a huge diff, but they should probably be reorganized by visibility.

This is related to #967 , which I suggested for the same reason.

Should fix #1011 .

Many utility functions have generic names that may conflict with
symbols from other libraries, causing linkage issues.

fixes leejet#1011
Comment thread util.h

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a .h file, not .hpp. There is no such thing as namespaces in C code. Maybe use #ifdef __cplusplus? Or use a prefix instead of a namespace.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually the whole file contains c++ stuff like std::strings, nevermind. It should probably be a .hpp instad.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that is far from consistent right now. I believe stable-diffusion.h is the only file that's intended to keep compatibility with C.

@leejet

leejet commented Nov 30, 2025

Copy link
Copy Markdown
Owner

This can only solve part of the symbol issues, and it makes the code a bit messy. I will refactor the relevant parts later. For now, I think we can just rename format in this PR.

@wbruna

wbruna commented Nov 30, 2025

Copy link
Copy Markdown
Contributor Author

I added the format rename to #967 , since it can be grouped with that commit.

@wbruna wbruna closed this Nov 30, 2025
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.

[Bug] Please consider renaming or inlining std::string format(const char* fmt, ...) in util.cpp, as it conflicts with llama.cpp def

3 participants