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

(cherry picked from commit 5e4dd57)
  • Loading branch information
ringabout authored and narimiran committed Aug 11, 2023
1 parent 01ef1e1 commit 5d39a82
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 @@ -101,3 +101,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 5d39a82

Please sign in to comment.