-
Notifications
You must be signed in to change notification settings - Fork 21
feat: support generic funcs #185
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
base: main
Are you sure you want to change the base?
Changes from all commits
05bac68
63a9420
c318de6
6ffc5d1
58aa8e3
4f3724f
561c467
73bafcd
74ff92a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,4 +71,32 @@ func MyHook1After(ictx inst.HookContext) { | |
| println("After MyStruct.Example()") | ||
| } | ||
|
|
||
| func MyHookRecvBefore(ictx inst.HookContext, recv, _ interface{}) { | ||
| println("GenericRecvExample before hook") | ||
| } | ||
|
|
||
| func MyHookRecvAfter(ictx inst.HookContext, _ interface{}) { | ||
| println("GenericRecvExample after hook") | ||
| } | ||
|
|
||
| func MyHookGenericBefore(ictx inst.HookContext, _, _ interface{}) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add usages of HookContext methods inside Hook function to exercise their functionalities
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, done in 74ff92a These integration tests should be refactored once golden file approach is moved to /test/integration |
||
| println("GenericExample before hook") | ||
| fmt.Printf("[Generic] Function: %s.%s\n", ictx.GetPackageName(), ictx.GetFuncName()) | ||
| fmt.Printf("[Generic] Param count: %d\n", ictx.GetParamCount()) | ||
| fmt.Printf("[Generic] Skip call: %v\n", ictx.IsSkipCall()) | ||
| for i := 0; i < ictx.GetParamCount(); i++ { | ||
| fmt.Printf("[Generic] Param[%d]: %v\n", i, *ictx.GetParam(i).(*int)) | ||
| } | ||
| ictx.SetData("test-data") | ||
| } | ||
|
|
||
| func MyHookGenericAfter(ictx inst.HookContext, _ interface{}) { | ||
| println("GenericExample after hook") | ||
| fmt.Printf("[Generic] Data from Before: %v\n", ictx.GetData()) | ||
| fmt.Printf("[Generic] Return value count: %d\n", ictx.GetReturnValCount()) | ||
| for i := 0; i < ictx.GetReturnValCount(); i++ { | ||
| fmt.Printf("[Generic] Return[%d]: %v\n", i, *ictx.GetReturnVal(i).(*int)) | ||
| } | ||
| } | ||
|
|
||
| func BeforeUnderscore(ictx inst.HookContext, _ int, _ float32) {} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add test case func (recv *Recv[T]) GenericExample
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test added.
There were some extra changes needed to support this case:
This new code would require some new 👀 63a9420