Skip to content

Commit

Permalink
Merge pull request #1561 from goplus/main
Browse files Browse the repository at this point in the history
v1.1.13
  • Loading branch information
xushiwei authored Nov 26, 2023
2 parents 0ce26cc + 83ab913 commit 9536d28
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 314 deletions.
2 changes: 1 addition & 1 deletion cl/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4710,7 +4710,7 @@ func main() {
}
`
if runtime.GOOS == "windows" {
expected = strings.Replace(expected, "../", `..\foo\`, -1)
expected = strings.Replace(expected, "../", `../foo/`, -1)
}
gopClTestEx(t, &conf, "main", src, expected)
}
2 changes: 1 addition & 1 deletion cl/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func offsetFileLine(ctx *blockCtx, file string) string {
file = filepath.Join(ctx.fileLineWorkingDir, file)
}
if ret, err := filepath.Rel(ctx.fileLineRoot, file); err == nil {
return ret
return filepath.ToSlash(ret)
}
return file
}
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ require (
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sys v0.14.0 // indirect
)

retract (
v1.1.12
)
15 changes: 9 additions & 6 deletions load.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,16 @@ func LoadDir(dir string, conf *Config, genTestPkg bool, promptGenGo ...bool) (ou

var pkgTest *ast.Package
var clConf = &cl.Config{
WorkingDir: dir,
Fset: fset,
Importer: imp,
LookupClass: mod.LookupClass,
LookupPub: c2go.LookupPub(mod),
FileLineRoot: mod.Root(),
WorkingDir: dir,
Fset: fset,
Importer: imp,
LookupClass: mod.LookupClass,
LookupPub: c2go.LookupPub(mod),
}
if mod.IsValid() {
clConf.FileLineRoot = mod.Root()
}

for name, pkg := range pkgs {
if strings.HasSuffix(name, "_test") {
if pkgTest != nil {
Expand Down
129 changes: 129 additions & 0 deletions x/fakenet/conn.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package fakenet

import (
"io"
"net"
"sync"
"time"
)

// NewConn returns a net.Conn built on top of the supplied reader and writer.
// It decouples the read and write on the conn from the underlying stream
// to enable Close to abort ones that are in progress.
// It's primary use is to fake a network connection from stdin and stdout.
func NewConn(name string, in io.ReadCloser, out io.WriteCloser) net.Conn {
c := &fakeConn{
name: name,
reader: newFeeder(in.Read),
writer: newFeeder(out.Write),
in: in,
out: out,
}
go c.reader.run()
go c.writer.run()
return c
}

type fakeConn struct {
name string
reader *connFeeder
writer *connFeeder
in io.ReadCloser
out io.WriteCloser
}

type fakeAddr string

// connFeeder serializes calls to the source function (io.Reader.Read or
// io.Writer.Write) by delegating them to a channel. This also allows calls to
// be intercepted when the connection is closed, and cancelled early if the
// connection is closed while the calls are still outstanding.
type connFeeder struct {
source func([]byte) (int, error)
input chan []byte
result chan feedResult
mu sync.Mutex
closed bool
done chan struct{}
}

type feedResult struct {
n int
err error
}

func (c *fakeConn) Close() error {
c.reader.close()
c.writer.close()
c.in.Close()
c.out.Close()
return nil
}

func (c *fakeConn) Read(b []byte) (n int, err error) { return c.reader.do(b) }
func (c *fakeConn) Write(b []byte) (n int, err error) { return c.writer.do(b) }
func (c *fakeConn) LocalAddr() net.Addr { return fakeAddr(c.name) }
func (c *fakeConn) RemoteAddr() net.Addr { return fakeAddr(c.name) }
func (c *fakeConn) SetDeadline(t time.Time) error { return nil }
func (c *fakeConn) SetReadDeadline(t time.Time) error { return nil }
func (c *fakeConn) SetWriteDeadline(t time.Time) error { return nil }
func (a fakeAddr) Network() string { return "fake" }
func (a fakeAddr) String() string { return string(a) }

func newFeeder(source func([]byte) (int, error)) *connFeeder {
return &connFeeder{
source: source,
input: make(chan []byte),
result: make(chan feedResult),
done: make(chan struct{}),
}
}

func (f *connFeeder) close() {
f.mu.Lock()
if !f.closed {
f.closed = true
close(f.done)
}
f.mu.Unlock()
}

func (f *connFeeder) do(b []byte) (n int, err error) {
// send the request to the worker
select {
case f.input <- b:
case <-f.done:
return 0, io.EOF
}
// get the result from the worker
select {
case r := <-f.result:
return r.n, r.err
case <-f.done:
return 0, io.EOF
}
}

func (f *connFeeder) run() {
var b []byte
for {
// wait for an input request
select {
case b = <-f.input:
case <-f.done:
return
}
// invoke the underlying method
n, err := f.source(b)
// send the result back to the requester
select {
case f.result <- feedResult{n: n, err: err}:
case <-f.done:
return
}
}
}
5 changes: 1 addition & 4 deletions x/jsonrpc2/jsonrpc2test/jsonrpc2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import (
func TestNetPipe(t *testing.T) {
jsonrpc2.SetDebug(jsonrpc2.DbgFlagCall)
ctx := context.Background()
listener, err := jsonrpc2test.NetPipeListener(ctx)
if err != nil {
t.Fatal(err)
}
listener := jsonrpc2test.NetPipeListener()
cases.Test(t, ctx, listener, jsonrpc2.HeaderFramer(), true)
}
4 changes: 2 additions & 2 deletions x/jsonrpc2/jsonrpc2test/pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ import (
// It is only possibly to connect to it using the Dialer returned by the
// Dialer method, each call to that method will generate a new pipe the other
// side of which will be returned from the Accept call.
func NetPipeListener(ctx context.Context) (jsonrpc2.Listener, error) {
func NetPipeListener() jsonrpc2.Listener {
return &netPiper{
done: make(chan struct{}),
dialed: make(chan io.ReadWriteCloser),
}, nil
}
}

// netPiper is the implementation of Listener build on top of net.Pipes.
Expand Down
32 changes: 0 additions & 32 deletions x/jsonrpc2/stdio/jsonrpc2_test.go

This file was deleted.

Loading

0 comments on commit 9536d28

Please sign in to comment.