cleanup(libsinsp): untangle table/entry class hierarchy#2848
cleanup(libsinsp): untangle table/entry class hierarchy#2848poiana merged 11 commits intofalcosecurity:masterfrom
Conversation
Perf diff from master - unit testsHeap diff from master - unit testsHeap diff from master - scap fileBenchmarks diff from master |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2848 +/- ##
==========================================
- Coverage 75.38% 75.31% -0.08%
==========================================
Files 295 295
Lines 31306 31304 -2
Branches 4898 4925 +27
==========================================
- Hits 23601 23576 -25
- Misses 7705 7728 +23
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
LGTM label has been added. DetailsGit tree hash: 219c0ebf0ef2eb954245193cd18b2508d1a4430d |
irozzo-1A
left a comment
There was a problem hiding this comment.
Just a few clarification requests
| "invalid field info passed to pair_table_entry_adapter::write_field"); | ||
| protected: | ||
| [[nodiscard]] const void* raw_read_field(const accessor& a) const override { | ||
| auto acc = dynamic_cast<const stl_table_raw_accessor*>(&a); |
There was a problem hiding this comment.
Should we add a nullptr check here to be more defensive?
There was a problem hiding this comment.
It's a dynamic_cast only to shut up clang-tidy (this cast goes away eventually). A dynamic_cast won't work if the accessor happens to be from a table that's not from libs core (any plugin-provided table). So the only safety we get from this is against using a threadinfo field with a fdinfo and vice versa. I don't think this buys us anything for the overhead (dynamic_casts are slow) and I won't miss it when it's gone.
ASAN helps with this a little.
df73200 to
1f31570
Compare
irozzo-1A
left a comment
There was a problem hiding this comment.
I'm good with the rest of the comments, I just spot a potential UB see my comment below.
| inline extensible_table(const std::string& name): | ||
| built_in_table<KeyType>(name), | ||
| m_dynamic_fields(std::make_shared<dynamic_field_infos>()) {} |
There was a problem hiding this comment.
I think we need to initialize m_static_fields to avoid UB
| inline extensible_table(const std::string& name): | |
| built_in_table<KeyType>(name), | |
| m_dynamic_fields(std::make_shared<dynamic_field_infos>()) {} | |
| inline extensible_table(const std::string& name): | |
| built_in_table<KeyType>(name), | |
| m_static_fields(nullptr), | |
| m_dynamic_fields(std::make_shared<dynamic_field_infos>()) {} |
Signed-off-by: Grzegorz Nosek <[email protected]>
Signed-off-by: Grzegorz Nosek <[email protected]>
Signed-off-by: Grzegorz Nosek <[email protected]>
Signed-off-by: Grzegorz Nosek <[email protected]>
…ible_struct The old versions of the code are left only to make the patch readable. The next commit removes them. Signed-off-by: Grzegorz Nosek <[email protected]>
Signed-off-by: Grzegorz Nosek <[email protected]>
Note: this does cause uninitialized memory access when calling static_fields() on a table that doesn't have any, so Don't Do That for now. We'll fix it by removing static_fields() soon. Signed-off-by: Grzegorz Nosek <[email protected]>
Signed-off-by: Grzegorz Nosek <[email protected]>
You should not need to access these on an instance any more (just call ->get_field instead). Signed-off-by: Grzegorz Nosek <[email protected]>
Signed-off-by: Grzegorz Nosek <[email protected]>
This is no longer a part of the public API. Signed-off-by: Grzegorz Nosek <[email protected]>
1f31570 to
5dba7bc
Compare
|
LGTM label has been added. DetailsGit tree hash: 0a36c006f9d19889c69bff2975d98dce4564ad99 |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ekoops, gnosek, irozzo-1A The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind cleanup
Any specific area of the project related to this PR?
/area libsinsp
Does this PR require a change in the driver versions?
What this PR does / why we need it:
This PR makes the following changes to the class hierarchy involved in tables/entries:
So, if you want to build a "normal" table, with static and dynamic fields, inherit from extensible_table and extensible_struct. Otherwise (STL table adapters have neither static nor dynamic fields in the "can use the implementation" sense), inherit from built_in_table and table_entry directly and implement everything yourself.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
This is a fairly large one, so it probably works best commit by commit.
Does this PR introduce a user-facing change?: