Compare commits

...

19 Commits

Author SHA1 Message Date
tersec
772b62cdeb don't access void* out of alignment in refc GC to avoid UB (#21560)
(cherry picked from commit e8a70ff179)
2023-04-05 08:10:11 +02:00
ringabout
82e9ec3b5c fixes broken CI; bump macOS version to macos-11 (#20098)
* bump macOS image on Azure CI to macos-11
* fix CI error

(cherry picked from commit 8ef509b85b)
2022-07-28 07:49:17 +02:00
narimiran
7e3e04c469 use --stylecheck:hint for chronicles package 2022-07-20 12:01:17 +02:00
Tanguy
f2bbff989f Fix nested finally handling in closureiters [backport] (#19933)
* Fix nested finally handling in closureiters

* Fix CI

* review comment

* third time the charm

* Update compiler/closureiters.nim

Co-authored-by: Dominik Picheta <dominikpicheta@googlemail.com>

Co-authored-by: Dominik Picheta <dominikpicheta@googlemail.com>
(cherry picked from commit fb5fbf1e08)
2022-07-18 17:16:06 +02:00
narimiran
de715892ac fix one more Defect 2022-06-22 10:19:00 +02:00
narimiran
24fb72c8ad no Defects in Nim 1.2 2022-06-21 12:24:12 +02:00
Tanguy
7e5686a828 Fix nimRawSetjmp for VCC [backport: 1.2] (#19899)
(cherry picked from commit 40464fa762)
2022-06-20 08:52:56 +02:00
Tanguy
843c479593 Windows: enable nimRawSetjmp by default [backport] (#19891)
* Windows: enable nimRawSetjmp by default

See #19197. The default setjmp can randomly segfault on windows

* Attempt to disable the flag for bootstraping

* Disable styleCheck for c_setjmp

(cherry picked from commit 251bdc1d5a)
2022-06-20 08:52:17 +02:00
flywind
7b35ce9812 fix NimNode comment repr() regression [backport: 1.2] (#19726)
(cherry picked from commit 15ae9323e8)
2022-06-20 08:49:34 +02:00
flywind
0798bd020b setjump => setjmp [backport: 1.2] (#19496)
(cherry picked from commit d0287748fe)
2022-06-20 08:48:57 +02:00
narimiran
c956aeae7f bump NimVersion to 1.2.19 2022-06-20 08:47:19 +02:00
narimiran
af3d1342c0 disable more packages that don't work anymore on Nim 1.2.x 2022-06-10 10:33:26 +02:00
narimiran
aa0dbaf3a1 disable packages that don't work anymore on Nim 1.2.x 2022-05-04 18:21:24 +02:00
narimiran
8a5c8d3e22 bump NimVersion to 1.2.18 2022-02-08 15:19:37 +01:00
narimiran
315a286d7c disable 'fragments' and 'telebot' packages 2022-01-17 11:27:23 +01:00
flywind
1d92e79dac mangle names in nimbase.h using cppDefine (#19395) [backport]
mangle names in nimbase.h
fix comments

(cherry picked from commit 4f6b59de96)
2022-01-17 11:18:36 +01:00
narimiran
01c8262426 bump NimVersion to 1.2.17 2022-01-17 07:41:23 +01:00
flywind
5e102df04d nrvo shouldn't touch bycopy object[backport:1.2] (#19385)
fix nim-lang#19342

(cherry picked from commit 9b9ae8a487)
2022-01-17 07:40:54 +01:00
Andreas Rumpf
57c9de181a Revert "Update uri.nim (#19148) [backport:1.0]" (#19280)
This reverts commit a3ef5df680.

(cherry picked from commit 81d32cf7e5)
2021-12-31 05:23:04 +01:00
18 changed files with 202 additions and 26 deletions

View File

@@ -27,7 +27,7 @@ jobs:
- target: windows
os: windows-2019
- target: osx
os: macos-10.15
os: macos-11
name: ${{ matrix.target }}
runs-on: ${{ matrix.os }}

View File

@@ -21,10 +21,10 @@ jobs:
vmImage: 'ubuntu-18.04'
CPU: i386
OSX_amd64:
vmImage: 'macOS-10.15'
vmImage: 'macOS-11'
CPU: amd64
OSX_amd64_cpp:
vmImage: 'macOS-10.15'
vmImage: 'macOS-11'
CPU: amd64
NIM_COMPILE_TO_CPP: true
Windows_amd64:

View File

@@ -220,7 +220,7 @@ proc isInvalidReturnType(conf: ConfigRef; rettype: PType): bool =
# such a poor programming language.
# We exclude records with refs too. This enhances efficiency and
# is necessary for proper code generation of assignments.
if rettype == nil or getSize(conf, rettype) > conf.target.floatSize*3:
if rettype == nil or (tfByCopy notin rettype.flags and getSize(conf, rettype) > conf.target.floatSize*3):
result = true
else:
case mapType(conf, rettype)

View File

@@ -121,7 +121,10 @@
# yield 2
# if :unrollFinally: # This node is created by `newEndFinallyNode`
# if :curExc.isNil:
# return :tmpResult
# if nearestFinally == 0:
# return :tmpResult
# else:
# :state = nearestFinally # bubble up
# else:
# closureIterSetupExc(nil)
# raise
@@ -793,7 +796,10 @@ proc newEndFinallyNode(ctx: var Ctx, info: TLineInfo): PNode =
# Generate the following code:
# if :unrollFinally:
# if :curExc.isNil:
# return :tmpResult
# if nearestFinally == 0:
# return :tmpResult
# else:
# :state = nearestFinally # bubble up
# else:
# raise
let curExc = ctx.newCurExcAccess()
@@ -802,11 +808,17 @@ proc newEndFinallyNode(ctx: var Ctx, info: TLineInfo): PNode =
let cmp = newTree(nkCall, newSymNode(ctx.g.getSysMagic(info, "==", mEqRef), info), curExc, nilnode)
cmp.typ = ctx.g.getSysType(info, tyBool)
let asgn = newTree(nkFastAsgn,
newSymNode(getClosureIterResult(ctx.g, ctx.fn), info),
ctx.newTmpResultAccess())
let retStmt =
if ctx.nearestFinally == 0:
# last finally, we can return
let asgn = newTree(nkFastAsgn,
newSymNode(getClosureIterResult(ctx.g, ctx.fn), info),
ctx.newTmpResultAccess())
newTree(nkReturnStmt, asgn)
else:
# bubble up to next finally
newTree(nkGotoState, ctx.g.newIntLit(info, ctx.nearestFinally))
let retStmt = newTree(nkReturnStmt, asgn)
let branch = newTree(nkElifBranch, cmp, retStmt)
let nullifyExc = newTree(nkCall, newSymNode(ctx.g.getCompilerProc("closureIterSetupExc")), nilnode)
@@ -850,6 +862,13 @@ proc transformReturnsInTry(ctx: var Ctx, n: PNode): PNode =
of nkSkip:
discard
of nkTryStmt:
if n.hasYields:
# the inner try will handle these transformations
discard
else:
for i in 0..<n.len:
n[i] = ctx.transformReturnsInTry(n[i])
else:
for i in 0..<n.len:
n[i] = ctx.transformReturnsInTry(n[i])

View File

@@ -225,7 +225,7 @@ const
errNoneBoehmRefcExpectedButXFound = "'none', 'boehm' or 'refc' expected, but '$1' found"
errNoneSpeedOrSizeExpectedButXFound = "'none', 'speed' or 'size' expected, but '$1' found"
errGuiConsoleOrLibExpectedButXFound = "'gui', 'console' or 'lib' expected, but '$1' found"
errInvalidExceptionSystem = "'goto', 'setjump', 'cpp' or 'quirky' expected, but '$1' found"
errInvalidExceptionSystem = "'goto', 'setjmp', 'cpp' or 'quirky' expected, but '$1' found"
proc testCompileOptionArg*(conf: ConfigRef; switch, arg: string, info: TLineInfo): bool =
case switch.normalize

View File

@@ -150,6 +150,7 @@ proc putNL(g: var TSrcGen) =
proc optNL(g: var TSrcGen, indent: int) =
g.pendingNL = indent
g.lineLen = indent
g.col = g.indent
when defined(nimpretty): g.pendingNewlineCount = 0
proc optNL(g: var TSrcGen) =
@@ -158,6 +159,7 @@ proc optNL(g: var TSrcGen) =
proc optNL(g: var TSrcGen; a, b: PNode) =
g.pendingNL = g.indent
g.lineLen = g.indent
g.col = g.indent
when defined(nimpretty): g.pendingNewlineCount = lineDiff(a, b)
proc indentNL(g: var TSrcGen) =

View File

@@ -3,3 +3,13 @@
when defined(nimHasCppDefine):
cppDefine "errno"
cppDefine "unix"
# mangle the macro names in nimbase.h
cppDefine "NAN_INFINITY"
cppDefine "INF"
cppDefine "NAN"
when defined(windows) and not defined(booting):
# Avoid some rare stack corruption while using exceptions with a SEH-enabled
# toolchain: https://github.com/nim-lang/Nim/pull/19197
switch("define", "nimRawSetjmp")

View File

@@ -163,8 +163,6 @@ proc parseAuthority(authority: string, result: var Uri) =
inIPv6 = true
of ']':
inIPv6 = false
of '\0':
break
else:
if inPort:
result.port.add(authority[i])

View File

@@ -2058,7 +2058,7 @@ const
NimMinor* {.intdefine.}: int = 2
## is the minor number of Nim's version.
NimPatch* {.intdefine.}: int = 16
NimPatch* {.intdefine.}: int = 19
## is the patch number of Nim's version.
NimVersion*: string = $NimMajor & "." & $NimMinor & "." & $NimPatch

View File

@@ -113,8 +113,9 @@ elif defined(nimBuiltinSetjmp):
proc c_builtin_setjmp(jmpb: ptr pointer): cint {.
importc: "__builtin_setjmp", nodecl.}
c_builtin_setjmp(unsafeAddr jmpb[0])
elif defined(nimRawSetjmp) and not defined(nimStdSetjmp):
when defined(windows):
when defined(windows) and not defined(vcc):
# No `_longjmp()` on Windows.
proc c_longjmp*(jmpb: C_JmpBuf, retval: cint) {.
header: "<setjmp.h>", importc: "longjmp".}
@@ -124,10 +125,16 @@ elif defined(nimRawSetjmp) and not defined(nimStdSetjmp):
# prone to stack corruption during unwinding, so we disable that by setting
# it to NULL.
# More details: https://github.com/status-im/nimbus-eth2/issues/3121
when defined(nimHasStyleChecks):
{.push styleChecks: off.}
proc c_setjmp*(jmpb: C_JmpBuf): cint =
proc c_setjmp_win(jmpb: C_JmpBuf, ctx: pointer): cint {.
header: "<setjmp.h>", importc: "_setjmp".}
c_setjmp_win(jmpb, nil)
when defined(nimHasStyleChecks):
{.pop.}
else:
proc c_longjmp*(jmpb: C_JmpBuf, retval: cint) {.
header: "<setjmp.h>", importc: "_longjmp".}

View File

@@ -381,7 +381,6 @@ else:
let regEnd = sp +% sizeof(registers)
while sp <% regEnd:
gcMark(gch, cast[PPointer](sp)[])
gcMark(gch, cast[PPointer](sp +% sizeof(pointer) div 2)[])
sp = sp +% sizeof(pointer)
# Make sure sp is word-aligned
sp = sp and not (sizeof(pointer) - 1)

View File

@@ -15,7 +15,7 @@ pkg "bncurve", true
pkg "c2nim", false, "nim c testsuite/tester.nim"
pkg "cascade"
pkg "chroma"
pkg "chronicles", true, "nim c -o:chr -r chronicles.nim"
pkg "chronicles", true, "nim c --stylecheck:hint -o:chr -r chronicles.nim"
pkg "chronos", true, "nim c -r -d:release tests/testall"
pkg "cligen", false, "nim c -o:cligenn -r cligen.nim"
pkg "coco", true
@@ -26,8 +26,8 @@ pkg "comprehension", false, "nimble test", "https://github.com/alehander42/compr
pkg "dashing", false, "nim c tests/functional.nim"
pkg "docopt"
pkg "easygl", true, "nim c -o:egl -r src/easygl.nim", "https://github.com/jackmott/easygl"
pkg "elvis"
pkg "fragments", false, "nim c -r fragments/dsl.nim"
# pkg "elvis"
# pkg "fragments", false, "nim c -r fragments/dsl.nim"
pkg "gara"
# pkg "ggplotnim", true, "nimble testCI"
pkg "glob"
@@ -68,7 +68,7 @@ pkg "ormin", true, "nim c -o:orminn ormin.nim"
pkg "patty"
pkg "plotly", true, "nim c --oldgensym:on examples/all.nim"
pkg "pnm"
pkg "polypbren"
# pkg "polypbren"
pkg "protobuf", true, "nim c -o:protobuff -r src/protobuf.nim"
pkg "rbtree"
pkg "react", false, "nimble example"
@@ -80,10 +80,10 @@ pkg "sdl2_nim", false, "nim c -r sdl2/sdl.nim"
pkg "snip", false, "nimble test", "https://github.com/genotrance/snip"
pkg "stint", false, "nim c -o:stintt -r stint.nim"
pkg "strunicode", true, "nim c -r src/strunicode.nim"
pkg "telebot", true, "nim c -o:tbot -r src/telebot.nim"
# pkg "telebot", true, "nim c -o:tbot -r src/telebot.nim"
pkg "tempdir"
pkg "tensordsl", false, "nim c -r tests/tests.nim", "https://krux02@bitbucket.org/krux02/tensordslnim.git"
pkg "tiny_sqlite"
# pkg "tiny_sqlite"
pkg "unicodedb"
pkg "unicodeplus", true
pkg "unpack"
@@ -91,4 +91,4 @@ pkg "unpack"
pkg "with"
# pkg "ws"
pkg "yaml"
pkg "zero_functional", false, "nim c -r test.nim"
# pkg "zero_functional", false, "nim c -r test.nim"

16
tests/ccgbugs/tmangle.nim Normal file
View File

@@ -0,0 +1,16 @@
block:
proc hello() =
let NAN_INFINITY = 12
doAssert NAN_INFINITY == 12
let INF = "2.0"
doAssert INF == "2.0"
let NAN = 2.3
doAssert NAN == 2.3
hello()
block:
proc hello(NAN: float) =
doAssert NAN == 2.0
hello(2.0)

View File

@@ -92,10 +92,10 @@ block:
result.add(1212)
try:
try:
raise newException(AssertionDefect, "a")
raise newException(AssertionError, "a")
finally:
result.add(42)
except AssertionDefect:
except AssertionError:
result.add(99)
finally:
result.add(10)
@@ -107,7 +107,7 @@ block:
result.add(-1)
except ValueError:
result.add(-1)
except IndexDefect:
except IndexError:
result.add(2)
except:
result.add(3)

View File

@@ -18,6 +18,14 @@ end
1
2
7
nested finally
outer finally
nested finally
outer finally
nested finally
outer finally
nested finally
outer finally
'''
"""
@@ -213,3 +221,71 @@ block t2023_objiter:
var o = init()
echo(o.iter())
block:
# bug #19911 (return in nested try)
# try yield -> try
iterator p1: int {.closure.} =
try:
yield 0
try:
return
finally:
echo "nested finally"
echo "shouldn't run"
finally:
echo "outer finally"
echo "shouldn't run"
for _ in p1():
discard
# try -> try yield
iterator p2: int {.closure.} =
try:
try:
yield 0
return
finally:
echo "nested finally"
echo "shouldn't run"
finally:
echo "outer finally"
echo "shouldn't run"
for _ in p2():
discard
# try yield -> try yield
iterator p3: int {.closure.} =
try:
yield 0
try:
yield 0
return
finally:
echo "nested finally"
echo "shouldn't run"
finally:
echo "outer finally"
echo "shouldn't run"
for _ in p3():
discard
# try -> try
iterator p4: int {.closure.} =
try:
try:
return
finally:
echo "nested finally"
echo "shouldn't run"
finally:
echo "outer finally"
echo "shouldn't run"
for _ in p4():
discard

View File

@@ -60,3 +60,22 @@ macro foo(t: static Tuple): untyped =
doAssert t.b == 12345
foo((a: "foo", b: 12345))
# bug #16307
macro bug(x: untyped): string =
newLit repr(x)
let res = bug:
block:
## one
## two
## three
doAssert res == """
block:
## one
## two
## three"""

12
tests/objects/m19342.c Normal file
View File

@@ -0,0 +1,12 @@
struct Node
{
int data[25];
};
struct Node hello(int name) {
struct Node x = {999, 1, 2, 3, 4, 5, 6, 7, 8, 9,
0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,
1, 2, 3, 4, 5};
return x;
}

18
tests/objects/t19342.nim Normal file
View File

@@ -0,0 +1,18 @@
discard """
targets: "c cpp"
"""
{.compile: "m19342.c".}
# bug #19342
type
Node* {.bycopy.} = object
data: array[25, cint]
proc myproc(name: cint): Node {.importc: "hello", cdecl.}
proc parse =
let node = myproc(10)
doAssert node.data[0] == 999
parse()