mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-02 03:02:31 +00:00
* beneficial refactoring; use system.Endianness * closes #18433
This commit is contained in:
@@ -592,8 +592,8 @@ proc isDefined*(conf: ConfigRef; symbol: string): bool =
|
||||
result = conf.target.targetOS == osNintendoSwitch
|
||||
of "freertos", "lwip":
|
||||
result = conf.target.targetOS == osFreeRTOS
|
||||
of "littleendian": result = CPU[conf.target.targetCPU].endian == platform.littleEndian
|
||||
of "bigendian": result = CPU[conf.target.targetCPU].endian == platform.bigEndian
|
||||
of "littleendian": result = CPU[conf.target.targetCPU].endian == littleEndian
|
||||
of "bigendian": result = CPU[conf.target.targetCPU].endian == bigEndian
|
||||
of "cpu8": result = CPU[conf.target.targetCPU].bit == 8
|
||||
of "cpu16": result = CPU[conf.target.targetCPU].bit == 16
|
||||
of "cpu32": result = CPU[conf.target.targetCPU].bit == 32
|
||||
|
||||
@@ -196,13 +196,11 @@ type
|
||||
cpuSparc64, cpuMips64, cpuMips64el, cpuRiscV32, cpuRiscV64, cpuEsp, cpuWasm32
|
||||
|
||||
type
|
||||
TEndian* = enum
|
||||
littleEndian, bigEndian
|
||||
TInfoCPU* = tuple[name: string, intSize: int, endian: TEndian,
|
||||
TInfoCPU* = tuple[name: string, intSize: int, endian: Endianness,
|
||||
floatSize, bit: int]
|
||||
|
||||
const
|
||||
EndianToStr*: array[TEndian, string] = ["littleEndian", "bigEndian"]
|
||||
EndianToStr*: array[Endianness, string] = ["littleEndian", "bigEndian"]
|
||||
CPU*: array[succ(low(TSystemCPU))..high(TSystemCPU), TInfoCPU] = [
|
||||
(name: "i386", intSize: 32, endian: littleEndian, floatSize: 64, bit: 32),
|
||||
(name: "m68k", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32),
|
||||
|
||||
38
tests/arc/tfuncobj.nim
Normal file
38
tests/arc/tfuncobj.nim
Normal file
@@ -0,0 +1,38 @@
|
||||
discard """
|
||||
outputsub: '''f1
|
||||
f2
|
||||
f3'''
|
||||
cmd: "nim c --gc:orc $file"
|
||||
valgrind: true
|
||||
"""
|
||||
|
||||
type
|
||||
FuncObj = object
|
||||
fn: proc (env: pointer) {.cdecl.}
|
||||
env: pointer
|
||||
|
||||
proc `=destroy`(x: var FuncObj) =
|
||||
GC_unref(cast[RootRef](x.env))
|
||||
|
||||
proc `=copy`(x: var FuncObj, y: FuncObj) {.error.}
|
||||
|
||||
# bug #18433
|
||||
|
||||
proc main =
|
||||
var fs: seq[FuncObj]
|
||||
|
||||
proc wrap(p: proc()) =
|
||||
proc closeOver() = p()
|
||||
let env = rawEnv closeOver
|
||||
GC_ref(cast[RootRef](env))
|
||||
fs.add(FuncObj(fn: cast[proc(env: pointer){.cdecl.}](rawProc closeOver), env: env))
|
||||
|
||||
wrap(proc() {.closure.} = echo "f1")
|
||||
wrap(proc() {.closure.} = echo "f2")
|
||||
wrap(proc() {.closure.} = echo "f3")
|
||||
|
||||
for a in fs:
|
||||
a.fn(a.env)
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user