From 95682cdfb7596466a30e610c01bd0c8fad39e877 Mon Sep 17 00:00:00 2001 From: Samadi van Koten Date: Mon, 28 Nov 2016 23:02:30 +0000 Subject: Remove docgen.nim's dependency on things being in path compiler/docgen.nim relied heavily on $lib/packages/docutils being in path at compile-time. While this works fine when building Nim itself, things start breaking when using compiler as a nimble package. --- compiler/docgen.nim | 6 ++++-- compiler/nim.cfg | 2 -- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'compiler') diff --git a/compiler/docgen.nim b/compiler/docgen.nim index 76b36d796..211544924 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -13,8 +13,10 @@ import ast, strutils, strtabs, options, msgs, os, ropes, idents, - wordrecg, syntaxes, renderer, lexer, rstast, rst, rstgen, times, highlite, - importer, sempass2, json, xmltree, cgi, typesrenderer, astalgo + wordrecg, syntaxes, renderer, lexer, packages/docutils/rstast, + packages/docutils/rst, packages/docutils/rstgen, times, + packages/docutils/highlite, importer, sempass2, json, xmltree, cgi, + typesrenderer, astalgo type TSections = array[TSymKind, Rope] diff --git a/compiler/nim.cfg b/compiler/nim.cfg index 0ff128ba3..853ae7e00 100644 --- a/compiler/nim.cfg +++ b/compiler/nim.cfg @@ -4,8 +4,6 @@ hint[XDeclaredButNotUsed]:off path:"llvm" path:"$projectPath/.." -path:"$lib/packages/docutils" - define:booting #import:"$projectpath/testability" -- cgit 1.4.1-2-gfad0 From c743b2969f9e7c922cbeadab983a84389953fb24 Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 29 Nov 2016 20:21:56 +0100 Subject: closure types get names; refs #4332 --- compiler/lambdalifting.nim | 33 +++++++++++++++++---------------- compiler/lowerings.nim | 4 ++++ 2 files changed, 21 insertions(+), 16 deletions(-) (limited to 'compiler') diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim index 36ad2e0a6..692d9265b 100644 --- a/compiler/lambdalifting.nim +++ b/compiler/lambdalifting.nim @@ -139,10 +139,10 @@ proc createStateField(iter: PSym): PSym = result = newSym(skField, getIdent(":state"), iter, iter.info) result.typ = createStateType(iter) -proc createEnvObj(owner: PSym): PType = +proc createEnvObj(owner: PSym; info: TLineInfo): PType = # YYY meh, just add the state field for every closure for now, it's too # hard to figure out if it comes from a closure iterator: - result = createObj(owner, owner.info) + result = createObj(owner, info) rawAddField(result, createStateField(owner)) proc getIterResult(iter: PSym): PSym = @@ -296,18 +296,19 @@ This is why need to store the 'ownerToType' table and use it during .closure'fication. """ -proc getEnvTypeForOwner(c: var DetectionPass; owner: PSym): PType = +proc getEnvTypeForOwner(c: var DetectionPass; owner: PSym; + info: TLineInfo): PType = result = c.ownerToType.getOrDefault(owner.id) if result.isNil: result = newType(tyRef, owner) - let obj = createEnvObj(owner) + let obj = createEnvObj(owner, info) rawAddSon(result, obj) c.ownerToType[owner.id] = result -proc createUpField(c: var DetectionPass; dest, dep: PSym) = - let refObj = c.getEnvTypeForOwner(dest) # getHiddenParam(dest).typ +proc createUpField(c: var DetectionPass; dest, dep: PSym; info: TLineInfo) = + let refObj = c.getEnvTypeForOwner(dest, info) # getHiddenParam(dest).typ let obj = refObj.lastSon - let fieldType = c.getEnvTypeForOwner(dep) #getHiddenParam(dep).typ + let fieldType = c.getEnvTypeForOwner(dep, info) #getHiddenParam(dep).typ if refObj == fieldType: localError(dep.info, "internal error: invalid up reference computed") @@ -347,10 +348,10 @@ Consider: """ -proc addClosureParam(c: var DetectionPass; fn: PSym) = +proc addClosureParam(c: var DetectionPass; fn: PSym; info: TLineInfo) = var cp = getEnvParam(fn) let owner = if fn.kind == skIterator: fn else: fn.skipGenericOwner - let t = c.getEnvTypeForOwner(owner) + let t = c.getEnvTypeForOwner(owner, info) if cp == nil: cp = newSym(skParam, getIdent(paramName), fn, fn.info) incl(cp.flags, sfFromGeneric) @@ -367,7 +368,7 @@ proc detectCapturedVars(n: PNode; owner: PSym; c: var DetectionPass) = if s.kind in {skProc, skMethod, skConverter, skIterator} and s.typ != nil and s.typ.callConv == ccClosure: # this handles the case that the inner proc was declared as # .closure but does not actually capture anything: - addClosureParam(c, s) + addClosureParam(c, s, n.info) c.somethingToDo = true let innerProc = isInnerProc(s) @@ -379,7 +380,7 @@ proc detectCapturedVars(n: PNode; owner: PSym; c: var DetectionPass) = if ow == owner: if owner.isIterator: c.somethingToDo = true - addClosureParam(c, owner) + addClosureParam(c, owner, n.info) if interestingIterVar(s): if not c.capturedVars.containsOrIncl(s.id): let obj = getHiddenParam(owner).typ.lastSon @@ -403,11 +404,11 @@ proc detectCapturedVars(n: PNode; owner: PSym; c: var DetectionPass) = # mark 'owner' as taking a closure: c.somethingToDo = true markAsClosure(owner, n) - addClosureParam(c, owner) + addClosureParam(c, owner, n.info) #echo "capturing ", n.info # variable 's' is actually captured: if interestingVar(s) and not c.capturedVars.containsOrIncl(s.id): - let obj = c.getEnvTypeForOwner(ow).lastSon + let obj = c.getEnvTypeForOwner(ow, n.info).lastSon #getHiddenParam(owner).typ.lastSon addField(obj, s) # create required upFields: @@ -428,8 +429,8 @@ proc detectCapturedVars(n: PNode; owner: PSym; c: var DetectionPass) = let up = w.skipGenericOwner #echo "up for ", w.name.s, " up ", up.name.s markAsClosure(w, n) - addClosureParam(c, w) # , ow - createUpField(c, w, up) + addClosureParam(c, w, n.info) # , ow + createUpField(c, w, up, n.info) w = up of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit, nkTemplateDef, nkTypeSection: @@ -793,7 +794,7 @@ proc liftLambdas*(fn: PSym, body: PNode; tooEarly: var bool): PNode = var d = initDetectionPass(fn) detectCapturedVars(body, fn, d) if not d.somethingToDo and fn.isIterator: - addClosureParam(d, fn) + addClosureParam(d, fn, body.info) d.somethingToDo = true if d.somethingToDo: var c = initLiftingPass(fn) diff --git a/compiler/lowerings.nim b/compiler/lowerings.nim index 6a8eccb83..af074e428 100644 --- a/compiler/lowerings.nim +++ b/compiler/lowerings.nim @@ -114,6 +114,10 @@ proc createObj*(owner: PSym, info: TLineInfo): PType = rawAddSon(result, nil) incl result.flags, tfFinal result.n = newNodeI(nkRecList, info) + let s = newSym(skType, getIdent("Env_" & info.toFilename & "_" & $info.line), + owner, info) + s.typ = result + result.sym = s proc rawAddField*(obj: PType; field: PSym) = assert field.kind == skField -- cgit 1.4.1-2-gfad0 From f9e54c1749672aa9fa92054eb21109561043b547 Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 30 Nov 2016 01:45:47 +0100 Subject: use preferName for type info names --- compiler/ccgtypes.nim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'compiler') diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 68e98e92e..4e17d628f 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -817,7 +817,8 @@ proc genTypeInfoAuxBase(m: BModule; typ, origType: PType; name, base: Rope) = if flags != 0: addf(m.s[cfsTypeInit3], "$1.flags = $2;$n", [name, rope(flags)]) if isDefined("nimTypeNames"): - addf(m.s[cfsTypeInit3], "$1.name = $2;$n", [name, makeCstring typeToString origType]) + addf(m.s[cfsTypeInit3], "$1.name = $2;$n", + [name, makeCstring typeToString(origType, preferName)]) discard cgsym(m, "TNimType") addf(m.s[cfsVars], "TNimType $1; /* $2 */$n", [name, rope(typeToString(typ))]) -- cgit 1.4.1-2-gfad0 From b1b2dd606ba736775868853657e331f287423dee Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 30 Nov 2016 11:00:51 +0100 Subject: fixes #5076 --- compiler/options.nim | 3 +-- tests/modules/UpperCased.nim | 6 ++++++ tests/modules/tuppercased.nim | 8 ++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 tests/modules/UpperCased.nim create mode 100644 tests/modules/tuppercased.nim (limited to 'compiler') diff --git a/compiler/options.nim b/compiler/options.nim index 9edafb17a..b04f6a963 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -227,8 +227,7 @@ proc setDefaultLibpath*() = libpath = parentNimLibPath proc canonicalizePath*(path: string): string = - when not FileSystemCaseSensitive: result = path.expandFilename.toLowerAscii - else: result = path.expandFilename + result = path.expandFilename proc shortenDir*(dir: string): string = ## returns the interesting part of a dir diff --git a/tests/modules/UpperCased.nim b/tests/modules/UpperCased.nim new file mode 100644 index 000000000..7beffcc5f --- /dev/null +++ b/tests/modules/UpperCased.nim @@ -0,0 +1,6 @@ + +# bug #5076 + +var str*: string + +UpperCased.str = "hello" diff --git a/tests/modules/tuppercased.nim b/tests/modules/tuppercased.nim new file mode 100644 index 000000000..65f41becd --- /dev/null +++ b/tests/modules/tuppercased.nim @@ -0,0 +1,8 @@ +discard """ + output: "hello" +""" + +import UpperCased + +# stress normalization rules: +echo Upper_Cased.str -- cgit 1.4.1-2-gfad0 From a80a0972b7757b23b950ef032019d2b5007d9b19 Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Wed, 30 Nov 2016 00:25:03 +0200 Subject: Fixed dynlink with OpenSSL >1.1.0. Added loadLibPattern. --- compiler/cgen.nim | 1 + compiler/options.nim | 11 -------- lib/pure/dynlib.nim | 32 ++++++++++++++++++++--- lib/pure/net.nim | 33 +++++++---------------- lib/wrappers/openssl.nim | 68 +++++++++++++++++++++++++++++++++++++++++------- 5 files changed, 97 insertions(+), 48 deletions(-) (limited to 'compiler') diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 6e18c8389..3217b86e4 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -17,6 +17,7 @@ import lowerings, semparallel from modulegraphs import ModuleGraph +from dynlib import libCandidates import strutils except `%` # collides with ropes.`%` diff --git a/compiler/options.nim b/compiler/options.nim index b04f6a963..04ed2412e 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -372,17 +372,6 @@ proc findModule*(modulename, currentModule: string): string = result = findFile(m) patchModule() -proc libCandidates*(s: string, dest: var seq[string]) = - var le = strutils.find(s, '(') - var ri = strutils.find(s, ')', le+1) - if le >= 0 and ri > le: - var prefix = substr(s, 0, le - 1) - var suffix = substr(s, ri + 1) - for middle in split(substr(s, le + 1, ri - 1), '|'): - libCandidates(prefix & middle & suffix, dest) - else: - add(dest, s) - proc canonDynlibName(s: string): string = let start = if s.startsWith("lib"): 3 else: 0 let ende = strutils.find(s, {'(', ')', '.'}) diff --git a/lib/pure/dynlib.nim b/lib/pure/dynlib.nim index 906a9d23e..fda41dadb 100644 --- a/lib/pure/dynlib.nim +++ b/lib/pure/dynlib.nim @@ -11,20 +11,22 @@ ## libraries. On POSIX this uses the ``dlsym`` mechanism, on ## Windows ``LoadLibrary``. +import strutils + type LibHandle* = pointer ## a handle to a dynamically loaded library {.deprecated: [TLibHandle: LibHandle].} -proc loadLib*(path: string, global_symbols=false): LibHandle +proc loadLib*(path: string, global_symbols=false): LibHandle {.gcsafe.} ## loads a library from `path`. Returns nil if the library could not ## be loaded. -proc loadLib*(): LibHandle +proc loadLib*(): LibHandle {.gcsafe.} ## gets the handle from the current executable. Returns nil if the ## library could not be loaded. -proc unloadLib*(lib: LibHandle) +proc unloadLib*(lib: LibHandle) {.gcsafe.} ## unloads the library `lib` proc raiseInvalidLibrary*(name: cstring) {.noinline, noreturn.} = @@ -34,7 +36,7 @@ proc raiseInvalidLibrary*(name: cstring) {.noinline, noreturn.} = e.msg = "could not find symbol: " & $name raise e -proc symAddr*(lib: LibHandle, name: cstring): pointer +proc symAddr*(lib: LibHandle, name: cstring): pointer {.gcsafe.} ## retrieves the address of a procedure/variable from `lib`. Returns nil ## if the symbol could not be found. @@ -44,6 +46,28 @@ proc checkedSymAddr*(lib: LibHandle, name: cstring): pointer = result = symAddr(lib, name) if result == nil: raiseInvalidLibrary(name) +proc libCandidates*(s: string, dest: var seq[string]) = + ## given a library name pattern `s` write possible library names to `dest`. + var le = strutils.find(s, '(') + var ri = strutils.find(s, ')', le+1) + if le >= 0 and ri > le: + var prefix = substr(s, 0, le - 1) + var suffix = substr(s, ri + 1) + for middle in split(substr(s, le + 1, ri - 1), '|'): + libCandidates(prefix & middle & suffix, dest) + else: + add(dest, s) + +proc loadLibPattern*(pattern: string, global_symbols=false): LibHandle = + ## loads a library with name matching `pattern`, similar to what `dlimport` + ## pragma does. Returns nil if the library could not be loaded. + ## Warning: this proc uses the GC and so cannot be used to load the GC. + var candidates = newSeq[string]() + libCandidates(pattern, candidates) + for c in candidates: + result = loadLib(c, global_symbols) + if not result.isNil: break + when defined(posix): # # ========================================================================= diff --git a/lib/pure/net.nim b/lib/pure/net.nim index 863a8a6f4..5e10f2291 100644 --- a/lib/pure/net.nim +++ b/lib/pure/net.nim @@ -90,8 +90,8 @@ when defineSsl: SslContext* = ref object context*: SslCtx - extraInternalIndex: int referencedData: HashSet[int] + extraInternal: SslContextExtraInternal SslAcceptResult* = enum AcceptNoClient = 0, AcceptNoHandshake, AcceptSuccess @@ -103,6 +103,10 @@ when defineSsl: SslServerGetPskFunc* = proc(identity: string): string + SslContextExtraInternal = ref object of RootRef + serverGetPskFunc: SslServerGetPskFunc + clientGetPskFunc: SslClientGetPskFunc + {.deprecated: [ESSL: SSLError, TSSLCVerifyMode: SSLCVerifyMode, TSSLProtVersion: SSLProtVersion, PSSLContext: SSLContext, TSSLAcceptResult: SSLAcceptResult].} @@ -240,11 +244,6 @@ when defineSsl: ErrLoadBioStrings() OpenSSL_add_all_algorithms() - type - SslContextExtraInternal = ref object of RootRef - serverGetPskFunc: SslServerGetPskFunc - clientGetPskFunc: SslClientGetPskFunc - proc raiseSSLError*(s = "") = ## Raises a new SSL error. if s != "": @@ -257,12 +256,6 @@ when defineSsl: var errStr = ErrErrorString(err, nil) raise newException(SSLError, $errStr) - proc getExtraDataIndex*(ctx: SSLContext): int = - ## Retrieves unique index for storing extra data in SSLContext. - result = SSL_CTX_get_ex_new_index(0, nil, nil, nil, nil).int - if result < 0: - raiseSSLError() - proc getExtraData*(ctx: SSLContext, index: int): RootRef = ## Retrieves arbitrary data stored inside SSLContext. if index notin ctx.referencedData: @@ -347,15 +340,11 @@ when defineSsl: discard newCTX.SSLCTXSetMode(SSL_MODE_AUTO_RETRY) newCTX.loadCertificates(certFile, keyFile) - result = SSLContext(context: newCTX, extraInternalIndex: 0, - referencedData: initSet[int]()) - result.extraInternalIndex = getExtraDataIndex(result) - - let extraInternal = new(SslContextExtraInternal) - result.setExtraData(result.extraInternalIndex, extraInternal) + result = SSLContext(context: newCTX, referencedData: initSet[int](), + extraInternal: new(SslContextExtraInternal)) proc getExtraInternal(ctx: SSLContext): SslContextExtraInternal = - return SslContextExtraInternal(ctx.getExtraData(ctx.extraInternalIndex)) + return ctx.extraInternal proc destroyContext*(ctx: SSLContext) = ## Free memory referenced by SSLContext. @@ -379,7 +368,7 @@ when defineSsl: proc pskClientCallback(ssl: SslPtr; hint: cstring; identity: cstring; max_identity_len: cuint; psk: ptr cuchar; max_psk_len: cuint): cuint {.cdecl.} = - let ctx = SSLContext(context: ssl.SSL_get_SSL_CTX, extraInternalIndex: 0) + let ctx = SSLContext(context: ssl.SSL_get_SSL_CTX) let hintString = if hint == nil: nil else: $hint let (identityString, pskString) = (ctx.clientGetPskFunc)(hintString) if psk.len.cuint > max_psk_len: @@ -398,8 +387,6 @@ when defineSsl: ## ## Only used in PSK ciphersuites. ctx.getExtraInternal().clientGetPskFunc = fun - assert ctx.extraInternalIndex == 0, - "The pskClientCallback assumes the extraInternalIndex is 0" ctx.context.SSL_CTX_set_psk_client_callback( if fun == nil: nil else: pskClientCallback) @@ -407,7 +394,7 @@ when defineSsl: return ctx.getExtraInternal().serverGetPskFunc proc pskServerCallback(ssl: SslCtx; identity: cstring; psk: ptr cuchar; max_psk_len: cint): cuint {.cdecl.} = - let ctx = SSLContext(context: ssl.SSL_get_SSL_CTX, extraInternalIndex: 0) + let ctx = SSLContext(context: ssl.SSL_get_SSL_CTX) let pskString = (ctx.serverGetPskFunc)($identity) if psk.len.cint > max_psk_len: return 0 diff --git a/lib/wrappers/openssl.nim b/lib/wrappers/openssl.nim index 241ad17ae..bf41270b0 100644 --- a/lib/wrappers/openssl.nim +++ b/lib/wrappers/openssl.nim @@ -37,6 +37,8 @@ else: DLLUtilName = "libcrypto.so" & versions from posix import SocketHandle +import dynlib + type SslStruct {.final, pure.} = object SslPtr* = ptr SslStruct @@ -185,16 +187,61 @@ const BIO_C_DO_STATE_MACHINE = 101 BIO_C_GET_SSL = 110 -proc SSL_library_init*(): cInt{.cdecl, dynlib: DLLSSLName, importc, discardable.} -proc SSL_load_error_strings*(){.cdecl, dynlib: DLLSSLName, importc.} +# Here we're trying to stay compatible with openssl 1.0.* and 1.1.*. Some +# symbols are loaded dynamically and we don't use them if not found. +var dl {.threadvar.}: LibHandle +template loadSSLLib() = + if dl.isNil: + dl = loadLib() + if dl.isNil: + dl = loadLibPattern(DLLSSLName) + +proc SSL_library_init*(): cint {.discardable.} = + loadSSLLib() + if not dl.isNil: + let theProc = cast[proc(): cint {.cdecl.}](symAddr(dl, "SSL_library_init")) + if not theProc.isNil: result = theProc() + +proc SSL_load_error_strings*() = + loadSSLLib() + if not dl.isNil: + let theProc = cast[proc() {.cdecl.}](symAddr(dl, "SSL_load_error_strings")) + if not theProc.isNil: theProc() + proc ERR_load_BIO_strings*(){.cdecl, dynlib: DLLUtilName, importc.} -proc SSLv23_client_method*(): PSSL_METHOD{.cdecl, dynlib: DLLSSLName, importc.} -proc SSLv23_method*(): PSSL_METHOD{.cdecl, dynlib: DLLSSLName, importc.} -proc SSLv2_method*(): PSSL_METHOD{.cdecl, dynlib: DLLSSLName, importc.} -proc SSLv3_method*(): PSSL_METHOD{.cdecl, dynlib: DLLSSLName, importc.} proc TLSv1_method*(): PSSL_METHOD{.cdecl, dynlib: DLLSSLName, importc.} +proc SSLv23_client_method*(): PSSL_METHOD {.deprecated.} = + loadSSLLib() + if not dl.isNil: + let theProc = cast[proc(): PSSL_METHOD {.cdecl, gcsafe.}](symAddr(dl, "SSLv23_client_method")) + if not theProc.isNil: result = theProc() + if result.isNil: result = TLSv1_method() + +proc SSLv23_method*(): PSSL_METHOD {.deprecated.} = + loadSSLLib() + if not dl.isNil: + let theProc = cast[proc(): PSSL_METHOD {.cdecl, gcsafe.}](symAddr(dl, "SSLv23_method")) + if not theProc.isNil: + result = theProc() + if result.isNil: + result = TLSv1_method() + +proc SSLv2_method*(): PSSL_METHOD {.deprecated.} = + loadSSLLib() + if not dl.isNil: + let theProc = cast[proc(): PSSL_METHOD {.cdecl, gcsafe.}](symAddr(dl, "SSLv2_method")) + if not theProc.isNil: result = theProc() + if result.isNil: result = TLSv1_method() + +proc SSLv3_method*(): PSSL_METHOD {.deprecated.} = + loadSSLLib() + if not dl.isNil: + let theProc = cast[proc(): PSSL_METHOD {.cdecl, gcsafe.}](symAddr(dl, "SSLv3_method")) + if not theProc.isNil: result = theProc() + if result.isNil: result = TLSv1_method() + proc SSL_new*(context: SslCtx): SslPtr{.cdecl, dynlib: DLLSSLName, importc.} proc SSL_free*(ssl: SslPtr){.cdecl, dynlib: DLLSSLName, importc.} proc SSL_get_SSL_CTX*(ssl: SslPtr): SslCtx {.cdecl, dynlib: DLLSSLName, importc.} @@ -261,10 +308,11 @@ proc ERR_error_string*(e: cInt, buf: cstring): cstring{.cdecl, proc ERR_get_error*(): cInt{.cdecl, dynlib: DLLUtilName, importc.} proc ERR_peek_last_error*(): cInt{.cdecl, dynlib: DLLUtilName, importc.} -when defined(android): - template OpenSSL_add_all_algorithms*() = discard -else: - proc OpenSSL_add_all_algorithms*(){.cdecl, dynlib: DLLUtilName, importc: "OPENSSL_add_all_algorithms_conf".} +proc OpenSSL_add_all_algorithms*() = + loadSSLLib() + if not dl.isNil: + let theProc = cast[proc() {.cdecl.}](symAddr(dl, "OPENSSL_add_all_algorithms_conf")) + if not theProc.isNil: theProc() proc OPENSSL_config*(configName: cstring){.cdecl, dynlib: DLLSSLName, importc.} -- cgit 1.4.1-2-gfad0 From 581c0c437b7cefce2ba0f33df70901e2b11181ab Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Wed, 30 Nov 2016 16:22:52 +0200 Subject: In case of synliboverride we support only openssl 1.0.* --- compiler/commands.nim | 2 + lib/wrappers/openssl.nim | 113 ++++++++++++++++++++++++++--------------------- 2 files changed, 64 insertions(+), 51 deletions(-) (limited to 'compiler') diff --git a/compiler/commands.nim b/compiler/commands.nim index 590c4871d..f85e53511 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -226,6 +226,8 @@ proc testCompileOptionArg*(switch, arg: string, info: TLineInfo): bool = of "staticlib": result = contains(gGlobalOptions, optGenStaticLib) and not contains(gGlobalOptions, optGenGuiApp) else: localError(info, errGuiConsoleOrLibExpectedButXFound, arg) + of "dynliboverride": + result = isDynlibOverride(arg) else: invalidCmdLineOption(passCmd1, switch, info) proc testCompileOption*(switch: string, info: TLineInfo): bool = diff --git a/lib/wrappers/openssl.nim b/lib/wrappers/openssl.nim index 491e3a569..1bd02eaf0 100644 --- a/lib/wrappers/openssl.nim +++ b/lib/wrappers/openssl.nim @@ -187,58 +187,73 @@ const BIO_C_DO_STATE_MACHINE = 101 BIO_C_GET_SSL = 110 -# Here we're trying to stay compatible with openssl 1.0.* and 1.1.*. Some -# symbols are loaded dynamically and we don't use them if not found. -proc thisModule(): LibHandle {.inline.} = - var thisMod {.global.}: LibHandle - if thisMod.isNil: thisMod = loadLib() - result = thisMod - -proc sslModule(): LibHandle {.inline.} = - var sslMod {.global.}: LibHandle - if sslMod.isNil: sslMod = loadLibPattern(DLLSSLName) - result = sslMod - -proc sslSym(name: string): pointer = - var dl = thisModule() - if not dl.isNil: - result = symAddr(dl, name) - if result.isNil: - dl = sslModule() - if not dl.isNil: - result = symAddr(dl, name) - -proc SSL_library_init*(): cint {.discardable.} = - let theProc = cast[proc(): cint {.cdecl.}](sslSym("SSL_library_init")) - if not theProc.isNil: result = theProc() - -proc SSL_load_error_strings*() = - let theProc = cast[proc() {.cdecl.}](sslSym("SSL_load_error_strings")) - if not theProc.isNil: theProc() - -proc ERR_load_BIO_strings*(){.cdecl, dynlib: DLLUtilName, importc.} - proc TLSv1_method*(): PSSL_METHOD{.cdecl, dynlib: DLLSSLName, importc.} -proc SSLv23_client_method*(): PSSL_METHOD {.deprecated.} = - let theProc = cast[proc(): PSSL_METHOD {.cdecl, gcsafe.}](sslSym("SSLv23_client_method")) - if not theProc.isNil: result = theProc() - else: result = TLSv1_method() +when compileOption("dynlibOverride", "ssl"): + proc SSL_library_init*(): cint {.cdecl, dynlib: DLLSSLName, importc, discardable.} + proc SSL_load_error_strings*() {.cdecl, dynlib: DLLSSLName, importc.} + proc SSLv23_client_method*(): PSSL_METHOD {.cdecl, dynlib: DLLSSLName, importc.} -proc SSLv23_method*(): PSSL_METHOD {.deprecated.} = - let theProc = cast[proc(): PSSL_METHOD {.cdecl, gcsafe.}](sslSym("SSLv23_method")) - if not theProc.isNil: result = theProc() - else: result = TLSv1_method() + proc SSLv23_method*(): PSSL_METHOD {.cdecl, dynlib: DLLSSLName, importc.} + proc SSLv2_method*(): PSSL_METHOD {.cdecl, dynlib: DLLSSLName, importc.} + proc SSLv3_method*(): PSSL_METHOD {.cdecl, dynlib: DLLSSLName, importc.} -proc SSLv2_method*(): PSSL_METHOD {.deprecated.} = - let theProc = cast[proc(): PSSL_METHOD {.cdecl, gcsafe.}](sslSym("SSLv2_method")) - if not theProc.isNil: result = theProc() - else: result = TLSv1_method() + template OpenSSL_add_all_algorithms*() = discard +else: + # Here we're trying to stay compatible with openssl 1.0.* and 1.1.*. Some + # symbols are loaded dynamically and we don't use them if not found. + proc thisModule(): LibHandle {.inline.} = + var thisMod {.global.}: LibHandle + if thisMod.isNil: thisMod = loadLib() + result = thisMod + + proc sslModule(): LibHandle {.inline.} = + var sslMod {.global.}: LibHandle + if sslMod.isNil: sslMod = loadLibPattern(DLLSSLName) + result = sslMod + + proc sslSym(name: string): pointer = + var dl = thisModule() + if not dl.isNil: + result = symAddr(dl, name) + if result.isNil: + dl = sslModule() + if not dl.isNil: + result = symAddr(dl, name) + + proc SSL_library_init*(): cint {.discardable.} = + let theProc = cast[proc(): cint {.cdecl.}](sslSym("SSL_library_init")) + if not theProc.isNil: result = theProc() + + proc SSL_load_error_strings*() = + let theProc = cast[proc() {.cdecl.}](sslSym("SSL_load_error_strings")) + if not theProc.isNil: theProc() + + proc SSLv23_client_method*(): PSSL_METHOD = + let theProc = cast[proc(): PSSL_METHOD {.cdecl, gcsafe.}](sslSym("SSLv23_client_method")) + if not theProc.isNil: result = theProc() + else: result = TLSv1_method() + + proc SSLv23_method*(): PSSL_METHOD = + let theProc = cast[proc(): PSSL_METHOD {.cdecl, gcsafe.}](sslSym("SSLv23_method")) + if not theProc.isNil: result = theProc() + else: result = TLSv1_method() + + proc SSLv2_method*(): PSSL_METHOD = + let theProc = cast[proc(): PSSL_METHOD {.cdecl, gcsafe.}](sslSym("SSLv2_method")) + if not theProc.isNil: result = theProc() + else: result = TLSv1_method() + + proc SSLv3_method*(): PSSL_METHOD = + let theProc = cast[proc(): PSSL_METHOD {.cdecl, gcsafe.}](sslSym("SSLv3_method")) + if not theProc.isNil: result = theProc() + else: result = TLSv1_method() + + proc OpenSSL_add_all_algorithms*() = + let theProc = cast[proc() {.cdecl.}](sslSym("OPENSSL_add_all_algorithms_conf")) + if not theProc.isNil: theProc() -proc SSLv3_method*(): PSSL_METHOD {.deprecated.} = - let theProc = cast[proc(): PSSL_METHOD {.cdecl, gcsafe.}](sslSym("SSLv3_method")) - if not theProc.isNil: result = theProc() - else: result = TLSv1_method() +proc ERR_load_BIO_strings*(){.cdecl, dynlib: DLLUtilName, importc.} proc SSL_new*(context: SslCtx): SslPtr{.cdecl, dynlib: DLLSSLName, importc.} proc SSL_free*(ssl: SslPtr){.cdecl, dynlib: DLLSSLName, importc.} @@ -306,10 +321,6 @@ proc ERR_error_string*(e: cInt, buf: cstring): cstring{.cdecl, proc ERR_get_error*(): cInt{.cdecl, dynlib: DLLUtilName, importc.} proc ERR_peek_last_error*(): cInt{.cdecl, dynlib: DLLUtilName, importc.} -proc OpenSSL_add_all_algorithms*() = - let theProc = cast[proc() {.cdecl.}](sslSym("OPENSSL_add_all_algorithms_conf")) - if not theProc.isNil: theProc() - proc OPENSSL_config*(configName: cstring){.cdecl, dynlib: DLLSSLName, importc.} when not useWinVersion and not defined(macosx) and not defined(android): -- cgit 1.4.1-2-gfad0 From 20cf28adde8c6e3177f1cc0eca6fe249bc4de438 Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 30 Nov 2016 19:02:16 +0100 Subject: fixes the regressions introduced by fix for #5076 --- compiler/ccgexprs.nim | 8 ++++++-- compiler/extccomp.nim | 2 +- compiler/options.nim | 11 ++++++++++- compiler/pragmas.nim | 1 + 4 files changed, 18 insertions(+), 4 deletions(-) (limited to 'compiler') diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 2761f888b..b863568d3 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1129,7 +1129,11 @@ proc genNewSeqOfCap(p: BProc; e: PNode; d: var TLoc) = proc genConstExpr(p: BProc, n: PNode): Rope proc handleConstExpr(p: BProc, n: PNode, d: var TLoc): bool = - if d.k == locNone and n.len > ord(n.kind == nkObjConstr) and n.isDeepConstExpr: + proc forbiddenType(t: PType): bool {.inline.} = + result = t.kind == tyObject and not isObjLackingTypeField(t) + #echo "forbidden type ", result + if d.k == locNone and n.len > ord(n.kind == nkObjConstr) and n.isDeepConstExpr and + not forbiddenType(n.typ): var t = getUniqueType(n.typ) discard getTypeDesc(p.module, t) # so that any fields are initialized let id = nodeTableTestOrSet(p.module.dataCache, n, p.module.labels) @@ -1144,8 +1148,8 @@ proc handleConstExpr(p: BProc, n: PNode, d: var TLoc): bool = result = false proc genObjConstr(p: BProc, e: PNode, d: var TLoc) = - if handleConstExpr(p, e, d): return #echo rendertree e, " ", e.isDeepConstExpr + if handleConstExpr(p, e, d): return var tmp: TLoc var t = e.typ.skipTypes(abstractInst) getTemp(p, t, tmp) diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim index 6f8b0b197..1f9af95a5 100644 --- a/compiler/extccomp.nim +++ b/compiler/extccomp.nim @@ -34,7 +34,7 @@ type TInfoCCProps* = set[TInfoCCProp] TInfoCC* = tuple[ name: string, # the short name of the compiler - objExt: string, # the compiler's object file extenstion + objExt: string, # the compiler's object file extension optSpeed: string, # the options for optimization for speed optSize: string, # the options for optimization for size compilerExe: string, # the compiler's executable diff --git a/compiler/options.nim b/compiler/options.nim index 04ed2412e..50f12d843 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -227,7 +227,16 @@ proc setDefaultLibpath*() = libpath = parentNimLibPath proc canonicalizePath*(path: string): string = - result = path.expandFilename + # on Windows, 'expandFilename' calls getFullPathName which doesn't do + # case corrections, so we have to use this convoluted way of retrieving + # the true filename (see tests/modules and Nimble uses 'import Uri' instead + # of 'import uri'): + when defined(windows): + result = path.expandFilename + for x in walkFiles(result): + return x + else: + result = path.expandFilename proc shortenDir*(dir: string): string = ## returns the interesting part of a dir diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index e11a8d08b..ffb2aa812 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -490,6 +490,7 @@ proc pragmaLine(c: PContext, n: PNode) = elif y.kind != nkIntLit: localError(n.info, errIntLiteralExpected) else: + # XXX this produces weird paths which are not properly resolved: n.info.fileIndex = msgs.fileInfoIdx(x.strVal) n.info.line = int16(y.intVal) else: -- cgit 1.4.1-2-gfad0 From 7b44896e03cde0071bb3d9ab25ca846c4dfc599c Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 30 Nov 2016 21:10:22 +0100 Subject: fixes #5079 --- compiler/semexprs.nim | 3 ++- tests/ccgbugs/tmissingderef2.nim | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/ccgbugs/tmissingderef2.nim (limited to 'compiler') diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 8aaf4f9d8..723045fb0 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1274,7 +1274,8 @@ proc propertyWriteAccess(c: PContext, n, nOrig, a: PNode): PNode = # this is ugly. XXX Semantic checking should use the ``nfSem`` flag for # nodes? let aOrig = nOrig[0] - result = newNode(nkCall, n.info, sons = @[setterId, a[0], semExpr(c, n[1])]) + result = newNode(nkCall, n.info, sons = @[setterId, a[0], + semExprWithType(c, n[1])]) result.flags.incl nfDotSetter let orig = newNode(nkCall, n.info, sons = @[setterId, aOrig[0], nOrig[1]]) result = semOverloadedCallAnalyseEffects(c, result, orig, {}) diff --git a/tests/ccgbugs/tmissingderef2.nim b/tests/ccgbugs/tmissingderef2.nim new file mode 100644 index 000000000..59cd24dd1 --- /dev/null +++ b/tests/ccgbugs/tmissingderef2.nim @@ -0,0 +1,25 @@ +discard """ + output: "c" +""" + +# bug #5079 + +import tables, strutils + +type Test = ref object + s: string + +proc `test=`(t: Test, s: string) = + t.s = s + +var t = Test() + +#t.test = spaces(2) # -- works + +var a = newTable[string, string]() +a["b"] = "c" + +#t.s = a["b"] # -- works +#t.test a["b"] # -- works +t.test = a["b"] # -- prints "out of memory" and quits +echo t.s -- cgit 1.4.1-2-gfad0 From 8494338bcbe1ffbd9845a6a5318d0853952b25d0 Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 30 Nov 2016 22:25:56 +0100 Subject: fixes #5055 --- compiler/ccgexprs.nim | 9 ++++----- compiler/ccgmerge.nim | 2 +- compiler/cgendata.nim | 2 +- tests/ccgbugs/tobjconstr_regression.nim | 14 ++++++++++++++ 4 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 tests/ccgbugs/tobjconstr_regression.nim (limited to 'compiler') diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index b863568d3..feb70071a 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1129,11 +1129,7 @@ proc genNewSeqOfCap(p: BProc; e: PNode; d: var TLoc) = proc genConstExpr(p: BProc, n: PNode): Rope proc handleConstExpr(p: BProc, n: PNode, d: var TLoc): bool = - proc forbiddenType(t: PType): bool {.inline.} = - result = t.kind == tyObject and not isObjLackingTypeField(t) - #echo "forbidden type ", result - if d.k == locNone and n.len > ord(n.kind == nkObjConstr) and n.isDeepConstExpr and - not forbiddenType(n.typ): + if d.k == locNone and n.len > ord(n.kind == nkObjConstr) and n.isDeepConstExpr: var t = getUniqueType(n.typ) discard getTypeDesc(p.module, t) # so that any fields are initialized let id = nodeTableTestOrSet(p.module.dataCache, n, p.module.labels) @@ -2156,6 +2152,9 @@ proc genNamedConstExpr(p: BProc, n: PNode): Rope = proc genConstSimpleList(p: BProc, n: PNode): Rope = var length = sonsLen(n) result = rope("{") + if n.kind == nkObjConstr and not isObjLackingTypeField(n.typ): + addf(result, "{$1}", [genTypeInfo(p.module, n.typ)]) + if n.len > 1: add(result, ",") for i in countup(ord(n.kind == nkObjConstr), length - 2): addf(result, "$1,$n", [genNamedConstExpr(p, n.sons[i])]) if length > ord(n.kind == nkObjConstr): diff --git a/compiler/ccgmerge.nim b/compiler/ccgmerge.nim index 92b6aa9dc..67ffaf8b0 100644 --- a/compiler/ccgmerge.nim +++ b/compiler/ccgmerge.nim @@ -27,8 +27,8 @@ const cfsFieldInfo: "NIM_merge_FIELD_INFO", cfsTypeInfo: "NIM_merge_TYPE_INFO", cfsProcHeaders: "NIM_merge_PROC_HEADERS", - cfsData: "NIM_merge_DATA", cfsVars: "NIM_merge_VARS", + cfsData: "NIM_merge_DATA", cfsProcs: "NIM_merge_PROCS", cfsInitProc: "NIM_merge_INIT_PROC", cfsTypeInit1: "NIM_merge_TYPE_INIT1", diff --git a/compiler/cgendata.nim b/compiler/cgendata.nim index faeea7afb..def0b4fee 100644 --- a/compiler/cgendata.nim +++ b/compiler/cgendata.nim @@ -27,8 +27,8 @@ type cfsFieldInfo, # section for field information cfsTypeInfo, # section for type information cfsProcHeaders, # section for C procs prototypes - cfsData, # section for C constant data cfsVars, # section for C variable declarations + cfsData, # section for C constant data cfsProcs, # section for C procs that are not inline cfsInitProc, # section for the C init proc cfsTypeInit1, # section 1 for declarations of type information diff --git a/tests/ccgbugs/tobjconstr_regression.nim b/tests/ccgbugs/tobjconstr_regression.nim new file mode 100644 index 000000000..87d037894 --- /dev/null +++ b/tests/ccgbugs/tobjconstr_regression.nim @@ -0,0 +1,14 @@ +discard """ + output: "@[(username: user, role: admin, description: desc, email_addr: email), (username: user, role: admin, description: desc, email_addr: email)]" +""" + +type + User = object of RootObj + username, role, description, email_addr: string + +# bug 5055 +let us4 = @[ + User(username:"user", role:"admin", description:"desc", email_addr:"email"), + User(username:"user", role:"admin", description:"desc", email_addr:"email"), +] +echo us4 -- cgit 1.4.1-2-gfad0 From 2a7b4fda78758005a9c67a0e5f83b7594d616b2a Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 1 Dec 2016 08:46:44 +0100 Subject: fixes #5081 --- compiler/ccgexprs.nim | 3 ++- tests/cpp/tasync_cpp.nim | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'compiler') diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index feb70071a..b3ad6bbc3 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -2152,7 +2152,8 @@ proc genNamedConstExpr(p: BProc, n: PNode): Rope = proc genConstSimpleList(p: BProc, n: PNode): Rope = var length = sonsLen(n) result = rope("{") - if n.kind == nkObjConstr and not isObjLackingTypeField(n.typ): + if n.kind == nkObjConstr and not isObjLackingTypeField(n.typ) and + not p.module.compileToCpp: addf(result, "{$1}", [genTypeInfo(p.module, n.typ)]) if n.len > 1: add(result, ",") for i in countup(ord(n.kind == nkObjConstr), length - 2): diff --git a/tests/cpp/tasync_cpp.nim b/tests/cpp/tasync_cpp.nim index 792f2938b..81215bd58 100644 --- a/tests/cpp/tasync_cpp.nim +++ b/tests/cpp/tasync_cpp.nim @@ -8,4 +8,7 @@ discard """ import jester import asyncdispatch, asyncnet +# bug #5081 +import nre + echo "hello" -- cgit 1.4.1-2-gfad0 From 2adb2be86a5302e532d8463243cbdd57beaa0d4f Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 1 Dec 2016 09:01:00 +0100 Subject: fixes tconsttable regression --- compiler/ccgexprs.nim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'compiler') diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index b3ad6bbc3..18b0e5e20 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -2152,9 +2152,10 @@ proc genNamedConstExpr(p: BProc, n: PNode): Rope = proc genConstSimpleList(p: BProc, n: PNode): Rope = var length = sonsLen(n) result = rope("{") - if n.kind == nkObjConstr and not isObjLackingTypeField(n.typ) and + let t = n.typ.skipTypes(abstractInst) + if n.kind == nkObjConstr and not isObjLackingTypeField(t) and not p.module.compileToCpp: - addf(result, "{$1}", [genTypeInfo(p.module, n.typ)]) + addf(result, "{$1}", [genTypeInfo(p.module, t)]) if n.len > 1: add(result, ",") for i in countup(ord(n.kind == nkObjConstr), length - 2): addf(result, "$1,$n", [genNamedConstExpr(p, n.sons[i])]) -- cgit 1.4.1-2-gfad0