mirror of
https://gitlab.gnome.org/GNOME/libxslt
synced 2025-07-29 15:41:13 +03:00
tried to fix #79105 by providing a specific error registering routine.
* python/libxslt-python-api.xml python/libxslt.c python/libxsltclass.txt : tried to fix #79105 by providing a specific error registering routine. Daniel
This commit is contained in:
@ -1,3 +1,9 @@
|
|||||||
|
Fri May 24 15:02:50 CEST 2002 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
|
* python/libxslt-python-api.xml python/libxslt.c
|
||||||
|
python/libxsltclass.txt : tried to fix #79105 by providing a
|
||||||
|
specific error registering routine.
|
||||||
|
|
||||||
Thu May 23 17:28:35 CEST 2002 Daniel Veillard <daniel@veillard.com>
|
Thu May 23 17:28:35 CEST 2002 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
* libxslt/xsltutils.[ch] : applied patch from Morus Walter
|
* libxslt/xsltutils.[ch] : applied patch from Morus Walter
|
||||||
|
@ -12,6 +12,12 @@
|
|||||||
<arg name='doc' type='xmlDocPtr' info='a parsed XML document'/>
|
<arg name='doc' type='xmlDocPtr' info='a parsed XML document'/>
|
||||||
<arg name='params' type='pythonObject' info='the parameters dictionnary'/>
|
<arg name='params' type='pythonObject' info='the parameters dictionnary'/>
|
||||||
</function>
|
</function>
|
||||||
|
<function name='xsltRegisterErrorHandler' file='python'>
|
||||||
|
<info>Register a Python written function to for error reporting. The function is called back as f(ctx, error).</info>
|
||||||
|
<return type='int' info="1 in case of success, 0 or -1 in case of error"/>
|
||||||
|
<arg name='f' type='pythonObject' info='the python function'/>
|
||||||
|
<arg name='ctx' type='pythonObject' info='a context for the callback'/>
|
||||||
|
</function>
|
||||||
<function name='xsltRegisterExtModuleFunction' file='python'>
|
<function name='xsltRegisterExtModuleFunction' file='python'>
|
||||||
<info>Register a Python written function to the XSLT engine</info>
|
<info>Register a Python written function to the XSLT engine</info>
|
||||||
<return type='int' info="0 in case of success, -1 in case of error"/>
|
<return type='int' info="0 in case of success, -1 in case of error"/>
|
||||||
|
117
python/libxslt.c
117
python/libxslt.c
@ -251,6 +251,118 @@ libxslt_xsltApplyStylesheet(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
|
|||||||
return(py_retval);
|
return(py_retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* *
|
||||||
|
* Error message callback *
|
||||||
|
* *
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
static PyObject *libxslt_xsltPythonErrorFuncHandler = NULL;
|
||||||
|
static PyObject *libxslt_xsltPythonErrorFuncCtxt = NULL;
|
||||||
|
|
||||||
|
static void
|
||||||
|
libxslt_xsltErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
int size;
|
||||||
|
int chars;
|
||||||
|
char *larger;
|
||||||
|
va_list ap;
|
||||||
|
char *str;
|
||||||
|
PyObject *list;
|
||||||
|
PyObject *message;
|
||||||
|
PyObject *result;
|
||||||
|
|
||||||
|
#ifdef DEBUG_ERROR
|
||||||
|
printf("libxslt_xsltErrorFuncHandler(%p, %s, ...) called\n", ctx, msg);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
if (libxslt_xsltPythonErrorFuncHandler == NULL) {
|
||||||
|
va_start(ap, msg);
|
||||||
|
vfprintf(stdout, msg, ap);
|
||||||
|
va_end(ap);
|
||||||
|
} else {
|
||||||
|
str = (char *) xmlMalloc(150);
|
||||||
|
if (str == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
size = 150;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
va_start(ap, msg);
|
||||||
|
chars = vsnprintf(str, size, msg, ap);
|
||||||
|
va_end(ap);
|
||||||
|
if ((chars > -1) && (chars < size))
|
||||||
|
break;
|
||||||
|
if (chars > -1)
|
||||||
|
size += chars + 1;
|
||||||
|
else
|
||||||
|
size += 100;
|
||||||
|
if ((larger = (char *) xmlRealloc(str, size)) == NULL) {
|
||||||
|
xmlFree(str);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
str = larger;
|
||||||
|
}
|
||||||
|
|
||||||
|
list = PyTuple_New(2);
|
||||||
|
PyTuple_SetItem(list, 0, libxslt_xsltPythonErrorFuncCtxt);
|
||||||
|
Py_XINCREF(libxslt_xsltPythonErrorFuncCtxt);
|
||||||
|
message = libxml_charPtrWrap(str);
|
||||||
|
PyTuple_SetItem(list, 1, message);
|
||||||
|
result = PyEval_CallObject(libxslt_xsltPythonErrorFuncHandler, list);
|
||||||
|
Py_XDECREF(list);
|
||||||
|
Py_XDECREF(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
libxslt_xsltErrorInitialize(void)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_ERROR
|
||||||
|
printf("libxslt_xsltErrorInitialize() called\n");
|
||||||
|
#endif
|
||||||
|
xmlSetGenericErrorFunc(NULL, libxslt_xsltErrorFuncHandler);
|
||||||
|
xsltSetGenericErrorFunc(NULL, libxslt_xsltErrorFuncHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
libxslt_xsltRegisterErrorHandler(ATTRIBUTE_UNUSED PyObject * self,
|
||||||
|
PyObject * args)
|
||||||
|
{
|
||||||
|
PyObject *py_retval;
|
||||||
|
PyObject *pyobj_f;
|
||||||
|
PyObject *pyobj_ctx;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple
|
||||||
|
(args, (char *) "OO:xmlRegisterErrorHandler", &pyobj_f,
|
||||||
|
&pyobj_ctx))
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
#ifdef DEBUG_ERROR
|
||||||
|
printf("libxml_registerXPathFunction(%p, %p) called\n", pyobj_ctx,
|
||||||
|
pyobj_f);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (libxslt_xsltPythonErrorFuncHandler != NULL) {
|
||||||
|
Py_XDECREF(libxslt_xsltPythonErrorFuncHandler);
|
||||||
|
}
|
||||||
|
if (libxslt_xsltPythonErrorFuncCtxt != NULL) {
|
||||||
|
Py_XDECREF(libxslt_xsltPythonErrorFuncCtxt);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_XINCREF(pyobj_ctx);
|
||||||
|
Py_XINCREF(pyobj_f);
|
||||||
|
|
||||||
|
/* TODO: check f is a function ! */
|
||||||
|
libxslt_xsltPythonErrorFuncHandler = pyobj_f;
|
||||||
|
libxslt_xsltPythonErrorFuncCtxt = pyobj_ctx;
|
||||||
|
|
||||||
|
py_retval = libxml_intWrap(1);
|
||||||
|
return (py_retval);
|
||||||
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* *
|
* *
|
||||||
* Integrated cleanup *
|
* Integrated cleanup *
|
||||||
@ -296,15 +408,12 @@ void initlibxsltmod(void) {
|
|||||||
return;
|
return;
|
||||||
m = Py_InitModule((char *)"libxsltmod", libxsltMethods);
|
m = Py_InitModule((char *)"libxsltmod", libxsltMethods);
|
||||||
initialized = 1;
|
initialized = 1;
|
||||||
/* libxslt_xmlErrorInitialize(); */
|
|
||||||
/*
|
/*
|
||||||
* Specific XSLT initializations
|
* Specific XSLT initializations
|
||||||
*/
|
*/
|
||||||
/* xmlInitParser(); */
|
libxslt_xsltErrorInitialize();
|
||||||
xmlInitMemory();
|
xmlInitMemory();
|
||||||
/* LIBXML_TEST_VERSION */
|
|
||||||
xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
|
xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
|
||||||
/* xmlDefaultSAXHandlerInit(); */
|
|
||||||
xmlDefaultSAXHandler.cdataBlock = NULL;
|
xmlDefaultSAXHandler.cdataBlock = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ registerAllExtras()
|
|||||||
|
|
||||||
# functions from module python
|
# functions from module python
|
||||||
cleanup()
|
cleanup()
|
||||||
|
registerErrorHandler()
|
||||||
registerExtModuleFunction()
|
registerExtModuleFunction()
|
||||||
|
|
||||||
# functions from module transform
|
# functions from module transform
|
||||||
|
Reference in New Issue
Block a user