Conversation
✅ Deploy Preview for conkyweb canceled.
|
0959d40 to
4140f49
Compare
d24fc56 to
fab4ed5
Compare
e0f8a46 to
86e7192
Compare
Replace the first batch of ~40 text objects from the strcmp if-else chain in construct_text_object with an unordered_map registry that feature files populate at static init time via CONKY_REGISTER_VARIABLE. The registry dispatcher runs before the legacy chain — matched objects are handled by the new path, misses fall through to the old code. This allows incremental migration without breaking unported variables. Introduces print_variable/print_variable_impl: a type-dispatched helper that auto-formats values from static getters (strings, ints, floats, bools, chrono durations) with optional spaced_print padding. Uses a macro + local-struct trick to bridge C++17 lambdas into NTTP function pointers, producing fully non-capturing callbacks. Migrated variables (common.cc): kernel, machine, nodename, nodename_short, sysname, uptime, uptime_short, mem*, swap*, buffers, cached, free_bufcache, free_cached, memperc, membar, memgauge, memgraph, memwithbuffers*, swapperc, swapbar, processes, running_processes, threads, running_threads, loadavg, updates. Named print functions for these variables are eliminated — their logic is inlined as non-capturing lambdas in the registration block. Refs: #2052 Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
…les to registry
Move ~70 more text objects from the core.cc if-else chain into
distributed CONKY_REGISTER_VARIABLES blocks in their feature files.
Migrated groups:
- ACPI/battery (common.cc, #ifndef __OpenBSD__): acpitemp,
acpiacadapter, acpifan, battery, battery_short, battery_status,
battery_time, battery_percent, battery_power_draw, battery_bar
- Freq: freq, freq_g
- Control flow: if_empty, if_existing, if_running (all platform
variants), if_updatenr, no_update, eval, blink, include
- Misc: loadgraph, github_notifications, stock
- Proc (proc.cc): all 40 pid_* variables, cmdline_to_pid
Infrastructure additions:
- arg_object_variable: template helper for variables with live
sub-expression arguments (pid_* pattern), inlines
extract_object_args_to_sub
- print_cb type alias for print callback signature
- CONKY_CONCAT macro in macros.h for unique static init names,
enabling multiple CONKY_REGISTER_VARIABLES per translation unit
313 lines removed from core.cc, ~26% of the chain cleaned up.
Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
Delete proc.h — all functions are now internal to proc.cc via the
registry. Replace its macros with typed constants:
- PROCDIR → std::filesystem::path (proc.cc local, linux.h shared)
- READERR → constexpr const char* read_error
- READSIZE → constexpr std::size_t read_size
Replace C-style readfile (fopen/fread/realloc loop) with a 6-line
std::ifstream implementation returning std::optional<std::string>.
Remove readfile declaration from common.h — now static in proc.cc.
Replace 15 instances of unique_ptr<char[]> + generate_text_internal
with eval_sub_arg() returning std::string. Replace hand-rolled
ll_string linked list with std::unordered_set for dedup in
print_pid_openfiles.
Collapse repetitive functions into constexpr table + template pairs:
- 8 print_pid_{uid,gid,...} → print_pid_Xid<xid_type> + xid_table
- 12 print_pid_vm*/read/write → print_proc_field<field> + proc_field_table
- 3 print_pid_std{in,out,err} + chroot/cwd/exe → print_pid_readlink<link>
Migrate path construction from std::ostringstream to
std::filesystem::path operator/. pid_readlink now accepts
const filesystem::path& directly.
Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
|
@npyl just pushed some crypto spam to this branch. I am working on reverting that, and have blocked & reported the account (I'm guessing their credentials were compromised). |
8875b86 to
c0a3e0d
Compare
|
As a heads-up: I am going to change the branch policy to disallow force pushes to any branch (not just |
@brndnmtthws That breaks rebasing, makes PRs extremely annoying to use, and doesn't really improve security. Without force-pushes, PR branches effectively become append-only:
A collaborator with previous contribution can just push a new commit on top of someone else's PR, approve and merge the branch. Someone with alt accounts that both contributed can also still make a PR and verify it on their own. The only solution is to limit approvals, and make them auto-retract when branch is mutated. At the moment, 185 accounts (besides yours) have mutable access to main, if there's an alt account among those, a single person can push malicious code to main on their own, regardless of branch/PR mutability. Signing commits with GPG is what's supposed to address this problem, but that introduces friction for new developers. What I suggest you do instead:
With that in place, you don't disable majority of git functionality and it solves the problem you're pointing to without the solution being a nuisance or enforcing bad practices GitHub already makes all too easy. |
|
The main issue here was that someone rewrote the git history, which is annoying but not the worst thing. Let me think a bit more about it, I don't want to add too much friction and disabling force pushes just means you need to use merges instead of rebasing in your branch, but the final merge into master is always a rebase. I'll remove the rule for now but I might change my mind. I don't love the idea of requiring signed commits because most people don't sign their commits properly and invalidating approvals can be annoying when you want to approve the PR even if there are still some more follow-up changes needed. There's a balance here between avoiding bad things (such as likely credential compromise in this case) by making sure history can't be rewritten and making it super inconvenient for people. |
|
Ok, thank you for staying ahead of this. In this instance, my PRs were safe because I don't really ever pull from PR branches so their changes would've been overwritten once I rebased my local worktrees. I don't merge using GitHub Web UI because it's incapable of preserving even commits that are directly on main. I see it could be an issue for other contributors though and something that could erode trust towards people who are trying to enter the project. Not promising anything, but I might make a PR for the proposed solution, and rethink approval retraction (maybe make it conditional and trigger under certain circumstances (a new account appearing in commits)). GH triggers CI events even on force pushes (commit overwrites), so that shouldn't be much of an issue. |
c0a3e0d to
2e79529
Compare
This is a large refactor that untangles most of the code from
core.cc. It removes the huge if-elseif-elseif chain incore.ccand replaces it with a registry pattern andstd::unordered_maplookup.Improvements:
core.ccno longer needs blocks on everything else.O(1)amortized, instead ofO(n). (Though this wasn't really a huge cost)Changes that affect functionality (fix bugs) are separated into their own commits so they can be reverted separately if needed; none of
refactorcommits affect behavior.This PR requires bumping GCC minimal supported version to 13 (expand for details)
GCC 13.1 was released: April 26, 2023
GCC 13.1 is needed because a macro added in
variables.hhrelies on P1907R1 ("Inconsistencies with non-type template parameters") being applied as a defect resolution to C++17 mode. Theprint_variablemacro bridges C++17 lambdas into NTTP function pointers via a local struct's static member, whose address has no linkage under too-broad C++17 [basic.link]/8 rule. GCC 13+ and Clang treat P1907R1 as a DR and accept this in C++17 mode; GCC 11/12 do not. In C++20 this workaround becomes unnecessary because stateless lambdas are valid NTTPs directly.Intuitively, this makes sense to be a DR because a non-capturing lambda is fully static, and a struct declared in it should be statically linkable too.
Not having P1907R1 means that we can't use non-capturing lambdas for variable parsing, which avoidable but ugly because it reverts to having ~100 functions that are 1-3 lines of "read and print variable" code. DR makes this much cleaner.
Ubuntu 24.04 does have GCC 13/14, so this change doesn't affect compatibility matrix for official distro packaging (buildd), 22.04 will only backport security vulnerabilities.
GCC issue: gcc#96645
Closes #2052.
This is WIP until I move all variable parsing out of
core.cc. But each commit compiles and runs in isolation and can be tested as-is.