Skip to content

Commit

Permalink
Merge branch 'devel' into syncio
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout authored Jan 6, 2025
2 parents d0a3755 + 8ed0a63 commit 146170c
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 48 deletions.
2 changes: 1 addition & 1 deletion changelogs/changelog_1_0_0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions changelogs/changelog_1_0_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion changelogs/changelog_2_0_0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const
useEffectSystem* = true
useWriteTracking* = false
hasFFI* = defined(nimHasLibFFI)
copyrightYear* = "2024"
copyrightYear* = "2025"

nimEnableCovariance* = defined(nimEnableCovariance)

Expand Down
8 changes: 6 additions & 2 deletions compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion copying.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 2 additions & 3 deletions lib/pure/memfiles.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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: "<string.h>".}
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
Expand Down
6 changes: 3 additions & 3 deletions lib/pure/strutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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: "<string.h>".}
from system/ansi_c import c_memchr

const hasCStringBuiltin = true
else:
const hasCStringBuiltin = false
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion lib/std/formatfloat.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
when defined(nimPreviewSlimSystem):
import std/assertions

proc c_memcpy(a, b: pointer, size: csize_t): pointer {.importc: "memcpy", header: "<string.h>", 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
Expand Down
8 changes: 2 additions & 6 deletions lib/std/private/strimpl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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: "<string.h>".}
func c_strstr(haystack, needle: cstring): cstring {.
importc: "strstr", header: "<string.h>".}

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).
Expand All @@ -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
Expand Down
7 changes: 3 additions & 4 deletions lib/std/syncio.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import std/formatfloat
when defined(windows):
import std/widestrs

from system/ansi_c import c_memchr

# ----------------- IO Part ------------------------------------------------
from system/ansi_c import CFilePtr

Expand Down Expand Up @@ -395,9 +397,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: "<string.h>".}

when defined(windows):
proc readConsole(hConsoleInput: FileHandle, lpBuffer: pointer,
nNumberOfCharsToRead: int32,
Expand Down Expand Up @@ -485,7 +484,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])
Expand Down
12 changes: 3 additions & 9 deletions lib/std/varints.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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))
23 changes: 10 additions & 13 deletions lib/system/ansi_c.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ proc c_strcmp*(a, b: cstring): cint {.
importc: "strcmp", header: "<string.h>", noSideEffect.}
proc c_strlen*(a: cstring): csize_t {.
importc: "strlen", header: "<string.h>", noSideEffect.}
proc c_strstr*(haystack, needle: cstring): cstring {.
importc: "strstr", header: "<string.h>", noSideEffect.}
proc c_abort*() {.
importc: "abort", header: "<stdlib.h>", noSideEffect, noreturn.}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 146170c

Please sign in to comment.