summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--addMutex.go27
-rw-r--r--argv.go17
-rw-r--r--sortFunc.go9
-rw-r--r--sortNew.go1
5 files changed, 39 insertions, 21 deletions
diff --git a/Makefile b/Makefile
index 23d7038..068d8a1 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,6 @@
VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
-hmm: test
-
simple: build
# make -C example clean simpleMutexGlobal goimports vet
make -C example clean simpleMutexProtoc goimports vet
@@ -42,8 +40,10 @@ auto:
# rm -f auto.sort.pb.go auto.newsort.pb.go # auto.marshal.pb.go
test:
- make -C example modproto
make -C example rawproto
+ # The Go Protocol Buffers library embeds a sync.Mutex within the MessageState struct to prevent unintended shallow copies of message structs
+ # It only fails in Marshal() functions though. That is dumb.
+ make -C example modproto # THIS DOES NOT WORK. It could work however. This autogenerated code could be used to debug it.
junk:
cd example; rm -f go.* *.pb.go
diff --git a/addMutex.go b/addMutex.go
index cfd31b3..d0d8836 100644
--- a/addMutex.go
+++ b/addMutex.go
@@ -6,12 +6,29 @@ package main
import (
"fmt"
+ "io"
"os"
"strings"
"go.wit.com/log"
)
+func (pf *File) syncLock(w io.Writer) {
+ var LOCK string = pf.Bases.Lockname
+
+ fmt.Fprintln(w, "// a simple global lock")
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, "// this is needed because it seems Marshal() fails if locks are in the structs (?)")
+ fmt.Fprintln(w, "// this might just be a syntactical runtime error. notsure.")
+ fmt.Fprintln(w, "// maybe this autogen tool will help someone that actually knows what is going on inside")
+ fmt.Fprintln(w, "// go/src/google.golang.org/protobuf/proto/proto_methods.go")
+ fmt.Fprintln(w, "// go/src/google.golang.org/protobuf/proto/encode.go")
+ fmt.Fprintln(w, "// my guess is that Marshal() needs to be told to ignore sync.RWMutex as it ephemeral and can't be stored")
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, "var "+LOCK+" sync.RWMutex")
+ fmt.Fprintln(w, "")
+}
+
func (pb *Files) addMutex(f *File) error {
fullname := f.Pbfilename
log.Info("pb filename:", fullname)
@@ -47,7 +64,9 @@ func (pb *Files) addMutex(f *File) error {
if argv.Mutex {
log.Info("Adding Mutex to:", line)
fmt.Fprintln(w, line)
- fmt.Fprintln(w, "\tLock sync.RWMutex // auto-added by go.wit.com/apps/autogenpb")
+ fmt.Fprintln(w, "\tLock sync.RWMutex // auto-added by go.wit.com/apps/autogenpb") // this must be 'Lock' or Marshal() panics?
+ // fmt.Fprintln(w, "\t// auto-added by go.wit.com/apps/autogenpb")
+ // fmt.Fprintln(w, "\tsync.RWMutex")
fmt.Fprintln(w, "")
} else {
log.Info("Skipping. Mutex = false for:", line)
@@ -79,6 +98,12 @@ func (pf *File) structMatch(line string) bool {
return true
}
+ // ONLY PASS THIS IF YOU DO NOT WANT TO USE MARSHAL()
+
+ if argv.Marshal {
+ return false
+ }
+
msg = pf.Base
start = "type " + msg.Name + " struct {"
if strings.HasPrefix(line, start) {
diff --git a/argv.go b/argv.go
index 676e67e..d50dfad 100644
--- a/argv.go
+++ b/argv.go
@@ -9,14 +9,15 @@ package main
var argv args
type args struct {
- Package string `arg:"--package" help:"the package name"`
- Proto string `arg:"--proto" help:"the .proto filename"`
- Mutex bool `arg:"--mutex" default:"true" help:"insert a mutex into protoc .pb.go file"`
- Delete bool `arg:"--delete" help:"use delete with copy experiment"`
- DryRun bool `arg:"--dry-run" help:"show what would be run"`
- GoSrc string `arg:"--go-src" help:"default is ~/go/src. could be set to your go.work path"`
- GoPath string `arg:"--gopath" help:"the gopath of this repo"`
- Identify string `arg:"--identify" help:"identify file"`
+ Package string `arg:"--package" help:"the package name"`
+ Proto string `arg:"--proto" help:"the .proto filename"`
+ Mutex bool `arg:"--mutex" default:"true" help:"insert a mutex into protoc .pb.go file"`
+ Marshal bool `arg:"--marshal" default:"true" help:"if you need Marshal(), per-message Mutex's fail for some reason"`
+ Delete bool `arg:"--delete" help:"use delete with copy experiment"`
+ DryRun bool `arg:"--dry-run" help:"show what would be run"`
+ GoSrc string `arg:"--go-src" help:"default is ~/go/src. could be set to your go.work path"`
+ GoPath string `arg:"--gopath" help:"the gopath of this repo"`
+ Identify string `arg:"--identify" help:"identify file"`
}
func (a args) Description() string {
diff --git a/sortFunc.go b/sortFunc.go
index 2a5af91..e12db51 100644
--- a/sortFunc.go
+++ b/sortFunc.go
@@ -5,15 +5,6 @@ import (
"io"
)
-func (pf *File) syncLock(w io.Writer) {
- var LOCK string = pf.Bases.Lockname
-
- fmt.Fprintln(w, "// bad global lock until modifying the .pb.go file is tested")
- fmt.Fprintln(w, "// sync.RWMutex or sync.Mutex?")
- fmt.Fprintln(w, "var "+LOCK+" sync.RWMutex")
- fmt.Fprintln(w, "")
-}
-
func (msg *MsgName) iterTop(w io.Writer) {
var BASE string = msg.Name
diff --git a/sortNew.go b/sortNew.go
index b23f1aa..1de2e82 100644
--- a/sortNew.go
+++ b/sortNew.go
@@ -11,6 +11,7 @@ func (msg *MsgName) getLockname(s string) string {
if argv.Mutex {
// use the mutex lock from the modified protoc.pb.go file
return s + ".Lock"
+ // return s // causes Marshal() to panic? always use the variable name 'Lock'?
}
// a single global lock by struct name
return msg.Lockname