Fix a few deprecation warnings

This commit is contained in:
def 2015-07-11 14:39:19 +02:00
commit c50b5b62ef
32 changed files with 53 additions and 65 deletions

View file

@ -11,7 +11,7 @@
import strutils, db_sqlite, md5 import strutils, db_sqlite, md5
var db: TDbConn var db: DbConn
# We *hash* the relevant information into 128 bit hashes. This should be good # We *hash* the relevant information into 128 bit hashes. This should be good
# enough to prevent any collisions. # enough to prevent any collisions.
@ -33,7 +33,7 @@ type
const const
cb64 = [ cb64 = [
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
"O", "P", "Q", "R", "S", "T" "U", "V", "W", "X", "Y", "Z", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
"o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",

View file

@ -1,6 +1,6 @@
# Backend for a simple todo program with sqlite persistence. # Backend for a simple todo program with sqlite persistence.
# #
# Most procs dealing with a TDbConn object may raise an EDb exception. # Most procs dealing with a DbConn object may raise an EDb exception.
import db_sqlite, parseutils, strutils, times import db_sqlite, parseutils, strutils, times
@ -42,7 +42,7 @@ proc initDefaults*(params: var TPagedParams) =
params.showChecked = false params.showChecked = false
proc openDatabase*(path: string): TDbConn = proc openDatabase*(path: string): DbConn =
## Creates or opens the sqlite3 database. ## Creates or opens the sqlite3 database.
## ##
## Pass the path to the sqlite database, if the database doesn't exist it ## Pass the path to the sqlite database, if the database doesn't exist it
@ -86,7 +86,7 @@ proc getModificationDate*(todo: TTodo): Time =
return todo.modificationDate return todo.modificationDate
proc update*(todo: var TTodo; conn: TDbConn): bool = proc update*(todo: var TTodo; conn: DbConn): bool =
## Checks the database for the object and refreshes its variables. ## Checks the database for the object and refreshes its variables.
## ##
## Use this method if you (or another entity) have modified the database and ## Use this method if you (or another entity) have modified the database and
@ -112,7 +112,7 @@ proc update*(todo: var TTodo; conn: TDbConn): bool =
echo("Something went wrong selecting for id " & $todo.id) echo("Something went wrong selecting for id " & $todo.id)
proc save*(todo: var TTodo; conn: TDbConn): bool = proc save*(todo: var TTodo; conn: DbConn): bool =
## Saves the current state of text, priority and isDone to the database. ## Saves the current state of text, priority and isDone to the database.
## ##
## Returns true if the database object was updated (in which case the ## Returns true if the database object was updated (in which case the
@ -135,7 +135,7 @@ proc save*(todo: var TTodo; conn: TDbConn): bool =
# - Procs dealing directly with the database # - Procs dealing directly with the database
# #
proc addTodo*(conn: TDbConn; priority: int; text: string): TTodo = proc addTodo*(conn: DbConn; priority: int; text: string): TTodo =
## Inserts a new todo into the database. ## Inserts a new todo into the database.
## ##
## Returns the generated todo object. If there is an error EDb will be raised. ## Returns the generated todo object. If there is an error EDb will be raised.
@ -149,7 +149,7 @@ proc addTodo*(conn: TDbConn; priority: int; text: string): TTodo =
result = initFromDB(todoId, text, priority, false, currentDate) result = initFromDB(todoId, text, priority, false, currentDate)
proc deleteTodo*(conn: TDbConn; todoId: int64): int64 {.discardable.} = proc deleteTodo*(conn: DbConn; todoId: int64): int64 {.discardable.} =
## Deletes the specified todo identifier. ## Deletes the specified todo identifier.
## ##
## Returns the number of rows which were affected (1 or 0) ## Returns the number of rows which were affected (1 or 0)
@ -157,7 +157,7 @@ proc deleteTodo*(conn: TDbConn; todoId: int64): int64 {.discardable.} =
result = conn.execAffectedRows(query, $todoId) result = conn.execAffectedRows(query, $todoId)
proc getNumEntries*(conn: TDbConn): int = proc getNumEntries*(conn: DbConn): int =
## Returns the number of entries in the Todos table. ## Returns the number of entries in the Todos table.
## ##
## If the function succeeds, returns the zero or positive value, if something ## If the function succeeds, returns the zero or positive value, if something
@ -171,7 +171,7 @@ proc getNumEntries*(conn: TDbConn): int =
result = -1 result = -1
proc getPagedTodos*(conn: TDbConn; params: TPagedParams; proc getPagedTodos*(conn: DbConn; params: TPagedParams;
page = 0'i64): seq[TTodo] = page = 0'i64): seq[TTodo] =
## Returns the todo entries for a specific page. ## Returns the todo entries for a specific page.
## ##
@ -210,7 +210,7 @@ proc getPagedTodos*(conn: TDbConn; params: TPagedParams;
row[3].parseBool, Time(row[4].parseInt))) row[3].parseBool, Time(row[4].parseInt)))
proc getTodo*(conn: TDbConn; todoId: int64): ref TTodo = proc getTodo*(conn: DbConn; todoId: int64): ref TTodo =
## Returns a reference to a TTodo or nil if the todo could not be found. ## Returns a reference to a TTodo or nil if the todo could not be found.
var tempTodo: TTodo var tempTodo: TTodo
tempTodo.id = todoId tempTodo.id = todoId

View file

@ -3,7 +3,7 @@
import backend, db_sqlite, strutils, times import backend, db_sqlite, strutils, times
proc showPagedResults(conn: TDbConn; params: TPagedParams) = proc showPagedResults(conn: DbConn; params: TPagedParams) =
## Shows the contents of the database in pages of specified size. ## Shows the contents of the database in pages of specified size.
## ##
## Hmm... I guess this is more of a debug proc which should be moved outside, ## Hmm... I guess this is more of a debug proc which should be moved outside,

View file

@ -191,7 +191,7 @@ proc parseCmdLine(): TParamConfig =
abort("Used list options, but didn't specify the list command.", 10) abort("Used list options, but didn't specify the list command.", 10)
proc generateDatabaseRows(conn: TDbConn) = proc generateDatabaseRows(conn: DbConn) =
## Adds some rows to the database ignoring errors. ## Adds some rows to the database ignoring errors.
discard conn.addTodo(1, "Watch another random youtube video") discard conn.addTodo(1, "Watch another random youtube video")
discard conn.addTodo(2, "Train some starcraft moves for the league") discard conn.addTodo(2, "Train some starcraft moves for the league")
@ -209,7 +209,7 @@ proc generateDatabaseRows(conn: TDbConn) =
echo("Generated some entries, they were added to your database.") echo("Generated some entries, they were added to your database.")
proc listDatabaseContents(conn: TDbConn; listParams: TPagedParams) = proc listDatabaseContents(conn: DbConn; listParams: TPagedParams) =
## Dumps the database contents formatted to the standard output. ## Dumps the database contents formatted to the standard output.
## ##
## Pass the list/filter parameters parsed from the commandline. ## Pass the list/filter parameters parsed from the commandline.
@ -239,7 +239,7 @@ proc listDatabaseContents(conn: TDbConn; listParams: TPagedParams) =
todo.text]) todo.text])
proc deleteOneTodo(conn: TDbConn; todoId: int64) = proc deleteOneTodo(conn: DbConn; todoId: int64) =
## Deletes a single todo entry from the database. ## Deletes a single todo entry from the database.
let numDeleted = conn.deleteTodo(todoId) let numDeleted = conn.deleteTodo(todoId)
if numDeleted > 0: if numDeleted > 0:
@ -248,7 +248,7 @@ proc deleteOneTodo(conn: TDbConn; todoId: int64) =
quit("Couldn't delete todo id " & $todoId, 11) quit("Couldn't delete todo id " & $todoId, 11)
proc deleteAllTodos(conn: TDbConn) = proc deleteAllTodos(conn: DbConn) =
## Deletes all the contents from the database. ## Deletes all the contents from the database.
## ##
## Note that it would be more optimal to issue a direct DELETE sql statement ## Note that it would be more optimal to issue a direct DELETE sql statement
@ -273,7 +273,7 @@ proc deleteAllTodos(conn: TDbConn) =
echo("Deleted $1 todo entries from database." % $counter) echo("Deleted $1 todo entries from database." % $counter)
proc setTodoCheck(conn: TDbConn; todoId: int64; value: bool) = proc setTodoCheck(conn: DbConn; todoId: int64; value: bool) =
## Changes the check state of a todo entry to the specified value. ## Changes the check state of a todo entry to the specified value.
let let
newState = if value: "checked" else: "unchecked" newState = if value: "checked" else: "unchecked"
@ -293,7 +293,7 @@ proc setTodoCheck(conn: TDbConn; todoId: int64; value: bool) =
quit("Error updating todo id $1 to $2." % [$todoId, newState]) quit("Error updating todo id $1 to $2." % [$todoId, newState])
proc addTodo(conn: TDbConn; priority: int; tokens: seq[string]) = proc addTodo(conn: DbConn; priority: int; tokens: seq[string]) =
## Adds to the database a todo with the specified priority. ## Adds to the database a todo with the specified priority.
## ##
## The tokens are joined as a single string using the space character. The ## The tokens are joined as a single string using the space character. The

View file

@ -40,7 +40,7 @@ type
Actor[In, Out] = object{.pure, final.} Actor[In, Out] = object{.pure, final.}
i: Channel[Task[In, Out]] i: Channel[Task[In, Out]]
t: TThread[ptr Actor[In, Out]] t: Thread[ptr Actor[In, Out]]
PActor*[In, Out] = ptr Actor[In, Out] ## an actor PActor*[In, Out] = ptr Actor[In, Out] ## an actor
{.deprecated: [TTask: Task, TActor: Actor].} {.deprecated: [TTask: Task, TActor: Actor].}

View file

@ -39,7 +39,6 @@ when hostOS == "solaris":
import os, parseutils import os, parseutils
from times import epochTime from times import epochTime
import unsigned
when defined(ssl): when defined(ssl):
import openssl import openssl
@ -703,7 +702,7 @@ proc getHostByAddr*(ip: string): Hostent {.tags: [ReadIOEffect].} =
var s = posix.gethostbyaddr(addr(myaddr), sizeof(myaddr).Socklen, var s = posix.gethostbyaddr(addr(myaddr), sizeof(myaddr).Socklen,
cint(posix.AF_INET)) cint(posix.AF_INET))
if s == nil: if s == nil:
raiseOSError(osLastError(), $hstrerror(h_errno)) raise newException(OSError, $hstrerror(h_errno))
result.name = $s.h_name result.name = $s.h_name
result.aliases = cstringArrayToSeq(s.h_aliases) result.aliases = cstringArrayToSeq(s.h_aliases)

View file

@ -10,7 +10,6 @@
from pcre import nil from pcre import nil
import nre.private.util import nre.private.util
import tables import tables
import unsigned
from strutils import toLower, `%` from strutils import toLower, `%`
from math import ceil from math import ceil
import options import options

View file

@ -25,6 +25,8 @@
## .. include:: ../doc/regexprs.txt ## .. include:: ../doc/regexprs.txt
## ##
{.deprecated.}
import import
pcre, strutils, rtarrays pcre, strutils, rtarrays

View file

