Comments (6)
Solution:
var lock sync.Mutex
func demo(){
__xgo_lock1 := &lock
__xgo_lock1.Lock()
__xgo_lock2 := &lock
defer __xgo_lock2.Unlock()
...
}
However if lock
itself is a pointer, then we are wrong again.
var lock *sync.Mutex
func demo(){
__xgo_lock1 := &lock
__xgo_lock1.Lock()
__xgo_lock2 := &lock
defer __xgo_lock2.Unlock()
...
}
Another simple solution is to turn off rewritting selector expr. i.e. only direct references are intercepted.
var lock sync.Mutex
func demo(){
lock1:=&lock // intercepted
lock1.Lock()
lock.Unock() // not intercepted
}
from xgo.
Another simple solution is to turn off rewritting selector expr. i.e. only direct references are intercepted.
var lock sync.Mutex func demo(){ lock1:=&lock // intercepted lock1.Lock() lock.Unock() // not intercepted }
After this, some valid case may not be intercepted:
type Config struct {
On bool
}
var cfg = &Config{}
func demo(){
if cfg.On { // cfg is not captured
// ...
}
}
from xgo.
var lock sync.Mutex
...
Will be transformed to:
Is obviously wrong.Other types include: sync.Map.
Actually this does not happen, because func names are always skipped:
func (ctx *BlockContext) traverseCallExpr(node *syntax.CallExpr, globaleNames map[string]*DeclInfo, imports map[string]string) *syntax.CallExpr {
if node == nil {
return nil
}
if ctx.ArgCallExprParent == nil {
ctx.ArgCallExprParent = make(map[syntax.Node]*syntax.CallExpr, len(node.ArgList))
for _, arg := range node.ArgList {
ctx.ArgCallExprParent[arg] = node
}
}
// NOTE: we skip capturing a name as a function
// node.Fun = ctx.traverseExpr(node.Fun, globaleNames, imports)
for i, arg := range node.ArgList {
node.ArgList[i] = ctx.traverseExpr(arg, globaleNames, imports)
}
return node
}
from xgo.
However, this causes panic:
func incrLocked_Fn() {
f := lock.Lock
f()
count = count + 1
lock.Unlock()
}
fatal error: sync: unlock of unlocked mutex
from xgo.
After this, some valid case may not be intercepted:
type Config struct { On bool } var cfg = &Config{} func demo(){ if cfg.On { // cfg is not captured // ... } }
For cases where copy is allowed, we can add a comment to the definition to tell xgo allow it:
// xgo:trap
var cfg = &Config{}
from xgo.
After this, some valid case may not be intercepted:
type Config struct { On bool } var cfg = &Config{} func demo(){ if cfg.On { // cfg is not captured // ... } }For cases where copy is allowed, we can add a comment to the definition to tell xgo allow it:
// xgo:trap var cfg = &Config{}
But since current syntax does not include comments, we cannot tell what the user want to do.
So we instead of comment ,use this:
const __xgo_trap_cfg = 1
var cfg = &Config{}
from xgo.
Related Issues (20)
- `xgo` mock `os.MkdirAll` failed HOT 3
- documentation: use Autocorrect for CJK documentation HOT 2
- bug: go1.21 with -mod=vendor fails to link, go1.19 is ok HOT 1
- bug: xgo test -args failed with malformed import path "-args": leading dash HOT 1
- Feature: test-explorer: supports test-level annotation to add custom flags
- Enhancement: make `--strace` persistent
- Enhancement: test-explorer: make Test use the same streaming output as Debug HOT 1
- Bug: --trap-stdlib fails with method that having `recover()` HOT 1
- After making --trap-stdlib default with xgo test, tests with `--strace` on windows still block. HOT 1
- Support the incoming go1.23
- Perf: xgo build gets too much slower on large projects HOT 6
- Bug: `DefaultPeerEndpointReconcilerTTL = 15 * time.Second` causes build error
- Perf: add options to dynamically decide what functions should be trapped HOT 2
- Bug: test kubernetes: mismatched types uint32 and int HOT 1
- Bug: test hugo: map[*int]string: got "PTR???:0 PTR???:1 PTR???:2", want "PTR0:0 PTR1:1 PTR2:2" HOT 3
- Bug: internal compiler error: time.Duration is not assignable to int
- Bug: test kubernetes: test/e2e_node/cpu_manager_test.go:414:48: cannot convert __xgo_pod1_414_48 (variable of type *"k8s.io/api/core/v1".Pod) to type string HOT 2
- Perf: scan what needs to be trapped
- Proposal: make `xgo test-explorer`, `xgo explorer`, and `xgo e` a shortcut for `xgo tool test-explorer` HOT 1
- CI: Adding more large golang open source projects to the CI workflow to test with xgo
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xgo.