-
Notifications
You must be signed in to change notification settings - Fork 173
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
refactor(libsinsp/threadinfo): export static fields via static method #2296
base: master
Are you sure you want to change the base?
Conversation
07d4552
to
1cf9116
Compare
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ekoops, gnosek The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Perf diff from master - unit tests
Heap diff from master - unit tests
Heap diff from master - scap file
Benchmarks diff from master
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2296 +/- ##
==========================================
+ Coverage 77.13% 77.17% +0.04%
==========================================
Files 220 222 +2
Lines 30088 30132 +44
Branches 4598 4600 +2
==========================================
+ Hits 23207 23255 +48
+ Misses 6881 6877 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Make `define_static_field` static as it is not supposed to change the calling instance; moreover, change the field parameter type to pointer to allow the function to perform its duties just using pointer arithmetic. Signed-off-by: Leonardo Di Giovanna <leonardodigiovanna1@gmail.com>
Signed-off-by: Leonardo Di Giovanna <leonardodigiovanna1@gmail.com>
1cf9116
to
782ed13
Compare
@ekoops I took a look at how offsetof manages not to hit ubsan and it turns out that at least in my stdlib headers, it's a compiler builtin:
So I guess we'd have to explicitly pass the offset rather than a pointer inside a NULL-based struct. The downside is that offsetof doesn't have any type information. In my (unrelated) experiments, the best I came up with was a macro using |
Hi @gnosek , thank you for the help! I conducted similar experiments and approximately came out with the same conclusions. I'll still try to investigate the macro path, hoping there's a possible way to avoid creating and object. I'll also explore the other suggestion and update you |
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
static_struct::define_static_field()
static and accepting a field parameter pointer instead of a reference. It leverages this change to define an additional static methodsinsp_threadinfo::get_static_fields()
that can be used for the global initialization ofs_threadinfo_static_fields
inthreadinfo.cpp
. This is useful to avoid instantiating asinsp_threadinfo
object to initializes_threadinfo_static_fields
, a preliminary step needed before isolating thesinsp_thread_manager
dependencies and passing them directly to its constructor.Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: