Issue31779
Created on 2017-10-13 10:54 by Oren Milman, last changed 2022-04-11 14:58 by admin.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 3984 | open | Oren Milman, 2017-10-13 14:14 | |
| Messages (3) | |||
|---|---|---|---|
| msg304328 - (view) | Author: Oren Milman (Oren Milman) * | Date: 2017-10-13 10:54 | |
The following code causes an assertion failure:
import _struct
struct_obj = _struct.Struct.__new__(_struct.Struct)
struct_obj.iter_unpack(b'foo')
This is because Struct_iter_unpack() (in Modules/_struct.c) assumes that
Struct.__init__() was called, and so it does `assert(self->s_codes != NULL);`.
The same happens in (almost) every method of Struct, and in s_get_format(), so
in all them, too, we would get an assertion failure in case of an uninitialized
Struct object.
The exception is __sizeof__(), which doesn't have an `assert`, and simply
crashes while trying to iterate over `self->s_codes`.
I would open a PR to fix this soon.
|
|||
| msg325462 - (view) | Author: Alexey Izbyshev (izbyshev) * ![]() |
Date: 2018-09-15 22:53 | |
What are the drawbacks of moving all code from __init__ to __new__, at least in master branch (3.8)? IMO it's much more robust than playing whack-a-mole both with ref/memleaks caused by repeated calls to __init__ and absence of initialization checks in all methods. |
|||
| msg404285 - (view) | Author: Irit Katriel (iritkatriel) * ![]() |
Date: 2021-10-19 10:22 | |
Reproduced on 3.11. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:53 | admin | set | github: 75960 |
| 2021-10-19 10:22:17 | iritkatriel | set | nosy:
+ iritkatriel messages:
+ msg404285 |
| 2019-05-20 22:29:12 | cheryl.sabella | set | versions: - Python 3.6 |
| 2018-09-15 22:53:38 | izbyshev | set | nosy:
+ izbyshev, meador.inge, berker.peksag, serhiy.storchaka, mark.dickinson messages:
+ msg325462 |
| 2017-10-13 14:14:21 | Oren Milman | set | keywords:
+ patch stage: patch review pull_requests: + pull_request3960 |
| 2017-10-13 10:54:20 | Oren Milman | create | |

