diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-01-02 11:00:31 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-01-02 11:00:31 +0100 |
| commit | 18d8f06226e7d1ef4c6f2023f246f7cb0cf8783d (patch) | |
| tree | ff87af7374c84e0d62280859486075bf1dff5b08 /exports/disco.go | |
| parent | 240cf78bdf9f8f9e383d5fa45b04fd6f1fb1ecc5 (diff) | |
Exports: Use unsafe.Slice for C slice conversion
This is possible now as we require Go 1.17
Diffstat (limited to 'exports/disco.go')
| -rw-r--r-- | exports/disco.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/exports/disco.go b/exports/disco.go index 51de2f5..e18df3d 100644 --- a/exports/disco.go +++ b/exports/disco.go @@ -69,7 +69,7 @@ func getCPtrDiscoOrganizations( organizationsPtr := (**C.discoveryOrganization)( C.malloc(totalOrganizations * C.size_t(unsafe.Sizeof(uintptr(0)))), ) - cOrganizations := (*[1<<30 - 1]*C.discoveryOrganization)(unsafe.Pointer(organizationsPtr))[:totalOrganizations:totalOrganizations] + cOrganizations := unsafe.Slice(organizationsPtr, totalOrganizations) index := 0 for _, organization := range organizations.List { cOrganization := getCPtrDiscoOrganization(state, &organization) @@ -112,7 +112,7 @@ func getCPtrDiscoServers( serversPtr := (**C.discoveryServer)( C.malloc(totalServers * C.size_t(unsafe.Sizeof(uintptr(0)))), ) - cServers := (*[1<<30 - 1]*C.discoveryServer)(unsafe.Pointer(serversPtr)) + cServers := unsafe.Slice(serversPtr, totalServers) index := 0 for _, server := range servers.List { cServer := getCPtrDiscoServer(state, &server) @@ -147,7 +147,7 @@ func freeDiscoServer(cServer *C.discoveryServer) { //export FreeDiscoServers func FreeDiscoServers(cServers *C.discoveryServers) { if cServers.total_servers > 0 { - servers := (*[1<<30 - 1]*C.discoveryServer)(unsafe.Pointer(cServers.servers))[:cServers.total_servers:cServers.total_servers] + servers := unsafe.Slice(cServers.servers, cServers.total_servers) for i := C.size_t(0); i < cServers.total_servers; i++ { freeDiscoServer(servers[i]) } @@ -159,7 +159,7 @@ func FreeDiscoServers(cServers *C.discoveryServers) { //export FreeDiscoOrganizations func FreeDiscoOrganizations(cOrganizations *C.discoveryOrganizations) { if cOrganizations.total_organizations > 0 { - organizations := (*[1<<30 - 1]*C.discoveryOrganization)(unsafe.Pointer(cOrganizations.organizations))[:cOrganizations.total_organizations:cOrganizations.total_organizations] + organizations := unsafe.Slice(cOrganizations.organizations, cOrganizations.total_organizations) for i := C.size_t(0); i < cOrganizations.total_organizations; i++ { freeDiscoOrganization(organizations[i]) } |
