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: Potential Bug in errors.c
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.10
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Ken.Cheung, ezio.melotti, iritkatriel, pablogsal, serhiy.storchaka
Priority: normal Keywords:

Created on 2012-06-19 15:42 by Ken.Cheung, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
errors_clone.txt Ken.Cheung, 2012-06-19 15:42
Messages (4)
msg163181 - (view) Author: Ken Cheung (Ken.Cheung) Date: 2012-06-19 15:42
I observed a code clone from the following files.

function : PyErr_Restore @ (file: "Python-3.3.0a4/Python/errors.c", line: 27)~49
function : PyErr_SetExcInfo @ (file: "Python-3.3.0a4/Python/errors.c", line: 341)~353

The function PyErr_Restore performs some checking on traceback while PyErr_SetExcInfo does not. I wonder if this is necessary in the function PyErr_SetExcInfo. The source code is included in the attachment. Hope it helps.
msg223486 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-19 23:05
From what I can see the code is completely the same in default but does this matter or not?  As a matter of interest is there an official policy regarding code clones, whether in C or pure Python?
msg384248 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-01-03 01:06
The code is not really cloned - note that PyErr_Restore is operating on tstate->curexc (the exception currently being handled) while PyErr_SetExcInfo is operating on tstate->exc_info (the earliest exception currently on the exception stack).

If there is a bug here, I think it is the silent conversion of traceback to NULL in the case where it is neither NULL nor Py_None. (The case in PyErr_Restore that the comment says should not happen).

Otherwise, the difference is that PyErr_Restore transforms Py_None to NULL for the traceback, and PyErr_SetExcInfo doesn't.  That conversion seems neither necessary nor wrong.
msg384251 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-01-03 01:57
Adding extra checks to PyErr_SetExcInfo doesn't have a lot of value because is already out of of contract. If you pass an invalid object (let's say a list) to any of the specific APIs (like PyDict_GetItem) it will crash anyway. We could add some assert, though.
History
Date User Action Args
2022-04-11 14:57:31adminsetgithub: 59311
2021-01-03 02:01:22pablogsalsetstatus: open -> closed
resolution: not a bug
stage: resolved
2021-01-03 01:57:55pablogsalsetnosy: + pablogsal
messages: + msg384251
2021-01-03 01:06:44iritkatrielsetnosy: + iritkatriel

messages: + msg384248
versions: + Python 3.10, - Python 3.4
2019-04-26 20:03:20BreamoreBoysetnosy: - BreamoreBoy
2014-07-19 23:05:11BreamoreBoysetnosy: + BreamoreBoy
messages: + msg223486
2013-04-24 14:22:41ezio.melottisetnosy: + ezio.melotti, serhiy.storchaka

components: + Interpreter Core, - None
versions: + Python 3.4, - Python 3.3
2012-06-19 15:42:52Ken.Cheungcreate