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: Check for errors when using PyTokenizer_FindEncoding()
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.0
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: amaury.forgeotdarc Nosy List: amaury.forgeotdarc, benjamin.peterson, brett.cannon
Priority: deferred blocker Keywords: patch

Created on 2008-09-04 05:24 by brett.cannon, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
check_findencoding_errors.diff brett.cannon, 2008-09-04 05:24 Call PyErr_Occurred() to verify no error when using PyTokenizer_FindEncoding()
check_findencoding_malloc.diff amaury.forgeotdarc, 2008-09-04 18:09
Messages (10)
msg72484 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-09-04 05:24
The patch adds two lines to call_find_module() to check for errors after
calling PyTokenizer_FindEncoding() since it returns NULL as a default
value so a call to PyErr_Occurred() is needed.
msg72489 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-04 09:39
In PyTokenizer_FindEncoding(), PyMem_MALLOC may return NULL.
Another patch attached.
msg72513 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-09-04 17:45
If PyMem_MALLOC() returns NULL, shouldn't MemoryError be set?
msg72514 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-04 18:09
Right, here is an updated patch
msg72515 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-09-04 19:40
Your patch looks fine, Amaury.
msg72539 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-09-04 22:43
I think this patch should be reverted. It causes a linking error because
pgen isn't linked to libpython; it doesn't find the _PyErr_NoMemory symbol.
msg72542 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-04 22:48
pgen does not exist on Windows...

What if I simply remove the call to PyErr_NoMemory?
It is not strictly necessary: the function already returns NULL without
an exception set, for example when the file cannot be opened.
msg72543 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-09-04 22:50
On Thu, Sep 4, 2008 at 5:48 PM, Amaury Forgeot d'Arc
<report@bugs.python.org> wrote:
>
> Amaury Forgeot d'Arc <amauryfa@gmail.com> added the comment:
>
> pgen does not exist on Windows...
>
> What if I simply remove the call to PyErr_NoMemory?
> It is not strictly necessary: the function already returns NULL without
> an exception set, for example when the file cannot be opened.

That sounds ok. I can't remember what the rest of the parse does when
there's no memory, though.

>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue3773>
> _______________________________________
>
msg72545 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-09-04 22:52
You could also surround the PyErr_NoMemory with #ifndef PGEN.
msg72554 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-04 23:24
committed r66224 + r66225.
History
Date User Action Args
2022-04-11 14:56:38adminsetgithub: 48023
2008-09-04 23:24:33amaury.forgeotdarcsetstatus: open -> closed
resolution: fixed
messages: + msg72554
2008-09-04 22:52:58benjamin.petersonsetmessages: + msg72545
2008-09-04 22:50:15benjamin.petersonsetmessages: + msg72543
2008-09-04 22:48:15amaury.forgeotdarcsetmessages: + msg72542
2008-09-04 22:43:50benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg72539
2008-09-04 19:40:23brett.cannonsetassignee: amaury.forgeotdarc
messages: + msg72515
2008-09-04 18:10:07amaury.forgeotdarcsetfiles: - check_findencoding_malloc.diff
2008-09-04 18:09:45amaury.forgeotdarcsetfiles: + check_findencoding_malloc.diff
messages: + msg72514
2008-09-04 17:45:59brett.cannonsetmessages: + msg72513
2008-09-04 09:39:50amaury.forgeotdarcsetfiles: + check_findencoding_malloc.diff
nosy: + amaury.forgeotdarc
messages: + msg72489
2008-09-04 06:51:42brett.cannonsetpriority: release blocker -> deferred blocker
2008-09-04 06:51:25brett.cannonsettitle: Check for errors -> Check for errors when using PyTokenizer_FindEncoding()
2008-09-04 05:24:14brett.cannoncreate