Skip to content

Fix #12007 (partially): use RVec for RLog callbacks#25412

Open
seifreed wants to merge 1 commit intoradareorg:masterfrom
seifreed:codex/issue-12007-rlog-rvector
Open

Fix #12007 (partially): use RVec for RLog callbacks#25412
seifreed wants to merge 1 commit intoradareorg:masterfrom
seifreed:codex/issue-12007-rlog-rvector

Conversation

@seifreed
Copy link
Contributor

Partially addresses #12007.

This PR migrates the internal RLog callback storage from RList to the newer RVec implementation.

Changes:

  • Store callbacks in an RVec (less allocation per callback, simpler iteration).
  • Keep r_log_add_callback/r_log_del_callback API unchanged.
  • Add a unit test to ensure r_log_del_callback unregisters callbacks.

Note:
This does not yet integrate REvent logging.

Partially addresses radareorg#12007.

Replace the RLog callback list (RList) with an RVec-based implementation to reduce allocations and simplify callback storage, keeping the public API unchanged. Add a unit test to ensure r_log_del_callback unregisters callbacks.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 083362bf31

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

r_list_foreach (rlog->cbs, iter, cbu) {
if (cbu->cb (cbu->user, level, origin, out)) {
RLogCallbackUser *iter;
R_VEC_FOREACH (rlog->cbs, iter) {

Choose a reason for hiding this comment

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

P2 Badge Iterate callbacks over stable storage

This loop walks rlog->cbs with a raw element pointer, but callbacks are allowed to call r_log_add_callback/r_log_del_callback while handling a log message. With the new RVec backend, push_back can realloc at capacity boundaries (e.g. when growing from 8 to 9 callbacks), which invalidates iter mid-loop and can lead to use-after-free or corrupted iteration; removals can also shift elements and skip callbacks. A safer approach is to iterate by index over a captured length (or clone/snapshot the vector) before invoking user callbacks.

Useful? React with 👍 / 👎.

Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe good to fix what this comment mentions. even if its stupid to add and dlete log callbacks in the event of a logcallback execution it can happen and cause ugly crashes. i can think of two solutions:

  1. forbid that (easier, fster, more direct). just have a boolean inside rlog that tells addcallback and delcallback that we are iterating and we wont accept them to run, just return error if thats the case. this boolean can be set and unset before and after this R_VEC_FOREACH loop.

  2. add a second list of callbacks that is not iterated from here, fill it when we call add/dell a callback and sync it in an atomic way if there's any call. this will add more runtime code weight. and make log more complicated. but the resulting implementation will be more flexible.

i vote for the 1st option. what do you think? is there any relevant situation that im missing to be able to do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with option 1 to keep it simple and avoid extra runtime weight.
One detail: r_log_add_callback/r_log_del_callback currently return void, so we can’t return an error without API changes.
I propose to guard callback iteration with a boolean lock and make add/del no-op while iterating.
That prevents iterator invalidation/crashes with minimal complexity.

Copy link
Collaborator

Choose a reason for hiding this comment

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

sounds good to me, lets do that

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.

2 participants