diff options
author | Araq <rumpf_a@web.de> | 2014-09-22 01:25:13 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-09-22 01:25:13 +0200 |
commit | 1a3b730bf5a2e5978d2dad3d8fb4c157134535e7 (patch) | |
tree | 7a7b23ba1232224ee57a91e3550b3ee4f0a8c551 | |
parent | ed3c5094845d5674279c1fd8bdf4da27a0eed561 (diff) | |
download | Nim-1a3b730bf5a2e5978d2dad3d8fb4c157134535e7.tar.gz |
made tests green
-rw-r--r-- | examples/curlex.nim | 2 | ||||
-rw-r--r-- | examples/htmlrefs.nim | 6 | ||||
-rw-r--r-- | examples/httpserver2.nim | 58 | ||||
-rw-r--r-- | examples/sdlex.nim | 28 | ||||
-rw-r--r-- | lib/pure/concurrency/threadpool.nim | 4 | ||||
-rw-r--r-- | tests/effects/teffects1.nim | 2 | ||||
-rw-r--r-- | tests/effects/tgcsafe.nim | 3 | ||||
-rw-r--r-- | todo.txt | 6 |
8 files changed, 56 insertions, 53 deletions
diff --git a/examples/curlex.nim b/examples/curlex.nim index 1d0f18ddd..9dadd9a90 100644 --- a/examples/curlex.nim +++ b/examples/curlex.nim @@ -3,7 +3,7 @@ import var hCurl = easy_init() if hCurl != nil: - discard easy_setopt(hCurl, OPT_VERBOSE, True) + discard easy_setopt(hCurl, OPT_VERBOSE, true) discard easy_setopt(hCurl, OPT_URL, "http://force7.de/nimrod") discard easy_perform(hCurl) easy_cleanup(hCurl) diff --git a/examples/htmlrefs.nim b/examples/htmlrefs.nim index 6be28d1ca..5364d61b6 100644 --- a/examples/htmlrefs.nim +++ b/examples/htmlrefs.nim @@ -12,7 +12,7 @@ if paramCount() < 1: quit("Usage: htmlrefs filename[.html]") var links = 0 # count the number of links -var filename = addFileExt(ParamStr(1), "html") +var filename = addFileExt(paramStr(1), "html") var s = newFileStream(filename, fmRead) if s == nil: quit("cannot open the file " & filename) var x: XmlParser @@ -43,12 +43,12 @@ block mainLoop: while x.kind == xmlCharData: desc.add(x.charData) x.next() - Echo(desc & ": " & link) + echo(desc & ": " & link) else: x.next() of xmlEof: break # end of file reached of xmlError: - Echo(errorMsg(x)) + echo(errorMsg(x)) x.next() else: x.next() # skip other events diff --git a/examples/httpserver2.nim b/examples/httpserver2.nim index 45350ac89..13fea9e21 100644 --- a/examples/httpserver2.nim +++ b/examples/httpserver2.nim @@ -7,19 +7,19 @@ const type TRequestMethod = enum reqGet, reqPost TServer* = object ## contains the current server state - socket: TSocket + s: Socket job: seq[TJob] TJob* = object - client: TSocket - process: PProcess + client: Socket + process: Process # --------------- output messages -------------------------------------------- -proc sendTextContentType(client: TSocket) = +proc sendTextContentType(client: Socket) = send(client, "Content-type: text/html" & wwwNL) send(client, wwwNL) -proc badRequest(client: TSocket) = +proc badRequest(client: Socket) = # Inform the client that a request it has made has a problem. send(client, "HTTP/1.0 400 BAD REQUEST" & wwwNL) sendTextContentType(client) @@ -27,19 +27,19 @@ proc badRequest(client: TSocket) = "such as a POST without a Content-Length.</p>" & wwwNL) -proc cannotExec(client: TSocket) = +proc cannotExec(client: Socket) = send(client, "HTTP/1.0 500 Internal Server Error" & wwwNL) sendTextContentType(client) send(client, "<P>Error prohibited CGI execution.</p>" & wwwNL) -proc headers(client: TSocket, filename: string) = +proc headers(client: Socket, filename: string) = # XXX could use filename to determine file type send(client, "HTTP/1.0 200 OK" & wwwNL) send(client, ServerSig) sendTextContentType(client) -proc notFound(client: TSocket, path: string) = +proc notFound(client: Socket, path: string) = send(client, "HTTP/1.0 404 NOT FOUND" & wwwNL) send(client, ServerSig) sendTextContentType(client) @@ -50,7 +50,7 @@ proc notFound(client: TSocket, path: string) = send(client, "</body></html>" & wwwNL) -proc unimplemented(client: TSocket) = +proc unimplemented(client: Socket) = send(client, "HTTP/1.0 501 Method Not Implemented" & wwwNL) send(client, ServerSig) sendTextContentType(client) @@ -62,24 +62,25 @@ proc unimplemented(client: TSocket) = # ----------------- file serving --------------------------------------------- -proc discardHeaders(client: TSocket) = skip(client) +proc discardHeaders(client: Socket) = skip(client) -proc serveFile(client: TSocket, filename: string) = +proc serveFile(client: Socket, filename: string) = discardHeaders(client) - var f: TFile + var f: File if open(f, filename): headers(client, filename) const bufSize = 8000 # != 8K might be good for memory manager var buf = alloc(bufsize) - while True: + while true: var bytesread = readBuffer(f, buf, bufsize) if bytesread > 0: var byteswritten = send(client, buf, bytesread) if bytesread != bytesWritten: + let err = osLastError() dealloc(buf) close(f) - OSError() + raiseOSError(err) if bytesread != bufSize: break dealloc(buf) close(f) @@ -89,7 +90,7 @@ proc serveFile(client: TSocket, filename: string) = # ------------------ CGI execution ------------------------------------------- -proc executeCgi(server: var TServer, client: TSocket, path, query: string, +proc executeCgi(server: var TServer, client: Socket, path, query: string, meth: TRequestMethod) = var env = newStringTable(modeCaseInsensitive) var contentLength = -1 @@ -131,9 +132,10 @@ proc executeCgi(server: var TServer, client: TSocket, path, query: string, if meth == reqPost: # get from client and post to CGI program: var buf = alloc(contentLength) - if recv(client, buf, contentLength) != contentLength: + if recv(client, buf, contentLength) != contentLength: + let err = osLastError() dealloc(buf) - OSError() + raiseOSError(err) var inp = process.inputStream inp.writeData(buf, contentLength) dealloc(buf) @@ -163,7 +165,7 @@ proc animate(server: var TServer) = # --------------- Server Setup ----------------------------------------------- -proc acceptRequest(server: var TServer, client: TSocket) = +proc acceptRequest(server: var TServer, client: Socket) = var cgi = false var query = "" var buf = "" @@ -197,7 +199,7 @@ proc acceptRequest(server: var TServer, client: TSocket) = if path[path.len-1] == '/' or existsDir(path): path = path / "index.html" - if not ExistsFile(path): + if not existsFile(path): discardHeaders(client) notFound(client, path) client.close() @@ -215,26 +217,24 @@ proc acceptRequest(server: var TServer, client: TSocket) = else: executeCgi(server, client, path, query, meth) - - when isMainModule: var port = 80 var server: TServer server.job = @[] - server.socket = socket(AF_INET) - if server.socket == InvalidSocket: OSError() - server.socket.bindAddr(port=TPort(port)) - listen(server.socket) + server.s = socket(AF_INET) + if server.s == invalidSocket: raiseOSError(osLastError()) + server.s.bindAddr(port=Port(port)) + listen(server.s) echo("server up on port " & $port) while true: # check for new new connection & handle it - var list: seq[TSocket] = @[server.socket] + var list: seq[Socket] = @[server.s] if select(list, 10) > 0: - var client: TSocket + var client: Socket new(client) - accept(server.socket, client) + accept(server.s, client) try: acceptRequest(server, client) except: @@ -244,4 +244,4 @@ when isMainModule: animate(server) # some slack for CPU sleep(10) - server.socket.close() + server.s.close() diff --git a/examples/sdlex.nim b/examples/sdlex.nim index 665affff8..3dd474d8e 100644 --- a/examples/sdlex.nim +++ b/examples/sdlex.nim @@ -9,21 +9,21 @@ var event: TEvent bgColor = colChocolate.int32 -if Init(INIT_VIDEO) != 0: +if init(INIT_VIDEO) != 0: quit "SDL failed to initialize!" -screen = SetVideoMode(640, 480, 16, SWSURFACE or ANYFORMAT) +screen = setVideoMode(640, 480, 16, SWSURFACE or ANYFORMAT) if screen.isNil: - quit($sdl.GetError()) + quit($sdl.getError()) -greeting = IMG_load("tux.png") +greeting = imgLoad("tux.png") if greeting.isNil: echo "Failed to load tux.png" else: ## convert the image to alpha and free the old one - var s = greeting.DisplayFormatAlpha() + var s = greeting.displayFormatAlpha() swap(greeting, s) - s.FreeSurface() + s.freeSurface() r.x = 0 r.y = 0 @@ -31,22 +31,22 @@ r.y = 0 block game_loop: while true: - while PollEvent(addr event) > 0: + while pollEvent(addr event) > 0: case event.kind of QUITEV: break game_loop of KEYDOWN: - if EvKeyboard(addr event).keysym.sym == K_ESCAPE: + if evKeyboard(addr event).keysym.sym == K_ESCAPE: break game_loop else: discard - discard FillRect(screen, nil, bgColor) - discard BlitSurface(greeting, nil, screen, addr r) - discard Flip(screen) + discard fillRect(screen, nil, bgColor) + discard blitSurface(greeting, nil, screen, addr r) + discard flip(screen) -greeting.FreeSurface() -screen.FreeSurface() -sdl.Quit() +greeting.freeSurface() +screen.freeSurface() +sdl.quit() ## fowl wuz here 10/2012 \ No newline at end of file diff --git a/lib/pure/concurrency/threadpool.nim b/lib/pure/concurrency/threadpool.nim index fe08e94fc..7b0593b3e 100644 --- a/lib/pure/concurrency/threadpool.nim +++ b/lib/pure/concurrency/threadpool.nim @@ -94,7 +94,7 @@ type idx: int FlowVarBase* = ref FlowVarBaseObj ## untyped base class for 'FlowVar[T]' - FlowVarBaseObj = object of TObject + FlowVarBaseObj = object of RootObj ready, usesCondVar: bool cv: CondVar #\ # for 'awaitAny' support @@ -164,7 +164,7 @@ proc cleanFlowVars(w: ptr Worker) = let q = addr(w.q) acquire(q.lock) for i in 0 .. <q.len: - GC_unref(cast[PObject](q.data[i])) + GC_unref(cast[RootRef](q.data[i])) q.len = 0 release(q.lock) signal(q.empty) diff --git a/tests/effects/teffects1.nim b/tests/effects/teffects1.nim index bbae857ea..e6d38cbc2 100644 --- a/tests/effects/teffects1.nim +++ b/tests/effects/teffects1.nim @@ -1,5 +1,5 @@ discard """ - line: 2136 + line: 2169 file: "system.nim" errormsg: "can raise an unlisted exception: ref IOError" """ diff --git a/tests/effects/tgcsafe.nim b/tests/effects/tgcsafe.nim index 87388238a..0d5109439 100644 --- a/tests/effects/tgcsafe.nim +++ b/tests/effects/tgcsafe.nim @@ -1,6 +1,7 @@ discard """ - line: 15 + line: 16 errormsg: "'mainUnsafe' is not GC-safe" + cmd: "nim $target --hints:on --threads:on $options $file" """ proc mymap(x: proc ()) = diff --git a/todo.txt b/todo.txt index 3e89ab77b..b62c48d75 100644 --- a/todo.txt +++ b/todo.txt @@ -3,13 +3,13 @@ version 0.10 - Test nimfix on various babel packages - Pegs do not work at compile-time +- deprecate recursive tuples; tuple needs laxer type checking +- string case should require an 'else' - # echo type.int version 0.9.6 ============= -- allow simple read accesses to global variables --> difficult to ensure that - no data races happen - split idetools into separate tool - split docgen into separate tool - .benign pragma @@ -63,6 +63,8 @@ version 0.9.x - implicit deref for parameter matching - overloading of '='; general lift mechanism +- allow simple read accesses to global variables --> difficult to ensure that + no data races happen - pragmas need 'bindSym' support - pragmas need re-work: 'push' is dangerous, 'hasPragma' does not work reliably with user-defined pragmas |