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: Add more checks to testcapi
Type: enhancement 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, benjamin.peterson, georg.brandl, pitrou, vstinner
Priority: high Keywords: patch

Created on 2008-08-22 01:41 by vstinner, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
testcapi_py26.patch vstinner, 2008-08-22 01:41 Fix _test_thread_state() and raise_exception() and _testcapi module
testcapi_py30.patch vstinner, 2008-08-22 01:44 Fix exception_print() of _testcapi module
Messages (9)
msg71714 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-08-22 01:41
test_thread_state() doesn't check that the argument is a function and 
doesn't check function call result and so the exception is catched 
later:

Non callable argument:
   import _testcapi
   _testcapi._test_thread_state(10)
   # no exception raise here
   import gc
   # exception raised too late!
=> TypeError: 'int' object is not callable

Callback error:
   import _testcapi
   def err():
      raise ValueError("xxx")
   _testcapi._test_thread_state(err)
   # no exception raise here
   import gc
   # exception raised too late!
=> ValueError: xxx

So I wrote a patch which fixes that but also raise_exception() which 
have to check that the argument is an exception class.
msg71715 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-08-22 01:44
Python 3.0 has an new function which requires an extra patch: 
exception_print() have to check that the argument is an exception 
instance:

   >>> import _testcapi
   >>> _testcapi.exception_print(10)
   Erreur de segmentation (core dumped)
msg71716 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-08-22 01:56
Your patches are pretty harmless, but this module is just for testing
purposes.
msg71730 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-08-22 08:50
@benjamin.peterson: I know but the module (installed in CPython 
default installation) is for testing purpose only, but invalid uses of 
its method would lead to inconsistent CPython internal state and 
that's bad :-) If you tried to say that such issue is not critical: 
yes, it's just a suggestion to improve CPython ;-)
msg71735 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-08-22 09:33
Unless someone thinks it's somehow release-critical, I'm retargetting
this to 2.7/3.1.
msg71770 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-08-22 19:11
Ok. I'll apply your patches when we get to 2.7. Do ping me if a forget,
though.
msg71808 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-08-23 18:31
@pitrou: This issue is not critical. It's not a bug, it's an 
enhancement since _testcapi :-)
msg71810 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-08-23 19:53
Still, _testcapi is built even for non-debug builds, so it is a
gratuitous way for bad code to crash or internally invalidate a Python
interpreter, so this should be treated like a bugfix.
msg71814 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-08-23 20:33
Fair enough. Fixed in r66000 (trunk) and r66001 (py3k).
History
Date User Action Args
2022-04-11 14:56:38adminsetgithub: 47893
2008-08-23 20:33:11benjamin.petersonsetstatus: open -> closed
resolution: fixed
messages: + msg71814
versions: + Python 2.6, Python 3.0, - Python 3.1, Python 2.7
2008-08-23 19:53:16georg.brandlsetpriority: normal -> high
nosy: + georg.brandl
messages: + msg71810
2008-08-23 18:31:52vstinnersetmessages: + msg71808
2008-08-23 16:39:22ajaksu2setnosy: + ajaksu2
2008-08-22 19:11:34benjamin.petersonsetassignee: benjamin.peterson
messages: + msg71770
2008-08-22 09:33:29pitrousetnosy: + pitrou
messages: + msg71735
versions: + Python 3.1, Python 2.7, - Python 2.6, Python 3.0
2008-08-22 08:50:37vstinnersetmessages: + msg71730
2008-08-22 01:56:21benjamin.petersonsetpriority: normal
nosy: + benjamin.peterson
messages: + msg71716
2008-08-22 01:44:20vstinnersetfiles: + testcapi_py30.patch
messages: + msg71715
2008-08-22 01:41:22vstinnercreate