diff options
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/oids.nim | 3 | ||||
-rwxr-xr-x | lib/pure/osproc.nim | 26 | ||||
-rwxr-xr-x | lib/pure/sockets.nim | 22 | ||||
-rwxr-xr-x | lib/pure/times.nim | 44 |
4 files changed, 47 insertions, 48 deletions
diff --git a/lib/pure/oids.nim b/lib/pure/oids.nim index b84c3d53e..0fd1d8cd2 100644 --- a/lib/pure/oids.nim +++ b/lib/pure/oids.nim @@ -53,7 +53,8 @@ proc oidToString*(oid: TOid, str: cstring) = str[24] = '\0' var - incr, fuzz: int + incr: int + fuzz: int32 proc genOid*(): TOid = ## generates a new OID. diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index 808c0735e..6ed7e8d2c 100755 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -244,7 +244,7 @@ when defined(Windows) and not defined(useNimRtl): var s = PFileHandleStream(s) if s.atTheEnd: return 0 var br: int32 - var a = winlean.ReadFile(s.handle, buffer, bufLen, br, nil) + var a = winlean.ReadFile(s.handle, buffer, bufLen.cint, br, nil) # TRUE and zero bytes returned (EOF). # TRUE and n (>0) bytes returned (good data). # FALSE and bytes returned undefined (system error). @@ -255,7 +255,7 @@ when defined(Windows) and not defined(useNimRtl): proc hsWriteData(s: PStream, buffer: pointer, bufLen: int) = var s = PFileHandleStream(s) var bytesWritten: int32 - var a = winlean.writeFile(s.handle, buffer, bufLen, bytesWritten, nil) + var a = winlean.writeFile(s.handle, buffer, bufLen.cint, bytesWritten, nil) if a == 0: OSError() proc newFileHandleStream(handle: THandle): PFileHandleStream = @@ -293,7 +293,7 @@ when defined(Windows) and not defined(useNimRtl): proc CreatePipeHandles(Rdhandle, WrHandle: var THandle) = var piInheritablePipe: TSecurityAttributes - piInheritablePipe.nlength = SizeOF(TSecurityAttributes) + piInheritablePipe.nlength = SizeOF(TSecurityAttributes).cint piInheritablePipe.lpSecurityDescriptor = nil piInheritablePipe.Binherithandle = 1 if CreatePipe(Rdhandle, Wrhandle, piInheritablePipe, 1024) == 0'i32: @@ -313,7 +313,7 @@ when defined(Windows) and not defined(useNimRtl): success: int hi, ho, he: THandle new(result) - SI.cb = SizeOf(SI) + SI.cb = SizeOf(SI).cint if poParentStreams notin options: SI.dwFlags = STARTF_USESTDHANDLES # STARTF_USESHOWWINDOW or CreatePipeHandles(SI.hStdInput, HI) @@ -323,16 +323,16 @@ when defined(Windows) and not defined(useNimRtl): HE = HO else: CreatePipeHandles(HE, Si.hStdError) - result.inputHandle = hi - result.outputHandle = ho - result.errorHandle = he + result.inputHandle = TFileHandle(hi) + result.outputHandle = TFileHandle(ho) + result.errorHandle = TFileHandle(he) else: SI.hStdError = GetStdHandle(STD_ERROR_HANDLE) SI.hStdInput = GetStdHandle(STD_INPUT_HANDLE) SI.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE) - result.inputHandle = si.hStdInput - result.outputHandle = si.hStdOutput - result.errorHandle = si.hStdError + result.inputHandle = TFileHandle(si.hStdInput) + result.outputHandle = TFileHandle(si.hStdOutput) + result.errorHandle = TFileHandle(si.hStdError) var cmdl: cstring when false: # poUseShell in options: @@ -394,7 +394,7 @@ when defined(Windows) and not defined(useNimRtl): discard TerminateProcess(p.FProcessHandle, 0) proc waitForExit(p: PProcess, timeout: int = -1): int = - discard WaitForSingleObject(p.FProcessHandle, timeout) + discard WaitForSingleObject(p.FProcessHandle, timeout.int32) var res: int32 discard GetExitCodeProcess(p.FProcessHandle, res) @@ -424,7 +424,7 @@ when defined(Windows) and not defined(useNimRtl): ProcInfo: TProcessInformation process: THandle L: int32 - SI.cb = SizeOf(SI) + SI.cb = SizeOf(SI).cint SI.hStdError = GetStdHandle(STD_ERROR_HANDLE) SI.hStdInput = GetStdHandle(STD_INPUT_HANDLE) SI.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE) @@ -454,7 +454,7 @@ when defined(Windows) and not defined(useNimRtl): for i in 0..readfds.len()-1: rfds[i] = readfds[i].FProcessHandle - var ret = waitForMultipleObjects(readfds.len, + var ret = waitForMultipleObjects(readfds.len.int32, addr(rfds), 0'i32, timeout) case ret of WAIT_TIMEOUT: diff --git a/lib/pure/sockets.nim b/lib/pure/sockets.nim index 8c15c6adb..162e644d9 100755 --- a/lib/pure/sockets.nim +++ b/lib/pure/sockets.nim @@ -343,7 +343,7 @@ proc bindAddr*(socket: TSocket, port = TPort(0), address = "") = name.sin_port = sockets.htons(int16(port)) name.sin_addr.s_addr = sockets.htonl(INADDR_ANY) if bindSocket(socket.fd, cast[ptr TSockAddr](addr(name)), - sizeof(name)) < 0'i32: + sizeof(name).TSockLen) < 0'i32: OSError() else: var hints: TAddrInfo @@ -366,7 +366,7 @@ when false: name.sin_port = sockets.htons(int16(port)) name.sin_addr.s_addr = sockets.htonl(INADDR_ANY) if bindSocket(cint(socket), cast[ptr TSockAddr](addr(name)), - sizeof(name)) < 0'i32: + sizeof(name).TSockLen) < 0'i32: OSError() proc getSockName*(socket: TSocket): TPort = @@ -378,7 +378,7 @@ proc getSockName*(socket: TSocket): TPort = name.sin_family = posix.AF_INET #name.sin_port = htons(cint16(port)) #name.sin_addr.s_addr = htonl(INADDR_ANY) - var namelen: cint = sizeof(name) + var namelen = sizeof(name).TSockLen if getsockname(socket.fd, cast[ptr TSockAddr](addr(name)), addr(namelen)) == -1'i32: OSError() @@ -398,7 +398,7 @@ proc acceptAddr*(server: TSocket): tuple[client: TSocket, address: string] = ## **Warning:** This function might block even if socket is non-blocking ## when using SSL. var sockAddress: Tsockaddr_in - var addrLen: cint = sizeof(sockAddress) + var addrLen = sizeof(sockAddress).TSockLen var sock = accept(server.fd, cast[ptr TSockAddr](addr(sockAddress)), addr(addrLen)) @@ -477,9 +477,9 @@ proc getServByName*(name, proto: string): TServent = proc getServByPort*(port: TPort, proto: string): TServent = ## well-known getservbyport proc. when defined(Windows): - var s = winlean.getservbyport(ze(int16(port)), proto) + var s = winlean.getservbyport(ze(int16(port)).cint, proto) else: - var s = posix.getservbyport(ze(int16(port)), proto) + var s = posix.getservbyport(ze(int16(port)).cint, proto) if s == nil: OSError() result.name = $s.s_name result.aliases = cstringArrayToSeq(s.s_aliases) @@ -492,11 +492,11 @@ proc getHostByAddr*(ip: string): THostEnt = myaddr.s_addr = inet_addr(ip) when defined(windows): - var s = winlean.gethostbyaddr(addr(myaddr), sizeof(myaddr), + var s = winlean.gethostbyaddr(addr(myaddr), sizeof(myaddr).cint, cint(sockets.AF_INET)) if s == nil: OSError() else: - var s = posix.gethostbyaddr(addr(myaddr), sizeof(myaddr), + var s = posix.gethostbyaddr(addr(myaddr), sizeof(myaddr).cint, cint(posix.AF_INET)) if s == nil: raise newException(EOS, $hStrError(h_errno)) @@ -539,7 +539,7 @@ proc getHostByName*(name: string): THostEnt = proc getSockOptInt*(socket: TSocket, level, optname: int): int = ## getsockopt for integer options. var res: cint - var size: cint = sizeof(res) + var size = sizeof(res).cint if getsockopt(socket.fd, cint(level), cint(optname), addr(res), addr(size)) < 0'i32: OSError() @@ -549,7 +549,7 @@ proc setSockOptInt*(socket: TSocket, level, optname, optval: int) = ## setsockopt for integer options. var value = cint(optval) if setsockopt(socket.fd, cint(level), cint(optname), addr(value), - sizeof(value)) < 0'i32: + sizeof(value).cint) < 0'i32: OSError() proc connect*(socket: TSocket, name: string, port = TPort(0), @@ -608,7 +608,7 @@ proc connect*(socket: TSocket, name: string, port = TPort(0), of AF_INET: s.sin_family = posix.AF_INET of AF_INET6: s.sin_family = posix.AF_INET6 else: nil - if connect(socket.fd, cast[ptr TSockAddr](addr(s)), sizeof(s)) < 0'i32: + if connect(socket.fd, cast[ptr TSockAddr](addr(s)), sizeof(s).cint) < 0'i32: OSError() proc connectAsync*(socket: TSocket, name: string, port = TPort(0), diff --git a/lib/pure/times.nim b/lib/pure/times.nim index e6163ad8c..622c2655f 100755 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -111,7 +111,7 @@ type ## in the range 0 to 23. monthday*: range[1..31] ## The day of the month, in the range 1 to 31. month*: TMonth ## The current month. - year*: int ## The current year. + year*: range[-10_000..10_000] ## The current year. weekday*: TWeekDay ## The current day of the week. yearday*: range[0..365] ## The number of days since January 1, ## in the range 0 to 365. @@ -122,7 +122,7 @@ type timezone*: int ## The offset of the (non-DST) timezone in seconds ## west of UTC. - TTimeInterval* = object + TTimeInterval* {.pure.} = object ## a time interval miliseconds*: int ## The number of miliseconds seconds*: int ## The number of seconds minutes*: int ## The number of minutes @@ -150,11 +150,11 @@ proc `$` *(timeInfo: TTimeInfo): string proc `$` *(time: TTime): string ## converts a calendar time to a string representation. -proc `-` *(a, b: TTime): int64{. +proc `-`*(a, b: TTime): int64 {. rtl, extern: "ntDiffTime".} ## computes the difference of two calendar times. Result is in seconds. -proc `<` * (a, b: TTime): bool {. +proc `<`*(a, b: TTime): bool {. rtl, extern: "ntLtTime".} = ## returns true iff ``a < b``, that is iff a happened before b. result = a - b < 0 @@ -175,8 +175,8 @@ proc getStartMilsecs*(): int {.deprecated.} ## get the miliseconds from the start of the program. **Deprecated since ## version 0.8.10.** Use ``epochTime`` or ``cpuTime`` instead. -proc newInterval*(miliseconds, seconds, minutes, hours, days, months, - years: int = 0): TTimeInterval = +proc initInterval*(miliseconds, seconds, minutes, hours, days, months, + years: int = 0): TTimeInterval = ## creates a new ``TTimeInterval``. result.miliseconds = miliseconds result.seconds = seconds @@ -188,23 +188,20 @@ proc newInterval*(miliseconds, seconds, minutes, hours, days, months, proc isLeapYear(year: int): bool = if year mod 400 == 0: - return true + return true elif year mod 100 == 0: - return false + return false elif year mod 4 == 0: - return true + return true else: - return false + return false proc getDaysInMonth(month: TMonth, year: int): int = # http://www.dispersiondesign.com/articles/time/number_of_days_in_a_month - if month == mFeb: # Feb - if isLeapYear(year): - result = 29 - else: - result = 28 - elif month in [mApr, mJun, mSep, mNov]: result = 30 - else: result = 31 + case month + of mFeb: result = if isLeapYear(year): 29 else: 28 + of mApr, mJun, mSep, mNov: result = 30 + else: result = 31 proc calculateSeconds(a: TTimeInfo, interval: TTimeInterval): float = var anew = a @@ -228,9 +225,10 @@ proc calculateSeconds(a: TTimeInfo, interval: TTimeInterval): float = proc `+`*(a: TTimeInfo, interval: TTimeInterval): TTimeInfo = ## adds ``interval`` time. ## - ## **Note:** This has been only briefly tested and it may not be very accurate. + ## **Note:** This has been only briefly tested and it may not be + ## very accurate. let t = timeInfoToTime(a) - var secs = calculateSeconds(a, interval) + let secs = calculateSeconds(a, interval) if a.tzname == "UTC": result = getGMTime(TTime(float(t) + secs)) else: @@ -242,7 +240,7 @@ proc `-`*(a: TTimeInfo, interval: TTimeInterval): TTimeInfo = ## **Note:** This has been only briefly tested, it is inaccurate especially ## when you subtract so much that you reach the Julian calendar. let t = timeInfoToTime(a) - var secs = calculateSeconds(a, interval) + let secs = calculateSeconds(a, interval) if a.tzname == "UTC": result = getGMTime(TTime(float(t) - secs)) else: @@ -329,7 +327,7 @@ when not defined(ECMAScript): proc timeInfoToTM(t: TTimeInfo): structTM = const - weekDays: array [TWeekDay, int] = [1, 2, 3, 4, 5, 6, 0] + weekDays: array [TWeekDay, int8] = [1'i8,2'i8,3'i8,4'i8,5'i8,6'i8,0'i8] result.second = t.second result.minute = t.minute result.hour = t.hour @@ -362,13 +360,13 @@ when not defined(ECMAScript): var a = t result = tmToTimeInfo(localtime(addr(a))[], true) # copying is needed anyway to provide reentrancity; thus - # the convertion is not expensive + # the conversion is not expensive proc getGMTime(t: TTime): TTimeInfo = var a = t result = tmToTimeInfo(gmtime(addr(a))[], false) # copying is needed anyway to provide reentrancity; thus - # the convertion is not expensive + # the conversion is not expensive proc TimeInfoToTime(timeInfo: TTimeInfo): TTime = var cTimeInfo = timeInfo # for C++ we have to make a copy, |