Skip to content

Commit 41b8dba

Browse files
committed
Previous fix broke BSD/Darwin
- Fixes #14
1 parent c97806a commit 41b8dba

File tree

14 files changed

+30
-28
lines changed

14 files changed

+30
-28
lines changed

cmd/cgrep/cgrep.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2011 The Go Authors. All rights reserved.
2-
// Copyright 2013-2023 Manpreet Singh ( [email protected] ). All rights reserved.
2+
// Copyright 2013-2025 Manpreet Singh ( [email protected] ). All rights reserved.
33
//
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.

cmd/cindex/cindex.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2011 The Go Authors. All rights reserved.
2-
// Copyright 2013-2023 Manpreet Singh ( [email protected] ). All rights reserved.
2+
// Copyright 2013-2025 Manpreet Singh ( [email protected] ). All rights reserved.
33
//
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.
@@ -339,7 +339,6 @@ func main() {
339339
if stat != nil && (stat.IsDir() || !stat.Mode().IsRegular()) {
340340
log.Fatal("Invalid index path " + master)
341341
}
342-
343342
}
344343
file := master
345344
if !*resetFlag {

cmd/csearch/csearch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2011 The Go Authors. All rights reserved.
2-
// Copyright 2013-2023 Manpreet Singh ( [email protected] ). All rights reserved.
2+
// Copyright 2013-2025 Manpreet Singh ( [email protected] ). All rights reserved.
33
//
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.

index/merge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2011 The Go Authors. All rights reserved.
2-
// Copyright 2013-2023 Manpreet Singh ( [email protected] ). All rights reserved.
2+
// Copyright 2013-2025 Manpreet Singh ( [email protected] ). All rights reserved.
33
//
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.

index/mmap_bsd.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2011 The Go Authors. All rights reserved.
2-
// Copyright 2013-2023 Manpreet Singh ( [email protected] ). All rights reserved.
2+
// Copyright 2013-2025 Manpreet Singh ( [email protected] ). All rights reserved.
33
//
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.
@@ -32,18 +32,19 @@ func mmapFile(f *os.File) mmapData {
3232
}
3333
n := int(size)
3434
if n == 0 {
35-
return mmapData{f, nil, 0}
35+
return mmapData{f, 0, nil, nil}
3636
}
3737
data, err := syscall.Mmap(int(f.Fd()), 0, (n+4095)&^4095, _PROT_READ, _MAP_SHARED)
3838
if err != nil {
3939
log.Fatalf("mmap %s: %v", f.Name(), err)
4040
}
41-
return mmapData{f, data[:n], 0}
41+
return mmapData{f, 0, data[:n], data[:]}
4242
}
4343

44-
func unmmapFile(mm *mmapData) {
45-
err := syscall.Munmap(mm.data[0:cap(mm.data)])
46-
if err != nil {
44+
func unmmapFile(mm *mmapData) error {
45+
if err := syscall.Munmap(mm.dall); err != nil {
4746
log.Println("unmmapFile:", err)
47+
return err
4848
}
49+
return mm.f.Close()
4950
}

index/mmap_linux.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2011 The Go Authors. All rights reserved.
2-
// Copyright 2013-2023 Manpreet Singh ( [email protected] ). All rights reserved.
2+
// Copyright 2013-2025 Manpreet Singh ( [email protected] ). All rights reserved.
33
//
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.
@@ -23,19 +23,20 @@ func mmapFile(f *os.File) mmapData {
2323
}
2424
n := int(size)
2525
if n == 0 {
26-
return mmapData{f, nil, 0}
26+
return mmapData{f, 0, nil, nil}
2727
}
2828
data, err := syscall.Mmap(int(f.Fd()), 0, (n+4095)&^4095, syscall.PROT_READ, syscall.MAP_SHARED)
2929
if err != nil {
3030
log.Fatalf("mmap %s: %v", f.Name(), err)
3131
}
32-
return mmapData{f, data[:n], 0}
32+
return mmapData{f, 0, data[:n], data[:]}
3333
}
3434

35-
func unmmapFile(mm *mmapData) {
35+
func unmmapFile(mm *mmapData) error {
3636
len_equal_cap := mm.data[0:cap(mm.data)] // else get EINVAL
37-
err := syscall.Munmap(len_equal_cap)
38-
if err != nil {
37+
if err := syscall.Munmap(len_equal_cap); err != nil {
3938
log.Println("unmmapFile:", err)
39+
return err
4040
}
41+
return mm.f.Close()
4142
}

index/mmap_windows.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2011 The Go Authors. All rights reserved.
2-
// Copyright 2013-2023 Manpreet Singh ( [email protected] ). All rights reserved.
2+
// Copyright 2013-2025 Manpreet Singh ( [email protected] ). All rights reserved.
33
//
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.
@@ -23,7 +23,7 @@ func mmapFile(f *os.File) mmapData {
2323
log.Fatalf("%s: too large for mmap", f.Name())
2424
}
2525
if size == 0 {
26-
return mmapData{f, nil, 0}
26+
return mmapData{f, 0, nil, nil}
2727
}
2828
h, err := syscall.CreateFileMapping(syscall.Handle(f.Fd()), nil, syscall.PAGE_READONLY, uint32(size>>32), uint32(size), nil)
2929
if err != nil {
@@ -35,7 +35,7 @@ func mmapFile(f *os.File) mmapData {
3535
log.Fatalf("MapViewOfFile %s: %v", f.Name(), err)
3636
}
3737
data := (*[1 << 30]byte)(unsafe.Pointer(addr))
38-
return mmapData{f, data[:size], uintptr(h)}
38+
return mmapData{f, uintptr(h), data[:size], data[:]}
3939
}
4040

4141
func unmmapFile(mm *mmapData) {

index/read.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2011 The Go Authors. All rights reserved.
2-
// Copyright 2013-2023 Manpreet Singh ( [email protected] ). All rights reserved.
2+
// Copyright 2013-2025 Manpreet Singh ( [email protected] ). All rights reserved.
33
//
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.
@@ -396,8 +396,9 @@ func corrupt() {
396396
// An mmapData is mmap'ed read-only data from a file.
397397
type mmapData struct {
398398
f *os.File
399-
data []byte
400399
h uintptr
400+
data []byte // [:file size]
401+
dall []byte // [:] hole mapped data, for Linux/BSD/Darwin
401402
}
402403

403404
// mmap maps the given file into memory.

index/regexp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2011 The Go Authors. All rights reserved.
2-
// Copyright 2013-2023 Manpreet Singh ( [email protected] ). All rights reserved.
2+
// Copyright 2013-2025 Manpreet Singh ( [email protected] ). All rights reserved.
33
//
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.

index/write.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2011 The Go Authors. All rights reserved.
2-
// Copyright 2013-2023 Manpreet Singh ( [email protected] ). All rights reserved.
2+
// Copyright 2013-2025 Manpreet Singh ( [email protected] ). All rights reserved.
33
//
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.

0 commit comments

Comments
 (0)