Skip to content

golint: exported func returns unexported type *package._Ctype_char, which can be annoying to use #858

Closed
@adambabik

Description

@adambabik

Thank you for creating the issue!

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc).

The problem is with golint and returning C types in CGO files. In previous versions of golangci-lint, it was not a problem.

The example I reproduce the problem looks like this:

package main

// #include <stdlib.h>
import "C"
import "fmt"

// SomeFunction blah blah blah.
//export
func SomeFunction() *C.char {
	return C.CString("some string")
}

func main() {
	fmt.Println(C.GoString(SomeFunction()))
}

I also installed golint and run it on the same package with the code from above:

$ go get -u golang.org/x/lint/golint
$ golint ./testc/...
# no errors

Please include the following information:

Version of golangci-lint
$ golangci-lint --version
golangci-lint has version 1.21.0 built from 645e794 on 2019-10-15T18:15:04Z
Config file
$ cat .golangci.yml
run:
  concurrency: 4
  deadline: 1m
  issues-exit-code: 1
  tests: true
  skip-dirs:
    - static

output:
  format: colored-line-number
  print-issued-lines: true
  print-linter-name: true

linters-settings:
  errcheck:
    check-type-assertions: false
    check-blank: false
  govet:
    check-shadowing: false
  golint:
    min-confidence: 0.8
  gofmt:
    simplify: true
  gocyclo:
    min-complexity: 16
  maligned:
    suggest-new: true
  dupl:
    threshold: 50
  goconst:
    min-len: 3
    min-occurrences: 2

linters:
  disable-all: true
  enable:
    - deadcode
    - errcheck
    - gosec
    - goconst
    - gocyclo
    - gofmt
    - golint
    - gosimple
    - govet
    - ineffassign
    - misspell
    - staticcheck
    - structcheck
    - typecheck
    - unconvert
    - varcheck
    - unused
  fast: false

issues:
  exclude:
    - "composite literal uses unkeyed fields" # govet
    - "G304: Potential file inclusion via variable" # gosec
    - "G104: Errors unhandled." #gosec
Go environment
$ go version && go env
go version go1.13 darwin/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/adamb/Library/Caches/go-build"
GOENV="/Users/adamb/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/adamb/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/adamb/repos/status-go/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/g2/km2y9qqj4bbf329f2bt1xqc80000gn/T/go-build712926417=/tmp/go-build -gno-record-gcc-switches -fno-common"
Verbose output of running
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /Users/adamb/repos/status-go/testc /Users/adamb/repos/status-go /Users/adamb/repos /Users/adamb /Users /]
INFO [config_reader] Used config file .golangci.yml
INFO [lintersdb] Active 17 linters: [deadcode errcheck goconst gocyclo gofmt golint gosec gosimple govet ineffassign misspell staticcheck structcheck typecheck unconvert unused varcheck]
INFO [loader] Go packages loading at mode 575 (compiled_files|exports_file|files|types_sizes|deps|imports|name) took 255.943424ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 495.881µs
INFO [runner/goanalysis_metalinter/goanalysis] analyzers took 0s with no stages
INFO [runner/unused/goanalysis] analyzers took 0s with no stages
INFO [runner] Issues before processing: 38, after processing: 1
INFO [runner] Processors filtering stat (out/in): source_code: 1/1, autogenerated_exclude: 2/2, identifier_marker: 2/2, exclude-rules: 1/1, max_per_file_from_linter: 1/1, skip_dirs: 2/2, max_same_issues: 1/1, max_from_linter: 1/1, filename_unadjuster: 2/2, skip_files: 2/2, uniq_by_line: 1/1, diff: 1/1, path_shortener: 1/1, cgo: 2/38, path_prettifier: 2/2, exclude: 1/2, nolint: 1/1
INFO [runner] processing took 1.959982ms with stages: exclude: 1.223534ms, nolint: 292.979µs, source_code: 139.55µs, path_prettifier: 114.731µs, identifier_marker: 84.568µs, autogenerated_exclude: 49.163µs, skip_files: 15.302µs, skip_dirs: 14.817µs, cgo: 6.053µs, uniq_by_line: 5.325µs, max_same_issues: 4.188µs, max_from_linter: 3.009µs, filename_unadjuster: 2.76µs, path_shortener: 2.364µs, max_per_file_from_linter: 773ns, diff: 474ns, exclude-rules: 392ns
INFO [runner] linters took 48.948762ms with stages: goanalysis_metalinter: 46.141564ms, unused: 526.612µs
testc/main.go:8:21: exported func SomeFunction returns unexported type *github.com/status-im/status-go/testc._Ctype_char, which can be annoying to use (golint)
func SomeFunction() *C.char {
                    ^
INFO File cache stats: 1 entries of total size 182B
INFO Memory: 5 samples, avg is 68.7MB, max is 68.7MB
INFO Execution took 325.296482ms

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdependenciesRelates to an upstream dependencyfalse positiveAn error is reported when one does not existstaleNo recent correspondence or work activity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions