From 21d0cc8cdf432b0eaf0bd6ea16d00070ab9dab89 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Tue, 15 Apr 2014 13:51:25 +0100 Subject: Add checks for invalid socket when creating sockets. --- lib/pure/ftpclient.nim | 2 ++ lib/pure/httpclient.nim | 1 + lib/pure/irc.nim | 2 ++ lib/pure/scgi.nim | 1 + lib/pure/selectors.nim | 1 + 5 files changed, 7 insertions(+) (limited to 'lib') diff --git a/lib/pure/ftpclient.nim b/lib/pure/ftpclient.nim index f136e0016..3bb55239b 100644 --- a/lib/pure/ftpclient.nim +++ b/lib/pure/ftpclient.nim @@ -107,6 +107,7 @@ proc ftpClient*(address: string, port = TPort(21), result.isAsync = false result.dsockConnected = false result.csock = socket() + if result.csock == InvalidSocket: osError(osLastError()) proc getDSock(ftp: PFTPClient): TSocket = if ftp.isAsync: return ftp.asyncDSock else: return ftp.dsock @@ -213,6 +214,7 @@ proc pasv(ftp: PFTPClient) = ## Negotiate a data connection. if not ftp.isAsync: ftp.dsock = socket() + if ftp.dsock == InvalidSocket: osError(osLastError()) else: ftp.asyncDSock = AsyncSocket() ftp.asyncDSock.handleRead = diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index 2a145eb89..1a0d8c5e1 100644 --- a/lib/pure/httpclient.nim +++ b/lib/pure/httpclient.nim @@ -288,6 +288,7 @@ proc request*(url: string, httpMethod = httpGET, extraHeaders = "", add(headers, "\c\L") var s = socket() + if s == InvalidSocket: osError(osLastError()) var port = sockets.TPort(80) if r.scheme == "https": when defined(ssl): diff --git a/lib/pure/irc.nim b/lib/pure/irc.nim index 83fb231f6..31a673210 100644 --- a/lib/pure/irc.nim +++ b/lib/pure/irc.nim @@ -249,6 +249,7 @@ proc reconnect*(irc: PIRC, timeout = 5000) = if secSinceReconnect < timeout: sleep(timeout - secSinceReconnect) irc.sock = socket() + if irc.sock == InvalidSocket: osError(osLastError()) irc.connect() irc.lastReconnect = epochTime() @@ -274,6 +275,7 @@ proc irc*(address: string, port: TPort = 6667.TPort, result.messageBuffer = @[] result.status = SockIdle result.sock = socket() + if result.sock == InvalidSocket: osError(osLastError()) proc processLine(irc: PIRC, line: string): TIRCEvent = if line.len == 0: diff --git a/lib/pure/scgi.nim b/lib/pure/scgi.nim index 04b77fafe..a6a0faabc 100644 --- a/lib/pure/scgi.nim +++ b/lib/pure/scgi.nim @@ -102,6 +102,7 @@ proc open*(s: var TScgiState, port = TPort(4000), address = "127.0.0.1", s.input = newString(s.buflen) # will be reused s.server = socket() + if s.server == InvalidSocket: osError(osLastError()) new(s.client) # Initialise s.client for `next` if s.server == InvalidSocket: scgiError("could not open socket") #s.server.connect(connectionName, port) diff --git a/lib/pure/selectors.nim b/lib/pure/selectors.nim index a4a7b5afd..6b5381c36 100644 --- a/lib/pure/selectors.nim +++ b/lib/pure/selectors.nim @@ -238,6 +238,7 @@ when isMainModule: sock: TSocket var sock = socket() + if sock == InvalidSocket: osError(osLastError()) #sock.setBlocking(false) sock.connect("irc.freenode.net", TPort(6667)) -- cgit 1.4.1-2-gfad0 From 6baedfe946d61c746edde89843f778e56c639843 Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Tue, 15 Apr 2014 21:22:35 +0200 Subject: Fixes typo to be able to use debugger. --- lib/system/debugger.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/system/debugger.nim b/lib/system/debugger.nim index b5cb5e9ba..af7b6d515 100644 --- a/lib/system/debugger.nim +++ b/lib/system/debugger.nim @@ -178,7 +178,7 @@ proc hash(data: pointer, size: int): THash = while s > 0: h = h !& ord(p[i]) inc(i) - cec(s) + dec(s) result = !$h proc hashGcHeader(data: pointer): THash = -- cgit 1.4.1-2-gfad0 From 941cc937d3670f71884f9cac97b71a1f86cebbad Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Tue, 15 Apr 2014 22:08:21 +0100 Subject: Fixes docgen. --- lib/pure/httpclient.nim | 2 +- lib/pure/selectors.nim | 2 +- tests/stdlib/tsockets.nim | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index 1a0d8c5e1..be06a7b8e 100644 --- a/lib/pure/httpclient.nim +++ b/lib/pure/httpclient.nim @@ -75,7 +75,7 @@ ## constructor should be used for this purpose. However, ## currently only basic authentication is supported. -import sockets, strutils, parseurl, parseutils, strtabs, base64 +import sockets, strutils, parseurl, parseutils, strtabs, base64, os import asyncnet, asyncdispatch import rawsockets diff --git a/lib/pure/selectors.nim b/lib/pure/selectors.nim index 6b5381c36..f630ba235 100644 --- a/lib/pure/selectors.nim +++ b/lib/pure/selectors.nim @@ -238,7 +238,7 @@ when isMainModule: sock: TSocket var sock = socket() - if sock == InvalidSocket: osError(osLastError()) + if sock == sockets.InvalidSocket: osError(osLastError()) #sock.setBlocking(false) sock.connect("irc.freenode.net", TPort(6667)) diff --git a/tests/stdlib/tsockets.nim b/tests/stdlib/tsockets.nim index 2b282c80d..ff566df74 100644 --- a/tests/stdlib/tsockets.nim +++ b/tests/stdlib/tsockets.nim @@ -1,4 +1,4 @@ -import sockets +import sockets, os var s: TSocket s = socket() if s == InvalidSocket: osError(osLastError()) -- cgit 1.4.1-2-gfad0 From de04c976961f8e4f63663a8e2d36d7408a270ea5 Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Wed, 16 Apr 2014 23:14:13 +0200 Subject: Improves startProcess docstring for poEvalCommand usage. --- lib/pure/osproc.nim | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index 5d6848565..ed83507d4 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -137,6 +137,14 @@ proc startProcess*(command: string, ## to `startProcess`. See the documentation of ``TProcessOption`` for the ## meaning of these flags. You need to `close` the process when done. ## + ## Note that you can't pass any `args` if you use the option + ## ``poEvalCommand``, which invokes the system shell to run the specified + ## `command`. In this situation you have to concatenate manually the contents + ## of `args` to `command` carefully escaping/quoting any special characters, + ## since it will be passed *as is* to the system shell. Each system/shell may + ## feature different escaping rules, so try to avoid this kind of shell + ## invokation if possible as it leads to non portable software. + ## ## Return value: The newly created process object. Nil is never returned, ## but ``EOS`` is raised in case of an error. @@ -633,7 +641,7 @@ elif not defined(useNimRtl): if poEvalCommand in options: sysCommand = "/bin/sh" sysArgsRaw = @[sysCommand, "-c", command] - assert args.len == 0 + assert args.len == 0, "`args` has to be empty when using poEvalCommand." else: sysCommand = command sysArgsRaw = @[command] -- cgit 1.4.1-2-gfad0 From 5859e80364448cefdeea5d8b39fc301e3f5c711d Mon Sep 17 00:00:00 2001 From: Simon Hafner Date: Wed, 16 Apr 2014 23:34:05 -0500 Subject: added an sqlite constant --- lib/wrappers/sqlite3.nim | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/wrappers/sqlite3.nim b/lib/wrappers/sqlite3.nim index 8ff1da1d1..586f763ae 100644 --- a/lib/wrappers/sqlite3.nim +++ b/lib/wrappers/sqlite3.nim @@ -90,6 +90,7 @@ const SQLITE_IGNORE* = 2 # Original from sqlite3.h: ##define SQLITE_STATIC ((void(*)(void *))0) ##define SQLITE_TRANSIENT ((void(*)(void *))-1) + SQLITE_DETERMINISTIC* = 0x800 const SQLITE_STATIC* = nil -- cgit 1.4.1-2-gfad0 From 00dc93b65b51e186b44485d9ae08daf9cef1d9ff Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Fri, 18 Apr 2014 21:50:51 +0100 Subject: Fixes collections/ttables. --- lib/pure/collections/tables.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim index 412bebeee..cd28f9af0 100644 --- a/lib/pure/collections/tables.nim +++ b/lib/pure/collections/tables.nim @@ -196,7 +196,7 @@ proc `==`*[A, B](s, t: TTable[A, B]): bool = # to use the slow route here: for key, val in s: if not hasKey(t, key): return false - if mget(t, key) != val: return false + if t[key] != val: return false return true proc indexBy*[A, B, C](collection: A, index: proc(x: B): C): TTable[C, B] = -- cgit 1.4.1-2-gfad0