From ac4dad51939affe9dfc6eb2b5f8212cbc40d1804 Mon Sep 17 00:00:00 2001 From: Ruslan Mustakov Date: Wed, 10 Feb 2016 14:53:46 +0600 Subject: Added nnkTemplateDef and nnkConverterDef to RoutineNodes set --- lib/core/macros.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 872d4848d..eda793620 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -601,7 +601,7 @@ proc last*(node: NimNode): NimNode {.compileTime.} = node[ Date: Wed, 10 Feb 2016 19:19:01 +0600 Subject: Added pragmas to ignore warnings in Nim-generated files for gcc, clang, vcc --- lib/nimbase.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib') diff --git a/lib/nimbase.h b/lib/nimbase.h index bba5ac023..374c0ceb1 100644 --- a/lib/nimbase.h +++ b/lib/nimbase.h @@ -23,6 +23,30 @@ __clang__ #ifndef NIMBASE_H #define NIMBASE_H +/* ------------ ignore typical warnings in Nim-generated files ------------- */ +#if defined(__GNUC__) || defined(__clang__) +# pragma GCC diagnostic ignored "-Wwritable-strings" +# pragma GCC diagnostic ignored "-Winvalid-noreturn" +# pragma GCC diagnostic ignored "-Wformat" +# pragma GCC diagnostic ignored "-Wlogical-not-parentheses" +# pragma GCC diagnostic ignored "-Wlogical-op-parentheses" +# pragma GCC diagnostic ignored "-Wshadow" +# pragma GCC diagnostic ignored "-Wunused-function" +# pragma GCC diagnostic ignored "-Wunused-variable" +# pragma GCC diagnostic ignored "-Winvalid-offsetof" +# pragma GCC diagnostic ignored "-Wtautological-compare" +# pragma GCC diagnostic ignored "-Wswitch-bool" +# pragma GCC diagnostic ignored "-Wmacro-redefined" +# pragma GCC diagnostic ignored "-Wincompatible-pointer-types-discards-qualifiers" +#endif + +#if defined(_MSC_VER) +# pragma warning(disable: 4005 4100 4101 4189 4191 4200 4244 4293 4296 4309) +# pragma warning(disable: 4310 4365 4456 4477 4514 4574 4611 4668 4702 4706) +# pragma warning(disable: 4710 4711 4774 4800 4820 4996) +#endif +/* ------------------------------------------------------------------------- */ + #if defined(__GNUC__) # define _GNU_SOURCE 1 #endif -- cgit 1.4.1-2-gfad0 From 867285c5a9645679caf9614f2bf0ffce20d40ac5 Mon Sep 17 00:00:00 2001 From: def Date: Thu, 11 Feb 2016 22:45:03 +0100 Subject: Rename THANDLE to Handle to fix deprecation warnings --- lib/impure/rdstdin.nim | 2 +- lib/windows/winlean.nim | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/impure/rdstdin.nim b/lib/impure/rdstdin.nim index 15137b436..469bb69c5 100644 --- a/lib/impure/rdstdin.nim +++ b/lib/impure/rdstdin.nim @@ -55,7 +55,7 @@ when defined(Windows): event*: KEY_EVENT_RECORD safetyBuffer: array[0..5, DWORD] - proc readConsoleInputW*(hConsoleInput: THANDLE, lpBuffer: var INPUTRECORD, + proc readConsoleInputW*(hConsoleInput: HANDLE, lpBuffer: var INPUTRECORD, nLength: uint32, lpNumberOfEventsRead: var uint32): WINBOOL{. stdcall, dynlib: "kernel32", importc: "ReadConsoleInputW".} diff --git a/lib/windows/winlean.nim b/lib/windows/winlean.nim index d12c661d6..d00964a6d 100644 --- a/lib/windows/winlean.nim +++ b/lib/windows/winlean.nim @@ -309,9 +309,9 @@ when useWinUnicode: stdcall, dynlib: "kernel32", importc: "FindNextFileW".} else: proc findFirstFileA*(lpFileName: cstring, - lpFindFileData: var WIN32_FIND_DATA): THANDLE {. + lpFindFileData: var WIN32_FIND_DATA): Handle {. stdcall, dynlib: "kernel32", importc: "FindFirstFileA".} - proc findNextFileA*(hFindFile: THANDLE, + proc findNextFileA*(hFindFile: Handle, lpFindFileData: var WIN32_FIND_DATA): int32 {. stdcall, dynlib: "kernel32", importc: "FindNextFileA".} @@ -685,7 +685,7 @@ else: proc createFileA*(lpFileName: cstring, dwDesiredAccess, dwShareMode: DWORD, lpSecurityAttributes: pointer, dwCreationDisposition, dwFlagsAndAttributes: DWORD, - hTemplateFile: THANDLE): THANDLE {. + hTemplateFile: Handle): Handle {. stdcall, dynlib: "kernel32", importc: "CreateFileA".} proc deleteFileA*(pathName: cstring): int32 {. importc: "DeleteFileA", dynlib: "kernel32", stdcall.} @@ -715,10 +715,10 @@ proc createFileMappingW*(hFile: Handle, stdcall, dynlib: "kernel32", importc: "CreateFileMappingW".} when not useWinUnicode: - proc createFileMappingA*(hFile: THANDLE, + proc createFileMappingA*(hFile: Handle, lpFileMappingAttributes: pointer, flProtect, dwMaximumSizeHigh: DWORD, - dwMaximumSizeLow: DWORD, lpName: cstring): THANDLE {. + dwMaximumSizeLow: DWORD, lpName: cstring): Handle {. stdcall, dynlib: "kernel32", importc: "CreateFileMappingA".} proc unmapViewOfFile*(lpBaseAddress: pointer): WINBOOL {.stdcall, -- cgit 1.4.1-2-gfad0 From 9aceaa0c0557d12c6d3b0521aa04595862f6162b Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Sat, 13 Feb 2016 21:49:07 +0200 Subject: Added -Wpragmas ignore --- lib/nimbase.h | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/nimbase.h b/lib/nimbase.h index 374c0ceb1..40ea6c66a 100644 --- a/lib/nimbase.h +++ b/lib/nimbase.h @@ -25,6 +25,7 @@ __clang__ /* ------------ ignore typical warnings in Nim-generated files ------------- */ #if defined(__GNUC__) || defined(__clang__) +# pragma GCC diagnostic ignored "-Wpragmas" # pragma GCC diagnostic ignored "-Wwritable-strings" # pragma GCC diagnostic ignored "-Winvalid-noreturn" # pragma GCC diagnostic ignored "-Wformat" -- cgit 1.4.1-2-gfad0 From 0290bc224042ae8fb943dd55f76c046163f5062e Mon Sep 17 00:00:00 2001 From: Anatoly Galiulin Date: Wed, 17 Feb 2016 17:05:20 +0600 Subject: Added reentrant locks module to stdlib --- lib/core/rlocks.nim | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/system/syslocks.nim | 14 +++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 lib/core/rlocks.nim (limited to 'lib') diff --git a/lib/core/rlocks.nim b/lib/core/rlocks.nim new file mode 100644 index 000000000..3316ffcd4 --- /dev/null +++ b/lib/core/rlocks.nim @@ -0,0 +1,50 @@ +# +# +# Nim's Runtime Library +# (c) Copyright 2015 Andreas Rumpf +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +## This module contains Nim's support for reentrant locks + +include "system/syslocks" + +type + RLock* = SysLock ## Nim lock, re-entrant + +proc initRLock*(lock: var RLock) {.inline.} = + ## Initializes the given lock. + when defined(posix): + var a: SysLockAttr + initSysLockAttr(a) + setSysLockType(a, SysLockType_Reentrant()) + initSysLock(lock, a.addr) + else: + initSysLock(lock) + +proc deinitRLock*(lock: var RLock) {.inline.} = + ## Frees the resources associated with the lock. + deinitSys(lock) + +proc tryAcquire*(lock: var RLock): bool = + ## Tries to acquire the given lock. Returns `true` on success. + result = tryAcquireSys(lock) + +proc acquire*(lock: var RLock) = + ## Acquires the given lock. + acquireSys(lock) + +proc release*(lock: var RLock) = + ## Releases the given lock. + releaseSys(lock) + +template withRLock*(lock: var RLock, code: stmt): stmt = + ## Acquires the given lock and then executes the code + block: + acquire(lock) + defer: + release(lock) + {.locks: [lock].}: + code diff --git a/lib/system/syslocks.nim b/lib/system/syslocks.nim index 7a113b9d4..907a6c609 100644 --- a/lib/system/syslocks.nim +++ b/lib/system/syslocks.nim @@ -75,12 +75,24 @@ else: type SysLock {.importc: "pthread_mutex_t", pure, final, header: "".} = object + SysLockAttr {.importc: "pthread_mutexattr_t", pure, final + header: "".} = object SysCond {.importc: "pthread_cond_t", pure, final, header: "".} = object + SysLockType = distinct cint + + proc SysLockType_Reentrant: SysLockType = + {.emit: "`result` = PTHREAD_MUTEX_RECURSIVE;".} - proc initSysLock(L: var SysLock, attr: pointer = nil) {. + proc initSysLock(L: var SysLock, attr: ptr SysLockAttr = nil) {. importc: "pthread_mutex_init", header: "", noSideEffect.} + proc initSysLockAttr(a: var SysLockAttr) {. + importc: "pthread_mutexattr_init", header: "", noSideEffect.} + + proc setSysLockType(a: var SysLockAttr, t: SysLockType) {. + importc: "pthread_mutexattr_settype", header: "", noSideEffect.} + proc acquireSys(L: var SysLock) {.noSideEffect, importc: "pthread_mutex_lock", header: "".} proc tryAcquireSysAux(L: var SysLock): cint {.noSideEffect, -- cgit 1.4.1-2-gfad0 From c1028b336322ad09cda83ba2cf6e1d9ea2a84bc5 Mon Sep 17 00:00:00 2001 From: Anatoly Galiulin Date: Wed, 17 Feb 2016 20:44:48 +0600 Subject: Added fixes from Araq's comments --- lib/core/rlocks.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/core/rlocks.nim b/lib/core/rlocks.nim index 3316ffcd4..2327153c0 100644 --- a/lib/core/rlocks.nim +++ b/lib/core/rlocks.nim @@ -1,7 +1,7 @@ # # # Nim's Runtime Library -# (c) Copyright 2015 Andreas Rumpf +# (c) Copyright 2015 Anatoly Galiulin # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -40,7 +40,7 @@ proc release*(lock: var RLock) = ## Releases the given lock. releaseSys(lock) -template withRLock*(lock: var RLock, code: stmt): stmt = +template withRLock*(lock: var RLock, code: untyped): untyped = ## Acquires the given lock and then executes the code block: acquire(lock) -- cgit 1.4.1-2-gfad0 From b0eeacf71e33a0084e2e30636155efa43517def2 Mon Sep 17 00:00:00 2001 From: Anatoly Galiulin Date: Thu, 18 Feb 2016 09:46:34 +0600 Subject: Added rlocks module to documentation and news.txt --- doc/lib.txt | 3 +++ lib/core/rlocks.nim | 6 +++--- lib/system/syslocks.nim | 2 +- web/news.txt | 6 ++++++ web/website.ini | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/doc/lib.txt b/doc/lib.txt index 90cf36240..5ff6de7fd 100644 --- a/doc/lib.txt +++ b/doc/lib.txt @@ -46,6 +46,9 @@ Core * `locks `_ Locks and condition variables for Nim. +* `rlocks `_ + Reentrant locks for Nim. + * `macros `_ Contains the AST API and documentation of Nim for writing macros. diff --git a/lib/core/rlocks.nim b/lib/core/rlocks.nim index 2327153c0..14f04592b 100644 --- a/lib/core/rlocks.nim +++ b/lib/core/rlocks.nim @@ -1,13 +1,13 @@ # # # Nim's Runtime Library -# (c) Copyright 2015 Anatoly Galiulin +# (c) Copyright 2016 Anatoly Galiulin # # See the file "copying.txt", included in this # distribution, for details about the copyright. # -## This module contains Nim's support for reentrant locks +## This module contains Nim's support for reentrant locks. include "system/syslocks" @@ -41,7 +41,7 @@ proc release*(lock: var RLock) = releaseSys(lock) template withRLock*(lock: var RLock, code: untyped): untyped = - ## Acquires the given lock and then executes the code + ## Acquires the given lock and then executes the code. block: acquire(lock) defer: diff --git a/lib/system/syslocks.nim b/lib/system/syslocks.nim index 907a6c609..a91a5e7d4 100644 --- a/lib/system/syslocks.nim +++ b/lib/system/syslocks.nim @@ -7,7 +7,7 @@ # distribution, for details about the copyright. # -## Low level system locks and condition vars. +# Low level system locks and condition vars. when defined(Windows): type diff --git a/web/news.txt b/web/news.txt index d8c591d53..bf665c85c 100644 --- a/web/news.txt +++ b/web/news.txt @@ -11,6 +11,12 @@ Changes affecting backwards compatibility - ``--out`` and ``--nimcache`` command line arguments are now relative to current directory. Previously they were relative to project directory. +Library Additions +----------------- + +- The rlocks module has been added providing reentrant lock synchronization + primitive + 2016-01-27 Nim in Action is now available! ========================================== diff --git a/web/website.ini b/web/website.ini index 46564d19f..d1f8a04bf 100644 --- a/web/website.ini +++ b/web/website.ini @@ -54,7 +54,7 @@ srcdoc2: "pure/collections/tables;pure/collections/sets;pure/collections/lists" srcdoc2: "pure/collections/intsets;pure/collections/queues;pure/encodings" srcdoc2: "pure/events;pure/collections/sequtils;pure/cookies" srcdoc2: "pure/memfiles;pure/subexes;pure/collections/critbits" -srcdoc2: "deprecated/pure/asyncio;deprecated/pure/actors;core/locks;pure/oids;pure/endians;pure/uri" +srcdoc2: "deprecated/pure/asyncio;deprecated/pure/actors;core/locks;core/rlocks;pure/oids;pure/endians;pure/uri" srcdoc2: "pure/nimprof;pure/unittest;packages/docutils/highlite" srcdoc2: "packages/docutils/rst;packages/docutils/rstast" srcdoc2: "packages/docutils/rstgen;pure/logging;pure/options;pure/asyncdispatch;pure/asyncnet" -- cgit 1.4.1-2-gfad0 From a27e4b519306f7bb883a1d32fbb39564c4bfee65 Mon Sep 17 00:00:00 2001 From: cheatfate Date: Thu, 18 Feb 2016 15:38:08 +0200 Subject: bug fix: repr() of sized enums presentation Issue #3864 --- lib/system/repr.nim | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/system/repr.nim b/lib/system/repr.nim index 986994203..7f18ed31c 100644 --- a/lib/system/repr.nim +++ b/lib/system/repr.nim @@ -76,6 +76,7 @@ proc reprEnum(e: int, typ: PNimType): string {.compilerRtl.} = # we read an 'int' but this may have been too large, so mask the other bits: let e = if typ.size == 1: e and 0xff elif typ.size == 2: e and 0xffff + elif typ.size == 4: e and 0xffffffff else: e # XXX we need a proper narrowing based on signedness here #e and ((1 shl (typ.size*8)) - 1) -- cgit 1.4.1-2-gfad0 From 378c904131f267fc9281f89b8df6ee0c2dcb008e Mon Sep 17 00:00:00 2001 From: Ruslan Mustakov Date: Thu, 18 Feb 2016 23:01:43 +0600 Subject: Added --noCppExceptions switch --- compiler/ccgexprs.nim | 6 ++++-- compiler/commands.nim | 4 ++++ compiler/options.nim | 1 + doc/advopt.txt | 1 + lib/system/excpt.nim | 2 +- web/news.txt | 7 +++++++ 6 files changed, 18 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index fcc36e4fd..1a5334a98 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -2111,8 +2111,10 @@ proc expr(p: BProc, n: PNode, d: var TLoc) = initLocExpr(p, n.sons[0], a) of nkAsmStmt: genAsmStmt(p, n) of nkTryStmt: - if p.module.compileToCpp: genTryCpp(p, n, d) - else: genTry(p, n, d) + if p.module.compileToCpp and optNoCppExceptions notin gGlobalOptions: + genTryCpp(p, n, d) + else: + genTry(p, n, d) of nkRaiseStmt: genRaiseStmt(p, n) of nkTypeSection: # we have to emit the type information for object types here to support diff --git a/compiler/commands.nim b/compiler/commands.nim index 8dacebd83..2622d64f4 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -619,6 +619,10 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) = cAssembler = nameToCC(arg) if cAssembler notin cValidAssemblers: localError(info, errGenerated, "'$1' is not a valid assembler." % [arg]) + of "nocppexceptions": + expectNoArg(switch, arg, pass, info) + incl(gGlobalOptions, optNoCppExceptions) + defineSymbol("noCppExceptions") else: if strutils.find(switch, '.') >= 0: options.setConfigVar(switch, arg) else: invalidCmdLineOption(pass, switch, info) diff --git a/compiler/options.nim b/compiler/options.nim index 82d18e242..29cdd96fb 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -66,6 +66,7 @@ type # please make sure we have under 32 options # also: generate header file optIdeDebug # idetools: debug mode optIdeTerse # idetools: use terse descriptions + optNoCppExceptions # use C exception handling even with CPP TGlobalOptions* = set[TGlobalOption] TCommands* = enum # Nim's commands # **keep binary compatible** diff --git a/doc/advopt.txt b/doc/advopt.txt index 02849498f..02aada4fb 100644 --- a/doc/advopt.txt +++ b/doc/advopt.txt @@ -69,6 +69,7 @@ Advanced options: --putenv:key=value set an environment variable --NimblePath:PATH add a path for Nimble support --noNimblePath deactivate the Nimble path + --noCppExceptions use default exception handling with C++ backend --excludePath:PATH exclude a path from the list of search paths --dynlibOverride:SYMBOL marks SYMBOL so that dynlib:SYMBOL has no effect and can be statically linked instead; diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim index df28c1493..8d1e04b8d 100644 --- a/lib/system/excpt.nim +++ b/lib/system/excpt.nim @@ -216,7 +216,7 @@ proc raiseExceptionAux(e: ref Exception) = if not localRaiseHook(e): return if globalRaiseHook != nil: if not globalRaiseHook(e): return - when defined(cpp): + when defined(cpp) and not defined(noCppExceptions): if e[] of OutOfMemError: showErrorMessage(e.name) quitOrDebug() diff --git a/web/news.txt b/web/news.txt index bf665c85c..d854347a5 100644 --- a/web/news.txt +++ b/web/news.txt @@ -17,6 +17,13 @@ Library Additions - The rlocks module has been added providing reentrant lock synchronization primitive +Compiler Additions +------------------ + +- Added a new ``--noCppExceptions`` switch that allows to use default exception + handling (no ``throw`` or ``try``/``catch`` generated) when compiling to C++ + code + 2016-01-27 Nim in Action is now available! ========================================== -- cgit 1.4.1-2-gfad0