Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_structseq.py @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | 42862169541f |
| children | aa0d2d51fbde |
| rev | line source |
|---|---|
|
20780
ab2e315849a7
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1 from test_support import vereq |
|
ab2e315849a7
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
2 |
|
ab2e315849a7
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
3 import time |
|
ab2e315849a7
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
4 |
|
ab2e315849a7
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
5 t = time.gmtime() |
|
ab2e315849a7
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
6 astuple = tuple(t) |
|
ab2e315849a7
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
7 vereq(len(t), len(astuple)) |
|
ab2e315849a7
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
8 vereq(t, astuple) |
|
ab2e315849a7
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
9 |
|
ab2e315849a7
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
10 # Check that slicing works the same way; at one point, slicing t[i:j] with |
|
ab2e315849a7
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
11 # 0 < i < j could produce NULLs in the result. |
|
ab2e315849a7
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
12 for i in range(-len(t), len(t)): |
|
ab2e315849a7
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
13 for j in range(-len(t), len(t)): |
|
ab2e315849a7
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
14 vereq(t[i:j], astuple[i:j]) |
|
ab2e315849a7
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
15 |
|
22163
42862169541f
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
20781
diff
changeset
|
16 # Devious code could crash structseqs' contructors |
|
42862169541f
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
20781
diff
changeset
|
17 class C: |
|
42862169541f
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
20781
diff
changeset
|
18 def __getitem__(self, i): |
|
42862169541f
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
20781
diff
changeset
|
19 raise IndexError |
|
42862169541f
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
20781
diff
changeset
|
20 def __len__(self): |
|
42862169541f
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
20781
diff
changeset
|
21 return 9 |
|
42862169541f
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
20781
diff
changeset
|
22 |
|
42862169541f
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
20781
diff
changeset
|
23 try: |
|
42862169541f
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
20781
diff
changeset
|
24 repr(time.struct_time(C())) |
|
42862169541f
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
20781
diff
changeset
|
25 except: |
|
42862169541f
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
20781
diff
changeset
|
26 pass |
|
42862169541f
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
20781
diff
changeset
|
27 |
|
20781
61226ddadc97
Huh. In an effort to be less thorough <wink>, seems I checked in a new
Tim Peters <tim.peters@gmail.com>
parents:
20780
diff
changeset
|
28 # XXX more needed |
