Skip to content

Commit

Permalink
track down crash
Browse files Browse the repository at this point in the history
Signed-off-by: Achille Roussel <[email protected]>
  • Loading branch information
achille-roussel committed Sep 20, 2023
1 parent 5510e58 commit 746a291
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions compiler/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/sys v0.12.0 // indirect
)
Expand Down
2 changes: 2 additions & 0 deletions compiler/go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
Expand Down
13 changes: 13 additions & 0 deletions compiler/testdata/coroutine.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,19 @@ func Range10ClosureHeterogenousCapture() {

n := 0
x := func() bool {
print("---",
"\n n = ", n, " @", &n,
"\n a = ", a, " @", &a,
"\n b = ", b, " @", &b,
"\n c = ", c, " @", &c,
"\n d = ", d, " @", &d,
"\n e = ", e, " @", &e,
"\n f = ", f, " @", &f,
"\n g = ", g, " @", &g,
"\n h = ", h, " @", &h,
"\n i = ", i, " @", &i,
"\n---\n",
)
var v int
switch n {
case 0:
Expand Down
14 changes: 14 additions & 0 deletions compiler/testdata/coroutine_durable.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion coroutine_durable.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

package coroutine

import "github.com/stealthrocket/coroutine/internal/serde"
import (
"fmt"

"github.com/stealthrocket/coroutine/internal/serde"
)

type serializedCoroutine struct {
entry func()
Expand Down Expand Up @@ -52,6 +56,7 @@ func (c *Context[R, S]) MarshalAppend(b []byte) ([]byte, error) {
// the number of bytes that were read in order to reconstruct the
// context.
func (c *Context[R, S]) Unmarshal(b []byte) (int, error) {
fmt.Println("UNMARSHAL:", &b[0])
start := len(b)
v, b := serde.Deserialize(b)
s := v.(*serializedCoroutine)
Expand Down
10 changes: 9 additions & 1 deletion internal/serde/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"reflect"
"unsafe"

"github.com/davecgh/go-spew/spew"

Check failure on line 10 in internal/serde/reflect.go

View workflow job for this annotation

GitHub Actions / Test

no required module provides package github.com/davecgh/go-spew/spew; to add it:
"github.com/stealthrocket/coroutine/types"
)

Expand Down Expand Up @@ -288,6 +289,7 @@ func deserializePointedAt(d *Deserializer, t reflect.Type) reflect.Value {
ep := e.UnsafePointer()
d.store(id, ep)
DeserializeAny(d, t, ep)
fmt.Printf("deserializePointedAt: %p => %v (%s)\n", ep, e.Elem().Interface(), t)
return e
}

Expand Down Expand Up @@ -465,6 +467,11 @@ func serializeFunc(s *Serializer, t reflect.Type, p unsafe.Pointer) {

if fn.Closure != nil {
t := fn.Closure
v := reflect.NewAt(t, p)

fmt.Println("SERIALIZE")
spew.Dump(v.Interface())

serializeStructFields(s, p, t.NumField()-1, func(i int) reflect.StructField {
return t.Field(i + 1)
})
Expand Down Expand Up @@ -496,7 +503,8 @@ func deserializeFunc(d *Deserializer, t reflect.Type, p unsafe.Pointer) {
deserializeStructFields(d, closure, t.NumField()-1, func(i int) reflect.StructField {
return t.Field(i + 1)
})
//fmt.Printf("%#v\n", v.Interface())
fmt.Print("DESERIALIZE")
spew.Dump(v.Interface())

*(*unsafe.Pointer)(p) = closure
} else {
Expand Down

0 comments on commit 746a291

Please sign in to comment.