From dcc4e07e546e515a04767d31c3fdd0342cc7ed86 Mon Sep 17 00:00:00 2001 From: Skylar Ray <137945430+sky-coderay@users.noreply.github.com> Date: Mon, 30 Dec 2024 13:40:45 +0200 Subject: [PATCH 1/6] chore: docs fix spelling issues (#24581) **handle - handles** **sensitiviy - sensitivity** --- changelogs/changelog_1_0_2.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelogs/changelog_1_0_2.md b/changelogs/changelog_1_0_2.md index aa01c503f6efe..88fca18b53d1e 100644 --- a/changelogs/changelog_1_0_2.md +++ b/changelogs/changelog_1_0_2.md @@ -11,7 +11,7 @@ * Fixed "Assertion error when running `nim check` on compiler/nim.nim" [#12281](https://github.com/nim-lang/Nim/issues/12281) * Fixed "Compiler crash with empty array and generic instantiation with int as parameter" [#12264](https://github.com/nim-lang/Nim/issues/12264) * Fixed "Regression in JS backend codegen "Error: request to generate code for .compileTime proc"" [#12240](https://github.com/nim-lang/Nim/issues/12240) -* Fix how `relativePath` handle case sensitiviy +* Fix how `relativePath` handles case sensitivity * Fixed "SIGSEGV in compiler when using generic types and seqs" [#12336](https://github.com/nim-lang/Nim/issues/12336) * Fixed "[1.0.0] weird interaction between `import os` and casting integer to char on macosx trigger bad codegen" [#12291](https://github.com/nim-lang/Nim/issues/12291) * VM: no special casing for big endian machines @@ -43,7 +43,7 @@ * threadpool: fix link in docs (#12258) * Fix spellings (#12277) * fix #12278, don't expose internal PCRE documentation -* Fixed "Documentation of quitprocs is wrong" [#12279(https://github.com/nim-lang/Nim/issues/12279) +* Fixed "Documentation of quitprocs is wrong" [#12279](https://github.com/nim-lang/Nim/issues/12279) * Fix typo in docs * Fix reference to parseSpec proc in readme * [doc/tut1] removed discard discussion in comments From 3dda60a8ce32cb7d5e3e99111399a1550c145176 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 31 Dec 2024 18:06:55 +0800 Subject: [PATCH 2/6] Update copyright year 2025 (#24593) --- compiler/options.nim | 2 +- copying.txt | 2 +- readme.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/options.nim b/compiler/options.nim index 0ef65a14048e9..b456651c82211 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -25,7 +25,7 @@ const useEffectSystem* = true useWriteTracking* = false hasFFI* = defined(nimHasLibFFI) - copyrightYear* = "2024" + copyrightYear* = "2025" nimEnableCovariance* = defined(nimEnableCovariance) diff --git a/copying.txt b/copying.txt index 6707dad448851..4025beacbabdf 100644 --- a/copying.txt +++ b/copying.txt @@ -1,7 +1,7 @@ ===================================================== Nim -- a Compiler for Nim. https://nim-lang.org/ -Copyright (C) 2006-2024 Andreas Rumpf. All rights reserved. +Copyright (C) 2006-2025 Andreas Rumpf. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/readme.md b/readme.md index 88f0b05d89865..69899da71bff4 100644 --- a/readme.md +++ b/readme.md @@ -202,7 +202,7 @@ Nim. You are explicitly permitted to develop commercial applications using Nim. Please read the [copying.txt](copying.txt) file for more details. -Copyright © 2006-2024 Andreas Rumpf, all rights reserved. +Copyright © 2006-2025 Andreas Rumpf, all rights reserved. [nim-site]: https://nim-lang.org [nim-forum]: https://forum.nim-lang.org From 78835562b14e764065ad56904f7f7463e73dff0b Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Thu, 2 Jan 2025 17:26:53 +0100 Subject: [PATCH 3/6] varints: no need for emit (#24585) --- lib/std/varints.nim | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/std/varints.nim b/lib/std/varints.nim index 88144a06c1efe..7adab9c37c28e 100644 --- a/lib/std/varints.nim +++ b/lib/std/varints.nim @@ -107,15 +107,9 @@ proc writeVu64*(z: var openArray[byte], x: uint64): int = varintWrite32(toOpenArray(z, 5, 8), y) return 9 -proc sar(a, b: int64): int64 {.noinit.} = - {.emit: [result, " = ", a, " >> ", b, ";"].} - -proc sal(a, b: int64): int64 {.noinit.} = - {.emit: [result, " = ", a, " << ", b, ";"].} - proc encodeZigzag*(x: int64): uint64 {.inline.} = - uint64(sal(x, 1)) xor uint64(sar(x, 63)) + let xu = uint64(x) + (xu shl 1) xor (xu shr 63) proc decodeZigzag*(x: uint64): int64 {.inline.} = - let casted = cast[int64](x) - result = (`shr`(casted, 1)) xor (-(casted and 1)) + cast[int64]((x shr 1) xor (x shl 63)) From e8bf6af0da52ce91dd0b5a7474d386d9a66809b9 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Thu, 2 Jan 2025 17:28:35 +0100 Subject: [PATCH 4/6] fix c_memchr, c_strstr definitions (#24587) One correct definition is enough --- lib/pure/memfiles.nim | 5 ++--- lib/pure/strutils.nim | 6 +++--- lib/std/formatfloat.nim | 2 +- lib/std/private/strimpl.nim | 8 ++------ lib/std/syncio.nim | 7 +++---- lib/system/ansi_c.nim | 23 ++++++++++------------- 6 files changed, 21 insertions(+), 30 deletions(-) diff --git a/lib/pure/memfiles.nim b/lib/pure/memfiles.nim index bb9b4b02c9a3a..8430dde8b30b8 100644 --- a/lib/pure/memfiles.nim +++ b/lib/pure/memfiles.nim @@ -30,6 +30,7 @@ import std/oserrors when defined(nimPreviewSlimSystem): import std/[syncio, assertions] +from system/ansi_c import c_memchr proc newEIO(msg: string): ref IOError = result = (ref IOError)(msg: msg) @@ -448,14 +449,12 @@ iterator memSlices*(mfile: MemFile, delim = '\l', eat = '\r'): MemSlice {.inline ## echo count ## ``` - proc c_memchr(cstr: pointer, c: char, n: csize_t): pointer {. - importc: "memchr", header: "".} proc `-!`(p, q: pointer): int {.inline.} = return cast[int](p) -% cast[int](q) var ending: pointer var ms = MemSlice(data: mfile.mem, size: 0) var remaining = mfile.size while remaining > 0: - ending = c_memchr(ms.data, delim, csize_t(remaining)) + ending = c_memchr(ms.data, cint(delim), csize_t(remaining)) if ending == nil: # unterminated final slice ms.size = remaining # Weird case..check eat? yield ms diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index 9cb6294fe6431..687dedd5141bb 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -1950,8 +1950,8 @@ func find*(a: SkipTable, s, sub: string, start: Natural = 0, last = -1): int {. inc skip, a[s[skip + subLast]] when not (defined(js) or defined(nimdoc) or defined(nimscript)): - func c_memchr(cstr: pointer, c: char, n: csize_t): pointer {. - importc: "memchr", header: "".} + from system/ansi_c import c_memchr + const hasCStringBuiltin = true else: const hasCStringBuiltin = false @@ -1982,7 +1982,7 @@ func find*(s: string, sub: char, start: Natural = 0, last = -1): int {.rtl, when hasCStringBuiltin: let length = last-start+1 if length > 0: - let found = c_memchr(s[start].unsafeAddr, sub, cast[csize_t](length)) + let found = c_memchr(s[start].unsafeAddr, cint(sub), cast[csize_t](length)) if not found.isNil: return cast[int](found) -% cast[int](s.cstring) else: diff --git a/lib/std/formatfloat.nim b/lib/std/formatfloat.nim index d8e6489262d79..c35adfd7cb027 100644 --- a/lib/std/formatfloat.nim +++ b/lib/std/formatfloat.nim @@ -12,7 +12,7 @@ when defined(nimPreviewSlimSystem): import std/assertions -proc c_memcpy(a, b: pointer, size: csize_t): pointer {.importc: "memcpy", header: "", discardable.} +from system/ansi_c import c_memcpy proc addCstringN(result: var string, buf: cstring; buflen: int) = # no nimvm support needed, so it doesn't need to be fast here either diff --git a/lib/std/private/strimpl.nim b/lib/std/private/strimpl.nim index d1732bf365492..8ddb39cf0c456 100644 --- a/lib/std/private/strimpl.nim +++ b/lib/std/private/strimpl.nim @@ -75,11 +75,7 @@ template endsWithImpl*[T: string | cstring](s, suffix: T) = func cmpNimIdentifier*[T: string | cstring](a, b: T): int = cmpIgnoreStyleImpl(a, b, true) -func c_memchr(cstr: pointer, c: char, n: csize_t): pointer {. - importc: "memchr", header: "".} -func c_strstr(haystack, needle: cstring): cstring {. - importc: "strstr", header: "".} - +from system/ansi_c import c_memchr, c_strstr func find*(s: cstring, sub: char, start: Natural = 0, last = 0): int = ## Searches for `sub` in `s` inside the range `start..last` (both ends included). @@ -91,7 +87,7 @@ func find*(s: cstring, sub: char, start: Natural = 0, last = 0): int = let last = if last == 0: s.high else: last let L = last-start+1 if L > 0: - let found = c_memchr(s[start].unsafeAddr, sub, cast[csize_t](L)) + let found = c_memchr(s[start].unsafeAddr, cint(sub), cast[csize_t](L)) if not found.isNil: return cast[int](found) -% cast[int](s) return -1 diff --git a/lib/std/syncio.nim b/lib/std/syncio.nim index 5c97712a4386b..911bff276e173 100644 --- a/lib/std/syncio.nim +++ b/lib/std/syncio.nim @@ -15,6 +15,8 @@ import std/formatfloat when defined(windows): import std/widestrs +from system/ansi_c import c_memchr + # ----------------- IO Part ------------------------------------------------ type CFile {.importc: "FILE", header: "", @@ -401,9 +403,6 @@ proc readLine*(f: File, line: var string): bool {.tags: [ReadIOEffect], ## `false` is returned `line` contains no new data. result = false - proc c_memchr(s: pointer, c: cint, n: csize_t): pointer {. - importc: "memchr", header: "".} - when defined(windows): proc readConsole(hConsoleInput: FileHandle, lpBuffer: pointer, nNumberOfCharsToRead: int32, @@ -491,7 +490,7 @@ proc readLine*(f: File, line: var string): bool {.tags: [ReadIOEffect], checkErr(f) break - let m = c_memchr(addr line[pos], '\L'.ord, cast[csize_t](sp)) + let m = c_memchr(addr line[pos], cint('\L'), cast[csize_t](sp)) if m != nil: # \l found: Could be our own or the one by fgets, in any case, we're done var last = cast[int](m) - cast[int](addr line[0]) diff --git a/lib/system/ansi_c.nim b/lib/system/ansi_c.nim index 3098e17d69d68..ed1a8aedf1c62 100644 --- a/lib/system/ansi_c.nim +++ b/lib/system/ansi_c.nim @@ -27,6 +27,8 @@ proc c_strcmp*(a, b: cstring): cint {. importc: "strcmp", header: "", noSideEffect.} proc c_strlen*(a: cstring): csize_t {. importc: "strlen", header: "", noSideEffect.} +proc c_strstr*(haystack, needle: cstring): cstring {. + importc: "strstr", header: "", noSideEffect.} proc c_abort*() {. importc: "abort", header: "", noSideEffect, noreturn.} @@ -76,19 +78,14 @@ elif defined(haiku): SIGTERM* = cint(15) SIGPIPE* = cint(7) SIG_DFL* = CSighandlerT(nil) -else: - when defined(nimscript): - {.error: "SIGABRT not ported to your platform".} - else: - var - SIGINT* {.importc: "SIGINT", nodecl.}: cint - SIGSEGV* {.importc: "SIGSEGV", nodecl.}: cint - SIGABRT* {.importc: "SIGABRT", nodecl.}: cint - SIGFPE* {.importc: "SIGFPE", nodecl.}: cint - SIGILL* {.importc: "SIGILL", nodecl.}: cint - SIG_DFL* {.importc: "SIG_DFL", nodecl.}: CSighandlerT - when defined(macosx) or defined(linux): - var SIGPIPE* {.importc: "SIGPIPE", nodecl.}: cint +elif not defined(nimscript): + var + SIGINT* {.importc: "SIGINT", nodecl.}: cint + SIGSEGV* {.importc: "SIGSEGV", nodecl.}: cint + SIGABRT* {.importc: "SIGABRT", nodecl.}: cint + SIGFPE* {.importc: "SIGFPE", nodecl.}: cint + SIGILL* {.importc: "SIGILL", nodecl.}: cint + SIG_DFL* {.importc: "SIG_DFL", nodecl.}: CSighandlerT when defined(macosx): const SIGBUS* = cint(10) From aeeccee50a603c37c94ee3aa0c3d109654814654 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Mon, 6 Jan 2025 01:10:36 +0800 Subject: [PATCH 5/6] fixes #24599; misleading error message with large array bounds (#24601) fixes #24599 --- compiler/semtypes.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 4855faf736c3a..5f33df5c7d1a8 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -409,8 +409,12 @@ proc semArrayIndex(c: PContext, n: PNode): PType = result = makeRangeWithStaticExpr(c, e.typ.n) elif e.kind in {nkIntLit..nkUInt64Lit}: if e.intVal < 0: - localError(c.config, n.info, - "Array length can't be negative, but was " & $e.intVal) + if e.kind in {nkIntLit..nkInt64Lit}: + localError(c.config, n.info, + "Array length can't be negative, but was " & $e.intVal) + else: + localError(c.config, n.info, + "Array length can't exceed its maximum value (9223372036854775807), but was " & $cast[BiggestUInt](e.intVal)) result = makeRangeType(c, 0, e.intVal-1, n.info, e.typ) elif e.kind == nkSym and (e.typ.kind == tyStatic or e.typ.kind == tyTypeDesc): if e.typ.kind == tyStatic: From 8ed0a6397301aefed8ccddadea908b7181ab42e4 Mon Sep 17 00:00:00 2001 From: planetBoy <140164174+Guayaba221@users.noreply.github.com> Date: Mon, 6 Jan 2025 06:48:35 +0100 Subject: [PATCH 6/6] docs fix spelling issues (#24597) Hey ! I fixed several spelling issues.Glad I could help . Br, Guayaba221. --- changelogs/changelog_1_0_0.md | 2 +- changelogs/changelog_2_0_0.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/changelogs/changelog_1_0_0.md b/changelogs/changelog_1_0_0.md index 5a9185ecb7f95..15da65e3d5899 100644 --- a/changelogs/changelog_1_0_0.md +++ b/changelogs/changelog_1_0_0.md @@ -22,7 +22,7 @@ - We removed `unicode.Rune16` without any deprecation period as the name was wrong (see the [RFC](https://github.com/nim-lang/RFCs/issues/151) for details) - and we didn't find any usages of it in the wild. If you still need it, add this + and we didn't find any usage of it in the wild. If you still need it, add this piece of code to your project: ```nim type diff --git a/changelogs/changelog_2_0_0.md b/changelogs/changelog_2_0_0.md index 457cc62a6b9cc..2d9db9576d538 100644 --- a/changelogs/changelog_2_0_0.md +++ b/changelogs/changelog_2_0_0.md @@ -283,7 +283,7 @@ The definition of `"strictFuncs"` was changed. The old definition was roughly: "A store to a ref/ptr deref is forbidden unless it's coming from a `var T` parameter". The new definition is: "A store to a ref/ptr deref is forbidden." -This new definition is much easier to understand, the price is some expressitivity. The following code used to be +This new definition is much easier to understand, the price is some expressiveness. The following code used to be accepted: ```nim