@ -456,7 +456,8 @@ proc bindAddr*(socket: AsyncSocket, port = Port(0), address = "") {.
of AF_INET6: realaddr = "::" of AF_INET6: realaddr = "::"
of AF_INET: realaddr = "0.0.0.0" of AF_INET: realaddr = "0.0.0.0"
else: else:
raiseOSError("Unknown socket address family and no address specified to bindAddr") raise newException(OSError,
"Unknown socket address family and no address specified to bindAddr")
var aiList = getAddrInfo(realaddr, port, socket.domain) var aiList = getAddrInfo(realaddr, port, socket.domain)
if bindAddr(socket.fd, aiList.ai_addr, aiList.ai_addrlen.Socklen) < 0'i32: if bindAddr(socket.fd, aiList.ai_addr, aiList.ai_addrlen.Socklen) < 0'i32:

View file

@ -1,6 +1,6 @@
#nim c -t:-march=i686 --cpu:amd64 --threads:on -d:release lockfreehash.nim #nim c -t:-march=i686 --cpu:amd64 --threads:on -d:release lockfreehash.nim
import unsigned, math, hashes import math, hashes
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
## Memory Utility Functions ## Memory Utility Functions

View file

@ -328,10 +328,10 @@ proc distinguishedSlave(w: ptr Worker) {.thread.} =
if w.q.len != 0: w.cleanFlowVars if w.q.len != 0: w.cleanFlowVars
var var
workers: array[MaxThreadPoolSize, TThread[ptr Worker]] workers: array[MaxThreadPoolSize, Thread[ptr Worker]]
workersData: array[MaxThreadPoolSize, Worker] workersData: array[MaxThreadPoolSize, Worker]
distinguished: array[MaxDistinguishedThread, TThread[ptr Worker]] distinguished: array[MaxDistinguishedThread, Thread[ptr Worker]]
distinguishedData: array[MaxDistinguishedThread, Worker] distinguishedData: array[MaxDistinguishedThread, Worker]
when defined(nimPinToCpu): when defined(nimPinToCpu):
@ -468,7 +468,7 @@ proc nimSpawn3(fn: WorkerProc; data: pointer) {.compilerProc.} =
await(gSomeReady) await(gSomeReady)
var var
distinguishedLock: TLock distinguishedLock: Lock
initLock distinguishedLock initLock distinguishedLock

View file

@ -1,5 +1,3 @@
import unsigned
type type
MersenneTwister* = object MersenneTwister* = object
mt: array[0..623, uint32] mt: array[0..623, uint32]

View file

@ -875,7 +875,8 @@ elif not defined(useNimRtl):
var error: cint var error: cint
let sizeRead = read(data.pErrorPipe[readIdx], addr error, sizeof(error)) let sizeRead = read(data.pErrorPipe[readIdx], addr error, sizeof(error))
if sizeRead == sizeof(error): if sizeRead == sizeof(error):
raiseOSError("Could not find command: '$1'. OS error: $2" % raise newException(OSError,
"Could not find command: '$1'. OS error: $2" %
[$data.sysCommand, $strerror(error)]) [$data.sysCommand, $strerror(error)])
return pid return pid

View file

@ -9,7 +9,7 @@
# TODO: Docs. # TODO: Docs.
import os, unsigned, hashes import os, hashes
when defined(linux): when defined(linux):
import posix, epoll import posix, epoll
@ -118,7 +118,7 @@ elif defined(linux):
# are therefore constantly ready. (leading to 100% CPU usage). # are therefore constantly ready. (leading to 100% CPU usage).
if epoll_ctl(s.epollFD, EPOLL_CTL_DEL, fd, nil) != 0: if epoll_ctl(s.epollFD, EPOLL_CTL_DEL, fd, nil) != 0:
raiseOSError(osLastError()) raiseOSError(osLastError())
s.fds.mget(fd).events = events s.fds[fd].events = events
else: else:
var event = createEventStruct(events, fd) var event = createEventStruct(events, fd)
if s.fds[fd].events == {}: if s.fds[fd].events == {}:
@ -129,7 +129,7 @@ elif defined(linux):
else: else:
if epoll_ctl(s.epollFD, EPOLL_CTL_MOD, fd, addr(event)) != 0: if epoll_ctl(s.epollFD, EPOLL_CTL_MOD, fd, addr(event)) != 0:
raiseOSError(osLastError()) raiseOSError(osLastError())
s.fds.mget(fd).events = events s.fds[fd].events = events
proc unregister*(s: var Selector, fd: SocketHandle) = proc unregister*(s: var Selector, fd: SocketHandle) =
if epoll_ctl(s.epollFD, EPOLL_CTL_DEL, fd, nil) != 0: if epoll_ctl(s.epollFD, EPOLL_CTL_DEL, fd, nil) != 0:
@ -229,7 +229,7 @@ elif defined(macosx) or defined(freebsd) or defined(openbsd) or defined(netbsd):
modifyKQueue(s.kqFD, fd, event, EV_ADD) modifyKQueue(s.kqFD, fd, event, EV_ADD)
for event in previousEvents-events: for event in previousEvents-events:
modifyKQueue(s.kqFD, fd, event, EV_DELETE) modifyKQueue(s.kqFD, fd, event, EV_DELETE)
s.fds.mget(fd).events = events s.fds[fd].events = events
proc unregister*(s: var Selector, fd: SocketHandle) = proc unregister*(s: var Selector, fd: SocketHandle) =
for event in s.fds[fd].events: for event in s.fds[fd].events:
@ -298,7 +298,7 @@ elif not defined(nimdoc):
proc update*(s: var Selector, fd: SocketHandle, events: set[Event]) = proc update*(s: var Selector, fd: SocketHandle, events: set[Event]) =
#if not s.fds.hasKey(fd): #if not s.fds.hasKey(fd):
# raise newException(ValueError, "File descriptor not found.") # raise newException(ValueError, "File descriptor not found.")
s.fds.mget(fd).events = events s.fds[fd].events = events
proc unregister*(s: var Selector, fd: SocketHandle) = proc unregister*(s: var Selector, fd: SocketHandle) =
s.fds.del(fd) s.fds.del(fd)

View file

@ -138,7 +138,7 @@ proc slave(w: ptr Worker) {.thread.} =
const NumThreads = 4 const NumThreads = 4
var var
workers: array[NumThreads, TThread[ptr Worker]] workers: array[NumThreads, Thread[ptr Worker]]
workersData: array[NumThreads, Worker] workersData: array[NumThreads, Worker]
proc setup() = proc setup() =

View file

@ -6,7 +6,7 @@ proc threadMain(a: int) {.thread.} =
discard discard
proc main() = proc main() =
var thread: TThread[int] var thread: Thread[int]
thread.createThread(threadMain, 0) thread.createThread(threadMain, 0)
thread.joinThreads() thread.joinThreads()

View file

@ -3,20 +3,20 @@ discard """
""" """
type type
TThreadFuncArgs[T] = object of RootObj ThreadFuncArgs[T] = object of RootObj
a: proc(): T {.thread.} a: proc(): T {.thread.}
b: proc(val: T) {.thread.} b: proc(val: T) {.thread.}
proc handleThreadFunc(arg: TThreadFuncArgs[int]){.thread.} = proc handleThreadFunc(arg: ThreadFuncArgs[int]){.thread.} =
var fn = arg.a var fn = arg.a
var callback = arg.b var callback = arg.b
var output = fn() var output = fn()
callback(output) callback(output)
proc `@||->`*[T](fn: proc(): T {.thread.}, proc `@||->`*[T](fn: proc(): T {.thread.},
callback: proc(val: T){.thread.}): TThread[TThreadFuncArgs[T]] = callback: proc(val: T){.thread.}): Thread[ThreadFuncArgs[T]] =
var thr: TThread[TThreadFuncArgs[T]] var thr: Thread[ThreadFuncArgs[T]]
var args: TThreadFuncArgs[T] var args: ThreadFuncArgs[T]
args.a = fn args.a = fn
args.b = callback args.b = callback
createThread(thr, handleThreadFunc, args) createThread(thr, handleThreadFunc, args)

View file

@ -1,5 +1,5 @@
import import
streams, md5, sockets, unsigned, streams, md5, sockets,
sg_packets, zlib_helpers, idgen sg_packets, zlib_helpers, idgen
type type
TClientType* = enum TClientType* = enum

View file

@ -1,5 +1,5 @@
import import
sockets, times, streams, streams_enh, tables, json, os, unsigned, sockets, times, streams, streams_enh, tables, json, os,
sg_packets, sg_assets, md5, server_utils, client_helpers sg_packets, sg_assets, md5, server_utils, client_helpers
var var
dirServer: PServer dirServer: PServer

View file

@ -8,10 +8,6 @@ from strutils import
`%`, `%`,
ffDecimal ffDecimal
from unsigned import
`shr`,
`and`
type type
TColor* = tuple[r, g, b, a: TR] TColor* = tuple[r, g, b, a: TR]

View file

@ -1,8 +1,6 @@
# bug #1638 # bug #1638
import unsigned
let v1 = 7 let v1 = 7
let v2 = 7'u64 let v2 = 7'u64

View file

@ -5,8 +5,6 @@ true'''
""" """
# bug 1420 # bug 1420
import unsigned
var x = 40'u32 var x = 40'u32
var y = 30'u32 var y = 30'u32
echo x > y # works echo x > y # works

View file

@ -1,6 +1,4 @@
import unsigned
# Tests unsigned literals and implicit conversion between uints and ints # Tests unsigned literals and implicit conversion between uints and ints
# Passes if it compiles # Passes if it compiles

View file

@ -1,5 +1,3 @@
import unsigned
discard """ discard """
errormsg: "number 0x123'u8 out of valid range" errormsg: "number 0x123'u8 out of valid range"
""" """

View file

@ -1,6 +1,6 @@
when false: when false:
template lock(a, b: ptr TLock; body: stmt) = template lock(a, b: ptr Lock; body: stmt) =
if cast[ByteAddress](a) < cast[ByteAddress](b): if cast[ByteAddress](a) < cast[ByteAddress](b):
pthread_mutex_lock(a) pthread_mutex_lock(a)
pthread_mutex_lock(b) pthread_mutex_lock(b)

View file

@ -11,7 +11,7 @@ type
of mLine: data: string of mLine: data: string
var var
producer, consumer: TThread[void] producer, consumer: Thread[void]
chan: TChannel[TMsg] chan: TChannel[TMsg]
printedLines = 0 printedLines = 0

View file

@ -8,7 +8,7 @@ discard """
import os import os
var var
thr: array [0..5, TThread[tuple[a, b: int]]] thr: array [0..5, Thread[tuple[a, b: int]]]
proc doNothing() = discard proc doNothing() = discard

View file

@ -8,7 +8,7 @@ discard """
import os import os
var var
thr: array [0..5, TThread[tuple[a, b: int]]] thr: array [0..5, Thread[tuple[a, b: int]]]
proc doNothing() = discard proc doNothing() = discard

View file

@ -6,7 +6,7 @@ discard """
var var
global: string = "test string" global: string = "test string"
t: TThread[void] t: Thread[void]
proc horrible() {.thread.} = proc horrible() {.thread.} =
global = "string in thread local heap!" global = "string in thread local heap!"

View file

@ -15,7 +15,7 @@ proc doAction(outC: PComm) {.thread.} =
send(outC[], i) send(outC[], i)
var var
thr: TThread[PComm] thr: Thread[PComm]
chan: TChannel[int] chan: TChannel[int]
open(chan) open(chan)

View file

@ -1,7 +1,7 @@
import db_sqlite import db_sqlite
var db: TDbConn var db: DbConn
exec(db, sql"create table blabla()") exec(db, sql"create table blabla()")

View file

@ -52,7 +52,7 @@ proc Connect*(irc: var TIRC, nick: string, host: string, port: int = 6667) =
connect(irc.Socket, host, TPort(port), TDomain.AF_INET) connect(irc.Socket, host, TPort(port), TDomain.AF_INET)
send(irc.Socket,"USER " & nick & " " & nick & " " & nick & " " & nick & "\r\L") send(irc.Socket,"USER " & nick & " " & nick & " " & nick & " " & nick & "\r\L")
send(irc.Socket,"NICK " & nick & "\r\L") send(irc.Socket,"NICK " & nick & "\r\L")
var thread: TThread[TIRC] var thread: Thread[TIRC]
createThread(thread, handleData, irc) createThread(thread, handleData, irc)
irc.Thread = thread irc.Thread = thread