py/objnamedtuple: Fix segfault with empty namedtuple.

The empty tuple is usually a constant object, but named tuples must be
allocated to allow modification.  Added explicit allocation to fix this.

Also added a regression test to verify creating an empty named tuple works.

Fixes issue #7870.

Signed-off-by: Lars Haulin <lars.haulin@gmail.com>
This commit is contained in:
Lars Haulin
2022-07-08 17:48:40 +02:00
committed by Damien George
parent 2076f2efcc
commit 5bf3765631
2 changed files with 9 additions and 3 deletions

View File

@@ -85,3 +85,8 @@ print(t.foo, t.bar)
# Not implemented so far
#T2 = namedtuple("TupComma", "foo,bar")
#t = T2(1, 2)
# Creating an empty namedtuple should not segfault
T5 = namedtuple("TupEmpty", [])
t = T5()
print(t)