Skip to content

Commit

Permalink
chore: update deprecated SliceHeader usage
Browse files Browse the repository at this point in the history
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
  • Loading branch information
rustatian committed Jul 13, 2024
1 parent cc274e9 commit 487d777
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ jobs:
uses: actions/checkout@v3

- name: Run linter
uses: golangci/golangci-lint-action@v3.4.0 # Action page: <https://github.com/golangci/golangci-lint-action>
uses: golangci/golangci-lint-action@v6.0.1 # Action page: <https://github.com/golangci/golangci-lint-action>
with:
version: v1.52 # without patch version
version: v1.59 # without patch version
only-new-issues: false # show only new issues if it's a pull request
args: --timeout=10m
11 changes: 0 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,12 @@

run:
timeout: 1m
skip-dirs:
- .github
- .git
modules-download-mode: readonly
allow-parallel-runners: true

output:
format: colored-line-number # colored-line-number|line-number|json|tab|checkstyle|code-climate

linters-settings:
govet:
check-shadowing: true
revive:
confidence: 0.8
errorCode: 0
warningCode: 0
gocyclo:
min-complexity: 15
godot:
Expand All @@ -37,7 +27,6 @@ linters-settings:
range-loops: true
for-loops: true
nolintlint:
allow-leading-space: false
require-specific: true

linters: # All available linters list: <https://golangci-lint.run/usage/linters/>
Expand Down
11 changes: 0 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
27 changes: 13 additions & 14 deletions shm/posix_shm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"os"
"reflect"
"syscall"
"unsafe"

Expand Down Expand Up @@ -83,7 +82,7 @@ func NewSharedMemoryPosix(name string, size uint, permission int, flags ...Flag)
}
fmt.Println(buff)

buffW := make([]byte, 13, 13)
buffW := make([]byte, 13)
buffW[0] = 1
buffW[1] = 2
buffW[2] = 3
Expand Down Expand Up @@ -162,12 +161,12 @@ func NewSharedMemorySegment(key int, size uint, permission int, flags ...Flag) (
}

// construct slice from memory segment
sh := (*reflect.SliceHeader)(unsafe.Pointer(&segment.data))
sh.Len = int(size)
sh.Cap = int(size)
sh.Data = shmAddr
// sh := (*reflect.SliceHeader)(unsafe.Pointer(&segment.data))
// sh.Len = int(size)
// sh.Cap = int(size)
// sh.Data = shmAddr

segment.data = *(*[]byte)(unsafe.Pointer(sh))
segment.data = unsafe.Slice((*byte)(unsafe.Pointer(shmAddr)), int(size))

return segment, nil
}
Expand Down Expand Up @@ -199,12 +198,12 @@ func AttachToShmSegment(shmID int, size uint, permission int) (*SharedMemorySegm
}

// construct slice from memory segment
sh := (*reflect.SliceHeader)(unsafe.Pointer(&segment.data))
sh.Len = int(size)
sh.Cap = int(size)
sh.Data = shmAddr
// sh := (*reflect.SliceHeader)(unsafe.Pointer(&segment.data))
// sh.Len = int(size)
// sh.Cap = int(size)
// sh.Data = shmAddr

segment.data = *(*[]byte)(unsafe.Pointer(sh))
segment.data = unsafe.Slice((*byte)(unsafe.Pointer(shmAddr)), int(size))

return segment, nil
}
Expand Down Expand Up @@ -247,8 +246,8 @@ func (s *SharedMemorySegment) Read(data []byte) error {

// Detach used to detach from memory segment
func (s *SharedMemorySegment) Detach() error {
data := (*reflect.SliceHeader)(unsafe.Pointer(&s.data))
_, _, errno := syscall.Syscall(syscall.SYS_SHMDT, data.Data, 0, 0)
data := unsafe.SliceData(s.data)
_, _, errno := syscall.Syscall(syscall.SYS_SHMDT, uintptr(unsafe.Pointer(data)), 0, 0)
if errno != 0 {
return errors.New(errno.Error())
}
Expand Down
3 changes: 2 additions & 1 deletion shm/posix_shm_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build linux
//go:build !windows

package shm

Expand All @@ -13,6 +13,7 @@ import (
const testData = "hello my dear friend"

func TestNewSharedMemorySegmentPOSIX(t *testing.T) {
t.Skip("test is not ready")
shms, err := NewSharedMemoryPosix("foo", 1024 /*unix.S_IRUSR|unix.S_IWUSR*/, unix.O_CREAT, unix.O_RDWR)
if err != nil {
panic(err)
Expand Down

0 comments on commit 487d777

Please sign in to comment.