Skip to content
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

Fix type patching #879

Merged
merged 2 commits into from
Nov 25, 2024
Merged

Fix type patching #879

merged 2 commits into from
Nov 25, 2024

Conversation

cpunion
Copy link
Contributor

@cpunion cpunion commented Nov 25, 2024

Fix #877

package main

import (
	"io"
	"os"
	"sync"
	"unsafe"

	llsync "github.com/goplus/llgo/c/pthread/sync"
)

type L struct {
	mu sync.Mutex
	s  string
	i  int
	w  io.Writer
}

func main() {
	l := &L{s: "hello", i: 123, w: os.Stdout}
	println("sizeof(L):", unsafe.Sizeof(L{}))
	println("sizeof(sync.Mutex):", unsafe.Sizeof(sync.Mutex{}))
	println("sizeof(llsync.Mutex):", unsafe.Sizeof(llsync.Mutex{}))
	println("l:", l, "l.s:", l.s, "l.i:", l.i, "l.w:", l.w)
	l.mu.Lock()
	println("locked")
	println("l:", l, "l.s:", l.s, "l.i:", l.i, "l.w:", l.w)
	l.w.Write([]byte(l.s))
	l.w.Write([]byte("\n"))
	l.mu.Unlock()
}

Outputs on macOS arm64:

sizeof(L): 48
sizeof(sync.Mutex): 8
sizeof(llsync.Mutex): 64
l: 0x102649a10 l.s: hello l.i: 123 l.w: (0x10264e8d0,0x10264e990)
locked
l: 0x102649a10 l.s: hello l.i: 123 l.w: (0x10264e8d0,0x10264e990)
hello

Outputs on Ubuntu arm64:

l: 0x4000163360 l.out: (0x84de58,0x4000120010)
sizeof(L): 48
sizeof(sync.Mutex): 8
sizeof(llsync.Mutex): 48
l: 0xe6b592ab7f60 l.s: hello l.i: 123 l.w: (0xe6b592aa17b0,0xe6b592aa1870)
locked
l: 0xe6b592ab7f60 l.s: hello l.i: 123 l.w: (0xe6b592aa17b0,0xe6b592aa1870)
hello

Copy link

codecov bot commented Nov 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.54%. Comparing base (2f5c033) to head (3f795e4).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #879   +/-   ##
=======================================
  Coverage   95.54%   95.54%           
=======================================
  Files          22       22           
  Lines        6237     6246    +9     
=======================================
+ Hits         5959     5968    +9     
  Misses        246      246           
  Partials       32       32           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@xushiwei xushiwei merged commit 93245ac into goplus:main Nov 25, 2024
10 checks passed
@cpunion cpunion deleted the fix-type-patching branch November 25, 2024 04:06
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.

sync.Mutex.Lock crashes on Linux
2 participants