fix: Activity action/eligibility callback ABI (dropped AnalysisContext)#25
Merged
Conversation
The C core invokes an Activity's action as void(*)(void*, BNAnalysisContext*) and
its eligibility as bool(*)(void*, BNActivity*, BNAnalysisContext*) (workflow.py:
ctypes.CFUNCTYPE(None, c_void_p, POINTER(BNAnalysisContext)) and CFUNCTYPE(c_bool,
c_void_p, POINTER(BNActivity), POINTER(BNAnalysisContext))). The binding marshaled
both as Action<IntPtr> (one argument, void return), so:
- the action never received its AnalysisContext (the whole point of the callback);
- the eligibility handler received neither handle AND returned garbage bool
(reading whatever happened to be in the return register), so eligibility was
effectively random.
Mirror the established MatchDataDelegate pattern: new public delegates
ActivityAction(AnalysisContext) and ActivityEligibility(Activity, AnalysisContext),
native-shaped ActivityActionDelegate/ActivityEligibilityDelegate, and holder contexts
that wrap the raw handles via AnalysisContext/Activity.NewFromHandle (borrowed; the
wrapper owns the reference it adds). Create/CreateWithEligibility now wrap the user
delegates and root the wrappers (not the user delegates) on the instance, since the
wrapper's function pointer is what the core invokes.
BNCreateActivity/WithEligibility P/Invoke signatures are unchanged (config, ctxt,
action[, eligibility]); only the delegate marshaling was wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The C core invokes an Activity's action as
void(*)(void*, BNAnalysisContext*)and its eligibility asbool(*)(void*, BNActivity*, BNAnalysisContext*)(workflow.py). The binding marshaled both asAction<IntPtr>(one argument, void return), so:AnalysisContext— the entire point of the callback;bool(reading whatever was in the return register) — eligibility was effectively random.This made the workflow
ActivityAPI (the foundation of BN's analysis-extension model) unusable.Changes
ActivityAction(AnalysisContext)andActivityEligibility(Activity, AnalysisContext), plus native-shapedActivityActionDelegate/ActivityEligibilityDelegateand holder contexts that wrap the raw handles viaAnalysisContext/Activity.NewFromHandle(borrowed handles; the wrapper owns the reference it adds and frees it on dispose). Mirrors the establishedMatchDataDelegatepattern.Activity.Create/CreateWithEligibilitynow wrap the user delegates and root the wrappers (not the user delegates) on the instance — the wrapper's function pointer is what the core invokes.BNCreateActivity/BNCreateActivityWithEligibilityP/Invoke signatures are unchanged (config, ctxt, action[, eligibility]); only the delegate marshaling was wrong.Verification
Activitywith the corrected delegates and registers it in a cloned editable workflow — exercising the real P/Invoke path (GetFunctionPointerForDelegateover the new delegate types,BNCreateActivityWithEligibility,BNWorkflowRegisterActivity) against the core.Coverage note (honest)
The callback is only invoked when the core runs the activity during analysis, which requires opening a view under a custom workflow — a workflow-machine surface (
WorkflowMachine, view-creation-under-custom-workflow) not yet bound. The function workflow DAG is immutable and there is no switch-workflow request command, so firing the callback end-to-end is deferred to that binding. The delegate shapes here mirror Python'sctypes.CFUNCTYPEdeclarations exactly, which are the authoritative ABI spec.