1
0
mirror of https://gitlab.gnome.org/GNOME/libxslt synced 2025-07-01 13:41:39 +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:
Daniel Veillard
2002-05-24 13:03:04 +00:00
parent 918350377b
commit eef2ef13ad
4 changed files with 126 additions and 4 deletions

View File

@ -251,6 +251,118 @@ libxslt_xsltApplyStylesheet(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
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 *
@ -296,15 +408,12 @@ void initlibxsltmod(void) {
return;
m = Py_InitModule((char *)"libxsltmod", libxsltMethods);
initialized = 1;
/* libxslt_xmlErrorInitialize(); */
/*
* Specific XSLT initializations
*/
/* xmlInitParser(); */
libxslt_xsltErrorInitialize();
xmlInitMemory();
/* LIBXML_TEST_VERSION */
xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
/* xmlDefaultSAXHandlerInit(); */
xmlDefaultSAXHandler.cdataBlock = NULL;
}