all: remove GODEBUG=cgocheck=0 scaffolding

This commit is contained in:
Sebastien Binet 2018-01-06 21:02:28 +01:00
parent 9240dfc24a
commit 2d30b71938
5 changed files with 1 additions and 97 deletions

View File

@ -15,8 +15,6 @@ sudo: required
before_install:
- sudo apt-get install libffi-dev python-cffi
- export PATH=$HOME/gopath/bin:$PATH
# temporary workaround for go-python/gopy#83
- export GODEBUG=cgocheck=0
notifications:
email:

View File

@ -6,9 +6,6 @@ gopy
`gopy` generates (and compiles) a `CPython` extension module from a `go` package.
**WARNING** `gopy` is currently not compatible with `Go>=1.6` and its improved `CGo` rules as documented in [cmd/cgo](https://golang.org/cmd/cgo/#hdr-Passing_pointers).
To be able to run a `CPython` module generated with `Go>=1.6`, one needs to export `GODEBUG=cgocheck=0` to disable the `CGo` rules runtime checker. (see [issue 83](https://github.com/go-python/gopy/issues/83) for more informations.)
## Installation
```sh

View File

@ -8,41 +8,10 @@ import (
"fmt"
"go/token"
"go/types"
"runtime"
"strings"
)
const (
checkGoVersionImport = `"strconv"
"strings"
"os"
`
checkGoVersion = "_cgopy_CheckGoVersion()"
checkGoVersionDef = `
func _cgopy_CheckGoVersion() {
godebug := os.Getenv("GODEBUG")
cgocheck := -1
var err error
if godebug != "" {
const prefix = "cgocheck="
for _, option := range strings.Split(godebug, ",") {
if !strings.HasPrefix(option, prefix) {
continue
}
cgocheck, err = strconv.Atoi(option[len(prefix):])
if err != nil {
cgocheck = -1
fmt.Fprintf(os.Stderr, "gopy: invalid cgocheck value %q (expected an integer)\n", option)
}
}
}
if cgocheck != 0 {
fmt.Fprintf(os.Stderr, "gopy: GODEBUG=cgocheck=0 should be set for Go>=1.6\n")
}
}
`
goPreamble = `// Package main is an autogenerated binder stub for package %[1]s.
// gopy gen -lang=go %[1]s
//
@ -1137,13 +1106,7 @@ func (g *goGen) genPreamble() {
panic(err)
}
version := runtime.Version()
major, minor, _ := getGoVersion(version)
if major >= 1 && minor >= 6 {
g.Printf(goPreamble, n, pkgcfg, pkgimport, checkGoVersionImport, checkGoVersionDef, checkGoVersion)
} else {
g.Printf(goPreamble, n, pkgcfg, pkgimport, "", "", "")
}
g.Printf(goPreamble, n, pkgcfg, pkgimport, "", "", "")
}
func (g *goGen) tupleString(tuple []*Var) string {

View File

@ -13,8 +13,6 @@ import (
"os/exec"
"regexp"
"sort"
"strconv"
"strings"
)
func isErrorType(typ types.Type) bool {
@ -146,15 +144,3 @@ func getPkgConfig(vers int) (string, error) {
return pkgcfg, nil
}
func getGoVersion(version string) (int64, int64, error) {
version_regex := regexp.MustCompile(`^go((\d+)(\.(\d+))*)`)
match := version_regex.FindStringSubmatch(version)
if match == nil {
return -1, -1, fmt.Errorf("gopy: invalid Go version information: %q", version)
}
version_info := strings.Split(match[1], ".")
major, _ := strconv.ParseInt(version_info[0], 10, 0)
minor, _ := strconv.ParseInt(version_info[1], 10, 0)
return major, minor, nil
}

View File

@ -1,40 +0,0 @@
// Copyright 2017 The go-python 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 bind
import (
"errors"
"testing"
)
func TestGetGoVersion(t *testing.T) {
for _, tt := range []struct {
info string
major int64
minor int64
err error
}{
{"go1.5", 1, 5, nil},
{"go1.6", 1, 6, nil},
{"go1.7", 1, 7, nil},
{"go1.8", 1, 8, nil},
{"gcc4", -1, -1, errors.New("gopy: invalid Go version information: \"gcc4\"")},
{"1.8go", -1, -1, errors.New("gopy: invalid Go version information: \"1.8go\"")},
{"llvm", -1, -1, errors.New("gopy: invalid Go version information: \"llvm\"")},
} {
major, minor, err := getGoVersion(tt.info)
if major != tt.major {
t.Errorf("getGoVersion(%s): expected major %d, actual %d", tt.info, tt.major, major)
}
if minor != tt.minor {
t.Errorf("getGoVersion(%s): expected major %d, actual %d", tt.info, tt.minor, minor)
}
if err != nil && err.Error() != tt.err.Error() {
t.Errorf("getGoVersion(%s): expected err %s, actual %s", tt.info, tt.err, err)
}
}
}