classification
Title: invalid result value of _weakref.__init__()
Type: Stage:
Components: Library (Lib) Versions: Python 3.0, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: benjamin.peterson Nosy List: ajaksu2, amaury.forgeotdarc, benjamin.peterson, pitrou, vstinner
Priority: normal Keywords: patch

Created on 2008-08-21 17:25 by vstinner, last changed 2008-09-09 20:56 by benjamin.peterson. This issue is now closed.

Files
File name Uploaded Description Edit
weakref_init.patch vstinner, 2008-08-21 17:25 Fix weakref___init__() return value: -1 on error
weakref_test-2.patch vstinner, 2008-09-09 09:44 Test <weakref to class>.__init__() using assertRaise()
Messages (9)
msg71662 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-08-21 17:25
_weakref.__init__() doesn't catch errors correctly. Example:
--------------------- 8< -------------------------
from gc import collect
import _weakref

class FuzzingUserClass:
    pass

obj = _weakref.ref(FuzzingUserClass)

# Exception not raised??
obj.__init__(
    0,
    0,
    0,
)

# Exception catched here??
collect()
--------------------- 8< -------------------------

Attached patch fix the bug for py3k branch: return -1 on error 
(instead of 1).
msg72809 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-09-08 23:45
The bug and the fix are trivials. Can anyone review my patch?
msg72811 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-09-08 23:58
The patch looks absolutely fine to me. (I think I have to have another
core developer look at it too, though.)
msg72812 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-09-09 00:17
Adding a simple unit test would be nice.
msg72830 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-09-09 08:17
Add a test to check to regression.
msg72833 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-09 09:20
I think the test should check that TypeError is actually raised:
  self.assertRaises(TypeError, r.__init__, 0, 0, 0, 0, 0)
It's even shorter than the try/except block...
msg72835 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-09-09 09:45
amaury: oh yes, i forget to use assertRaise(). A new patch is 
attached.
msg72842 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-09 11:20
Both patches look fine to me.
They could be backported to 2.5 as well.
msg72909 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-09-09 20:56
Fixed in r66352.
History
Date User Action Args
2008-09-09 20:56:33benjamin.petersonsetstatus: open -> closed
resolution: accepted -> fixed
messages: + msg72909
2008-09-09 11:20:24amaury.forgeotdarcsetkeywords: - needs review
resolution: accepted
messages: + msg72842
2008-09-09 09:45:03vstinnersetmessages: + msg72835
2008-09-09 09:44:16vstinnersetfiles: - weakref_test.patch
2008-09-09 09:44:12vstinnersetfiles: + weakref_test-2.patch
2008-09-09 09:20:55amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg72833
2008-09-09 08:17:46vstinnersetfiles: + weakref_test.patch
messages: + msg72830
2008-09-09 00:17:42pitrousetnosy: + pitrou
messages: + msg72812
2008-09-08 23:58:14benjamin.petersonsetkeywords: + needs review
assignee: benjamin.peterson
messages: + msg72811
nosy: + benjamin.peterson
2008-09-08 23:45:45vstinnersetmessages: + msg72809
2008-08-26 00:53:31ajaksu2setnosy: + ajaksu2
2008-08-21 17:25:00vstinnercreate