This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: segfault with defaultdict and pickle
Type: crash Stage:
Components: Library (Lib) Versions: Python 3.0
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, erickt, ocean-city
Priority: normal Keywords: patch

Created on 2008-10-22 09:26 by erickt, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
fix_defaultdict_reduce.patch ocean-city, 2008-10-22 11:32
fix_defaultdict_reduce_v2.patch ocean-city, 2008-10-23 00:13 also test with HIGHEST_PROTOCOL
Messages (7)
msg75073 - (view) Author: Erick Tryzelaar (erickt) Date: 2008-10-22 09:26
It seems like there's a bug with defaultdict. This is segfaulting with 
the latest python 3.0 svn checkout:

import collections, pickle
d=collections.defaultdict(int)
d[1]
pickle.dumps(d)


It errors out with:

Assertion failed: (PyIter_Check(iter)), function PyIter_Next, file 
Objects/abstract.c, line 2751.
zsh: abort      /tmp/python/bin/python3.0 foo.py
msg75076 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2008-10-22 11:32
On py3k, defaultdict#items() returns dict_items object not
dict_itemiterator object. I hope attached patch will fix this bug.
msg75086 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-10-22 16:18
The pickle protocol should also check that __reduce__ returns iterators
(iterables are not enough).
The code below crashes the interpreter (twice ;-)

class C:
    def __reduce__(self):
        return C, (), None, None, []
class D:
    def __reduce__(self):
        return D, (), None, [], None
import pickle
pickle.dumps(C())
pickle.dumps(D())
msg75087 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-10-22 16:23
My previous example also crashes python 2.4 & 2.6 (the classes have to
inherit from 'object')
msg75095 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2008-10-22 18:21
>My previous example also crashes python 2.4 & 2.6 (the classes have to
inherit from 'object')

I created new tracker item for this. (See issue4176)
msg75126 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2008-10-23 00:13
I created test case referring to test_bytes, but I noticed
range(pickle.HIGHETST_PROTOCOL) doesn't test HIGHEST_PROTOCOL itself. So
patch revised. I created another tracker item for other tests using
range(pickle.HIGHETST_PROTOCOL). See issue4183.
msg75380 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-10-30 20:58
Fixed with r67048.
History
Date User Action Args
2022-04-11 14:56:40adminsetgithub: 48420
2008-10-30 20:58:54amaury.forgeotdarcsetstatus: open -> closed
resolution: fixed
messages: + msg75380
2008-10-23 00:13:46ocean-citysetfiles: + fix_defaultdict_reduce_v2.patch
messages: + msg75126
2008-10-22 18:21:17ocean-citysetmessages: + msg75095
2008-10-22 16:23:18amaury.forgeotdarcsetmessages: + msg75087
2008-10-22 16:18:23amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg75086
2008-10-22 11:32:04ocean-citysetfiles: + fix_defaultdict_reduce.patch
keywords: + patch
messages: + msg75076
nosy: + ocean-city
2008-10-22 09:26:46ericktcreate