Skip to content

Commit 881424b

Browse files
authored
fix cgo issue (#104)
Signed-off-by: Loong <[email protected]>
1 parent 57dcc37 commit 881424b

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

pkg/gci/gci.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func LoadFormatGoFile(file io.FileObj, cfg config.Config) (src, dist []byte, err
129129
}
130130

131131
// do not do format if only one import
132-
if len(imports) == 1 {
132+
if len(imports) <= 1 {
133133
return src, src, nil
134134
}
135135

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sections:
2+
- Standard
3+
- Default
4+
- Prefix(github.com/daixiang0)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
// #cgo CFLAGS: -DPNG_DEBUG=1
4+
// #cgo amd64 386 CFLAGS: -DX86=1
5+
// #cgo LDFLAGS: -lpng
6+
// #include <png.h>
7+
import "C"
8+
9+
import (
10+
"fmt"
11+
12+
"github.com/daixiang0/gci"
13+
14+
g "github.com/golang"
15+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
// #cgo CFLAGS: -DPNG_DEBUG=1
4+
// #cgo amd64 386 CFLAGS: -DX86=1
5+
// #cgo LDFLAGS: -lpng
6+
// #include <png.h>
7+
import "C"
8+
9+
import (
10+
"fmt"
11+
12+
g "github.com/golang"
13+
14+
"github.com/daixiang0/gci"
15+
)

pkg/parse/parse.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"strings"
99
)
1010

11+
const C = "\"C\""
12+
1113
type GciImports struct {
1214
// original index of import group, include doc, name, path and comment
1315
Start, End int
@@ -79,14 +81,17 @@ func ParseFile(src []byte, filename string) (ImportList, int, int, error) {
7981
return nil, 0, 0, NoImportError{}
8082
}
8183

82-
var headEnd int
83-
var tailStart int
84+
var headEnd, tailStart int
8485

8586
var data ImportList
8687
for i, imp := range f.Imports {
88+
if imp.Path.Value == C {
89+
continue
90+
}
91+
8792
start, end, name := getImports(imp)
8893

89-
if i == 0 {
94+
if headEnd == 0 {
9095
headEnd = start
9196
}
9297
if i == len(f.Imports)-1 {

0 commit comments

Comments
 (0)