-
Couldn't load subscription status.
- Fork 388
fix several printf-related warnings #2309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
01727c5 to
ad4fb7d
Compare
|
This change exposes an implicit narrowing cast, which the last commit addresses. They might have been in the logs earlier, but it wasn't until this change where I noticed it. |
0adb7ad to
08b0a5b
Compare
|
This is ready for merge I believe. It seems we have |
|
Running ./test.sh gave me issues: Run the test script and fix issues. Will redo test. |
|
Also, it prints |
a806786 to
0f304a6
Compare
|
This still needs some work to fix the futex issues. |
0f304a6 to
3c2fc5e
Compare
|
It seems like both All tests are passing now. Thanks @torgeiru :) |
3c2fc5e to
8971abe
Compare
|
std::format could potentially be replaced with libfmt with the |
|
Isn't |
|
They have nearly the same API but one is in the standard library and the other is fast, as usual. It's not slow by any means, but if you can't use it because it uses futex internally, then I wouldn't mind bringing in libfmt. It's a staple default in any modern C++ project anyway. |
|
Nice. I might look into it tonight/tomorrow. The main downside with the statically sized char-buffer, using Right now I'm cleaning up some warnings which only show up when running tests. |
ae26f22 to
1efcf4e
Compare
use proper format specifier for pointer
1efcf4e to
a97d373
Compare
6a1e049 to
ed25751
Compare
|
Thanks for the suggestion on using {fmt} @fwsGonzo , but I can't seem to find any way to convert from I understand the types should be available at comptime, so in theory this should be possible I believe. I suspect a heap is required if {}-type format specifiers are used at runtime (correct me if I'm wrong), which is why it'd be nice to do the conversion at comptime. I have pulled in libfmt as a dependency regardless, it's a bit more convenient. Since All tests are passing, and I see no printf-related warnings on my end anymore. Yippie. :3 I believe this can be merged now, unless there anything else to do at this time? In the future it'd be nice to have a proper namespace for warnings, info, debugging including colours, prefixes and so forth (i.e. |
#include <os>
#include <service>
#include <fmt/core.h>
#include <fmt/compile.h>
consteval std::string constexpr_format(auto fmt, auto&&... args) {
std::string buf;
fmt::format_to(std::back_inserter(buf), fmt, std::forward<decltype(args)>(args)...);
return buf;
}
#define _kfmt(prefix, fmt, ...) do { \
kprintf("%s%s", prefix, constexpr_format(FMT_COMPILE(fmt "\n"), ##__VA_ARGS__).c_str()); \
} while (0)
void Service::start(const std::string& args) {
_kfmt("service::", "meow {} world", 42);
os::shutdown();
}My suspicion was right, it's actually possible to do this at comptime. Worth noting for a later time: currently we're still stuck with the 8192 limit of the serial console buffer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving this conditionally: I want us to make 100% sure that we can't convince std::fmt to work for us, without having to add futex. If we do need futex, please post an issue to remove this dependency if / when we get to implementing or stubbing futex.
And thanks for this - "{}" is so much easier to maintain than all the printf specifiers😍
| { | ||
| static intptr_t last = 0; | ||
|
|
||
| inline std::string to_human_size(std::uint64_t bytes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should live in api/util/ somewhere. I think they could be useful more places. See also https://github.com/includeos/IncludeOS/blob/main/api/util/units.hpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I was planning to move them into api/info in a later PR where I turn it into a proper namespaced library. Do you think I should partially start building that library here?
| pname = "fmt"; | ||
| version = "12.0.0"; | ||
|
|
||
| src = pkgs.fetchFromGitHub { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure there's no way of doing the same without adding another dependency? If we're sure std::fmt absolutely requires futex and fmtlib/fmt doesn't, I'm fine with this. But would much prefer to use the standard if we can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extent of what I changed can work just the same without libfmt. That said, libfmt does have some additional quality of life features such as colours and <fmt/compile.h>. Both std::format() and fmt::format() behave the same when it comes to futexes, and both std::format_to() and fmt::format_to() work without it.
If you want I can revert the addition of libfmt. Should be rather trivial.
|
Can confirm that this builds and that tests succeed after a rebase on current main. @mazunki this only needs the tracking issue requested by Alfred, then it should be ready to be merged:
|
|
Yep, I opened an issue about it. |
|
Thanks! |
Cleaning up more warnings, this time related to printing. This also introduces the
ExpectsfandEnsuresffunctions which act similar to the oldExpectsandEnsuresassertion functions, but take a condition and the format specifier as different arguments. I have introduced a basic example of its usage insrc/musl/mmap.cpp:Ensuresf(false, "hello {}", 42);will error immediately.I'd like to update all prior uses of
Expectsto separate the condition from the message, but I believe it would be cleaner to do this in a later PR. After that we could potentially merge the suffixed version into a single function. Related: What is the semantic difference betweenExpectsandEnsures? They behave identically.On a similar note, we currently have
util/logger.{cpp,hpp}with the Logger class. I believe we could move theinfof,warnfanderrorffunctions fromvmbuild/vmbuild.cppinto a namespace for the purpose of logging? Seems like it would be useful to have this in several places. TheINFO(namespace, ...)could just be defined local to each file. Is this something we want?