Skip to content

Commit

Permalink
fixes #20516; system.create doesn't work with bitfield objects (#20518)
Browse files Browse the repository at this point in the history
* Revert "fixes #19000 (#19032)"

This reverts commit 2bda4a3.

* fixes #20516; add testcase
  • Loading branch information
ringabout authored Oct 8, 2022
1 parent e83f27e commit 5e4dd57
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 0 additions & 6 deletions lib/system/memalloc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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 =
Expand Down
7 changes: 7 additions & 0 deletions tests/stdlib/tsystem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 5e4dd57

Please sign in to comment.