[Python-bugs-list] [Bug #112628] many extensions (wrongly?) use Py_FatalError

noreply@sourceforge.net noreply@sourceforge.net
Fri, 1 Sep 2000 02:01:37 -0700


Bug #112628, was updated on 2000-Aug-24 04:50
Here is a current snapshot of the bug.

Project: Python
Category: Modules
Status: Closed
Resolution: Fixed
Bug Group: None
Priority: 7
Summary: many extensions (wrongly?) use Py_FatalError 

Details: Many of the modules in the current CVS tree are handling errors in a
manner which I find unpythonic. A typical example is pyexpat.c which at
the end of initpyexpat does
    /* Check for errors */
    if (PyErr_Occurred())
        Py_FatalError("can't initialize module pyexpat");

the xml-sig group might regard this as a tragedy, but I might wish to
continue and use another parser. The correct behaviour for this sort of
error ought IMHO to be to raise an ImportError clean up any privately
allocated resources and return.

c sources which raise fatal errors

_cursesmodule.c:
_localemodule.c:
_tkinter.c:
almodule.c:
cdmodule.c:
errnomodule.c:
fcntlmodule.c:
fpectlmodule.c:
linuxaudiodev.c:
main.c:
mathmodule.c:
mpzmodule.c:
parsermodule.c:
pcremodule.c:
posixmodule.c:
puremodule.c:
pyexpat.c:
shamodule.c:
stropmodule.c:
syslogmodule.c:
timemodule.c:
timingmodule.c:

Follow-Ups:

Date: 2000-Aug-24 05:54
By: gvanrossum

Comment:
He's right!  The proper solution is

  if (PyErr_Occurred())
         return;

since the module initialization code explicitly checks for errors raised by the module's init function.

Assigned to Jeremy for pronouncement or delegation.
-------------------------------------------------------

Date: 2000-Aug-24 07:54
By: bwarsaw

Comment:
In that case, the PyErr_Occurred() call is /usually/ not necessary, since it's done as the last thing in the init() function and would just return anyway.  So given Guido's pronouncement, most of those checks can just be removed.
-------------------------------------------------------

Date: 2000-Sep-01 01:44
By: bwarsaw

Comment:
Fixed by removing PyErr_Occurred() checks and Py_FatalError() calls from module init functions.

-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=112628&group_id=5470