[Patches] [ python-Patches-1195571 ] simple callback system for Py_FatalError

SourceForge.net noreply at sourceforge.net
Thu May 5 09:21:06 CEST 2005


Patches item #1195571, was opened at 2005-05-05 01:57
Message generated for change (Comment added) made by mutkuk
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1195571&group_id=5470

Category: Core (C code)
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: m utku (mutkuk)
Assigned to: Nobody/Anonymous (nobody)
Summary: simple callback system for Py_FatalError 

Initial Comment:
Included implementation of a simple callback system for
Py_FatalError.

Everything is done in "pythonrun.c" and "pydebug.h"

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

>Comment By: m utku (mutkuk)
Date: 2005-05-05 10:21

Message:
Logged In: YES 
user_id=1272056

Extension case:
Extension developers may mess up too, why leave them orphaned?

Doc case:
UGGGHHH

Your patch is just slicker, why dont I delete this patch and
you submit. What do you say?

I have just 2 suggestions:
1. Declaration of register func would better be in pydebug.h
near Py_FatalError.

2. Last one to call register func owns the hook, this is
just expected case so IMHO remove NULL check from register func.



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

Comment By: James William Pye (jwpye)
Date: 2005-05-05 09:47

Message:
Logged In: YES 
user_id=1044177

Again, I think this should be explicitly exclusive to an
embedding application, as I cannot imagine a situation where
an extension module should even have access to this facility.

I have done rather limited tests. My application doesn't
seem to like Python 2.5alpha, so I'm going to test the patch
against 2.4.

Sorry to butt into your patch, mutkuk, but here's my
recommendation with docs(ugh, cant attach files):

Index: Doc/api/init.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/api/init.tex,v
retrieving revision 1.23
diff -r1.23 init.tex
39a40,53
>
\begin{cfuncdesc}{void}{Py_InitializeFatalHook}{PyFatalHook fp}
>   Force \cfunction{Py_FatalError()} to invoke the given
function
>   instead of printing to standard error and aborting out
of the
>   process.  This is intended for use in embedded
applications that
>   want to define their own route for handling fatal
errors.  Giving
>   the application the ability to log the error to a special
>   destination, and to do any appropriate cleanups before
exiting.
> 
>   If used, this \emph{must} be called prior to
>   \cfunction{Py_Initialize()}.  Otherwise,
\cfunction{Py_Initialize()}
>   will set the hook to the default, and future attempts to
>   \cfunction{Py_InitializeFatalHook()} will be ignored.
> \end{cfuncdesc}
> 
Index: Include/pythonrun.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/pythonrun.h,v
retrieving revision 2.65
diff -r2.65 pythonrun.h
24a25,27
> typedef void (*PyFatalHook)(const char *);
> PyAPI_FUNC(void) Py_InitializeFatalHook(PyFatalHook);
> 
Index: Python/pythonrun.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v
retrieving revision 2.213
diff -r2.213 pythonrun.c
99a100,109
> static PyFatalHook _fatalhook = NULL;
> 
> void
> Py_InitializeFatalHook(PyFatalHook f)
> {
> 	/* Only set it if it is uninitialized. */
> 	if (_fatalhook == NULL)
> 		_fatalhook = f;
> }
> 
150a161,162
> 	Py_InitializeFatalHook(Py_FatalError);
> 
1507a1520,1523
> 	if (_fatalhook != Py_FatalError && _fatalhook != NULL)
> 		_fatalhook(msg);
> 	/* If the hook fell through, finish the process anyways. */
> 

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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1195571&group_id=5470


More information about the Patches mailing list