From 5e4dd571d43c904c989c1a256f53df38672a20fe Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Sat, 8 Oct 2022 23:38:22 +0800 Subject: [PATCH] fixes #20516; system.create doesn't work with bitfield objects (#20518) * Revert "fixes #19000 (#19032)" This reverts commit 2bda4a30a6b12dd0840dc347e454e54fe26721e7. * fixes #20516; add testcase --- lib/system/memalloc.nim | 6 ------ tests/stdlib/tsystem.nim | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/system/memalloc.nim b/lib/system/memalloc.nim index 49766e69db4d..f8ebc8c5f669 100644 --- a/lib/system/memalloc.nim +++ b/lib/system/memalloc.nim @@ -116,9 +116,6 @@ when hasAlloc and not defined(js): ## ## See also: ## * `create <#create,typedesc>`_ - static: - when sizeof(T) <= 0: - {.fatal: "createU does not support types T where sizeof(T) == 0".} cast[ptr T](alloc(T.sizeof * size)) template alloc0*(size: Natural): pointer = @@ -144,9 +141,6 @@ when hasAlloc and not defined(js): ## ## The allocated memory belongs to its allocating thread! ## Use `createShared <#createShared,typedesc>`_ to allocate from a shared heap. - static: - when sizeof(T) <= 0: - {.fatal: "create does not support types T where sizeof(T) == 0".} cast[ptr T](alloc0(sizeof(T) * size)) template realloc*(p: pointer, newSize: Natural): pointer = diff --git a/tests/stdlib/tsystem.nim b/tests/stdlib/tsystem.nim index 1a976f7a2ea1..810c3af0468f 100644 --- a/tests/stdlib/tsystem.nim +++ b/tests/stdlib/tsystem.nim @@ -162,3 +162,10 @@ block: reset(y) doAssert y.b == {} +block: # bug #20516 + type Foo = object + x {.bitsize:4.}: uint + y {.bitsize:4.}: uint + + when not defined(js): + let a = create(Foo)