Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ABI fixes for OSX; fixes #6860 #11666

Merged
merged 5 commits into from
Jul 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog_v020.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

### Breaking changes in the standard library

- Mac OS X / BSD: TSa_Family is now the ``uint8`` type, so type
conversions like ``x.sin_family = uint16 toInt(nativesockets.AF_INET)``
need to be changed into ``x.sin_family = TSa_Family toInt(nativesockets.AF_INET)``.


### Breaking changes in the compiler

Expand Down
2 changes: 2 additions & 0 deletions lib/posix/posix.nim
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ const StatHasNanoseconds* = defined(linux) or defined(freebsd) or

when defined(linux) and defined(amd64):
include posix_linux_amd64
elif (defined(macosx) or defined(bsd)) and defined(cpu64):
include posix_macos_amd64
elif defined(nintendoswitch):
include posix_nintendoswitch
else:
Expand Down
596 changes: 596 additions & 0 deletions lib/posix/posix_macos_amd64.nim

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions lib/pure/nativesockets.nim
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ proc getAddrString*(sockAddr: ptr SockAddr): string =

when defined(posix) and not defined(nimdoc):
proc makeUnixAddr*(path: string): Sockaddr_un =
result.sun_family = AF_UNIX.uint16
result.sun_family = AF_UNIX.TSa_Family
if path.len >= Sockaddr_un_path_length:
raise newException(ValueError, "socket path too long")
copyMem(addr result.sun_path, path.cstring, path.len + 1)
Expand All @@ -460,7 +460,7 @@ proc getSockName*(socket: SocketHandle): Port =
when useWinVersion:
name.sin_family = uint16(ord(AF_INET))
else:
name.sin_family = uint16(posix.AF_INET)
name.sin_family = TSa_Family(posix.AF_INET)
#name.sin_port = htons(cint16(port))
#name.sin_addr.s_addr = htonl(INADDR_ANY)
var namelen = sizeof(name).SockLen
Expand All @@ -479,7 +479,7 @@ proc getLocalAddr*(socket: SocketHandle, domain: Domain): (string, Port) =
when useWinVersion:
name.sin_family = uint16(ord(AF_INET))
else:
name.sin_family = uint16(posix.AF_INET)
name.sin_family = TSa_Family(posix.AF_INET)
var namelen = sizeof(name).SockLen
if getsockname(socket, cast[ptr SockAddr](addr(name)),
addr(namelen)) == -1'i32:
Expand All @@ -491,7 +491,7 @@ proc getLocalAddr*(socket: SocketHandle, domain: Domain): (string, Port) =
when useWinVersion:
name.sin6_family = uint16(ord(AF_INET6))
else:
name.sin6_family = uint16(posix.AF_INET6)
name.sin6_family = TSa_Family(posix.AF_INET6)
var namelen = sizeof(name).SockLen
if getsockname(socket, cast[ptr SockAddr](addr(name)),
addr(namelen)) == -1'i32:
Expand All @@ -516,7 +516,7 @@ proc getPeerAddr*(socket: SocketHandle, domain: Domain): (string, Port) =
when useWinVersion:
name.sin_family = uint16(ord(AF_INET))
else:
name.sin_family = uint16(posix.AF_INET)
name.sin_family = TSa_Family(posix.AF_INET)
var namelen = sizeof(name).SockLen
if getpeername(socket, cast[ptr SockAddr](addr(name)),
addr(namelen)) == -1'i32:
Expand All @@ -528,7 +528,7 @@ proc getPeerAddr*(socket: SocketHandle, domain: Domain): (string, Port) =
when useWinVersion:
name.sin6_family = uint16(ord(AF_INET6))
else:
name.sin6_family = uint16(posix.AF_INET6)
name.sin6_family = TSa_Family(posix.AF_INET6)
var namelen = sizeof(name).SockLen
if getpeername(socket, cast[ptr SockAddr](addr(name)),
addr(namelen)) == -1'i32:
Expand Down
2 changes: 1 addition & 1 deletion lib/pure/os.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,7 @@ proc setFilePermissions*(filename: string, permissions: set[FilePermission]) {.
if fpOthersWrite in permissions: p = p or S_IWOTH
if fpOthersExec in permissions: p = p or S_IXOTH

if chmod(filename, p) != 0: raiseOSError(osLastError())
if chmod(filename, cast[Mode](p)) != 0: raiseOSError(osLastError())
else:
when useWinUnicode:
wrapUnary(res, getFileAttributesW, filename)
Expand Down
2 changes: 1 addition & 1 deletion lib/pure/osproc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ elif not defined(useNimRtl):
proc select(readfds: var seq[Process], timeout = 500): int =
var tv: Timeval
tv.tv_sec = posix.Time(0)
tv.tv_usec = timeout * 1000
tv.tv_usec = Suseconds(timeout * 1000)

var rd: TFdSet
var m = 0
Expand Down
2 changes: 1 addition & 1 deletion lib/pure/times.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2520,7 +2520,7 @@ when not defined(JS):
when defined(macosx):
var a: Timeval
gettimeofday(a)
result = toBiggestFloat(a.tv_sec.int64) + toFloat(a.tv_usec)*0.00_0001
result = toBiggestFloat(a.tv_sec.int64) + toBiggestFloat(a.tv_usec)*0.00_0001
elif defined(posix):
var ts: Timespec
discard clock_gettime(realTimeClockId, ts)
Expand Down
2 changes: 1 addition & 1 deletion tests/async/tasyncawait.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ proc createServer(port: Port) {.async.} =
var server = createAsyncNativeSocket()
block:
var name: Sockaddr_in
name.sin_family = toInt(AF_INET).uint16
name.sin_family = typeof(name.sin_family)(toInt(AF_INET))
name.sin_port = htons(uint16(port))
name.sin_addr.s_addr = htonl(INADDR_ANY)
if bindAddr(server.SocketHandle, cast[ptr SockAddr](addr(name)),
Expand Down
2 changes: 1 addition & 1 deletion tests/async/tnewasyncudp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ proc saveReceivedPort(port: int) =

proc prepareAddress(intaddr: uint32, intport: uint16): ptr Sockaddr_in =
result = cast[ptr Sockaddr_in](alloc0(sizeof(Sockaddr_in)))
result.sin_family = toInt(nativesockets.AF_INET).uint16
result.sin_family = typeof(result.sin_family)(toInt(nativesockets.AF_INET))
result.sin_port = nativesockets.htons(intport)
result.sin_addr.s_addr = nativesockets.htonl(intaddr)

Expand Down