trap

package
v1.0.43 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const ClosureHasFunc = true
View Source
const GenericImplIsClosure = false

Variables

View Source
var ErrAbort error = errors.New("abort trap interceptor")
View Source
var ErrSkip error = errors.New("skip trap interceptor")

Functions

func AddFuncInfoInterceptor

func AddFuncInfoInterceptor(f *core.FuncInfo, interceptor *Interceptor) func()

func AddFuncInterceptor

func AddFuncInterceptor(f interface{}, interceptor *Interceptor) func()

AddFuncInterceptor add func interceptor, allowing f to be re-entrant

func AddInterceptor

func AddInterceptor(interceptor *Interceptor) func()

AddInterceptor add a general interceptor, disallowing re-entrant

func AddInterceptorHead

func AddInterceptorHead(interceptor *Interceptor) func()

func Direct

func Direct(fn func())

Direct make a call to fn, without any trap and mock interceptors

func GetTrappingPC

func GetTrappingPC() uintptr

func Ignore

func Ignore(f interface{})

mark functions that should skip trap

func Inspect

func Inspect(f interface{}) (recvPtr interface{}, funcInfo *core.FuncInfo)

Inspect make a call to f to capture its receiver pointer if it is bound method It can be used to get the unwrapped innermost function of a method wrapper. if f is a bound method, then guaranteed that recvPtr cannot be nil

func InspectPC

func InspectPC(f interface{}) (recvPtr interface{}, funcInfo *core.FuncInfo, funcPC uintptr, trappingPC uintptr)

func Skip

func Skip()

Skip serves as mark to tell xgo not insert trap instructions for the function that calls Skip() NOTE: the function body is intenionally leave empty as trap.Skip() is just a mark that makes sense at compile time.

func WithFuncOverride

func WithFuncOverride(funcInfo *core.FuncInfo, interceptor *Interceptor, f func())

func WithInterceptor

func WithInterceptor(interceptor *Interceptor, f func())

WithInterceptor executes given f with interceptor setup. It can be used from init phase safely. it clears the interceptor after f finishes. the interceptor will be added to head, so it will gets firstly invoked. f cannot be nil.

NOTE: the implementation uses addLocalInterceptor even from init because it will be soon cleared without causing concurrent issues.

func WithOverride

func WithOverride(interceptor *Interceptor, f func())

WithOverride override local and global interceptors in current goroutine temporarily, it returns a function that can be used to cancel the override.

Types

type Interceptor

type Interceptor struct {
	Pre  func(ctx context.Context, f *core.FuncInfo, args core.Object, result core.Object) (data interface{}, err error)
	Post func(ctx context.Context, f *core.FuncInfo, args core.Object, result core.Object, data interface{}) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL