Skip to content

Commit 881424b

Browse files
authored
fix cgo issue (#104)
Signed-off-by: Loong <loong.dai@intel.com>
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sections:
2+
- Standard
3+
- Default
4+
- Prefix(github.com/daixiang0)
Lines changed: 15 additions & 0 deletions
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+
)
Lines changed: 15 additions & 0 deletions
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

Lines changed: 8 additions & 3 deletions
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)