previous fix for #124044 was broken, correct fix provided. fix

* python/libxml.c: previous fix for #124044 was broken, correct
  fix provided.
* HTMLparser.c parser.c parserInternals.c xmlIO.c: fix xmlStopParser()
  and the error handlers to address #125877
Daniel
diff --git a/ChangeLog b/ChangeLog
index 08ae843..dea79b4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Fri Oct 31 11:33:18 CET 2003 Daniel Veillard <daniel@veillard.com>
+
+	* python/libxml.c: previous fix for #124044 was broken, correct
+	  fix provided.
+	* HTMLparser.c parser.c parserInternals.c xmlIO.c: fix xmlStopParser()
+	  and the error handlers to address #125877
+
 Thu Oct 30 23:10:46 CET 2003 Daniel Veillard <daniel@veillard.com>
 
 	* parser.c: side effect of #123105 patch, namespace resolution
diff --git a/HTMLparser.c b/HTMLparser.c
index 5e9b2c4..fa9519d 100644
--- a/HTMLparser.c
+++ b/HTMLparser.c
@@ -73,6 +73,9 @@
 static void
 htmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra)
 {
+    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
+        (ctxt->instate == XML_PARSER_EOF))
+	return;
     if (ctxt != NULL) {
         ctxt->errNo = XML_ERR_NO_MEMORY;
         ctxt->instate = XML_PARSER_EOF;
@@ -103,6 +106,9 @@
 htmlParseErr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
              const char *msg, const xmlChar *str1, const xmlChar *str2)
 {
+    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
+        (ctxt->instate == XML_PARSER_EOF))
+	return;
     ctxt->errNo = error;
     __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_HTML, error,
                     XML_ERR_ERROR, NULL, 0,
@@ -125,6 +131,9 @@
 htmlParseErrInt(xmlParserCtxtPtr ctxt, xmlParserErrors error,
              const char *msg, int val)
 {
+    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
+        (ctxt->instate == XML_PARSER_EOF))
+	return;
     ctxt->errNo = error;
     __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_HTML, error,
                     XML_ERR_ERROR, NULL, 0, NULL, NULL,
diff --git a/parser.c b/parser.c
index 7924146..64f670f 100644
--- a/parser.c
+++ b/parser.c
@@ -141,6 +141,9 @@
 xmlErrAttributeDup(xmlParserCtxtPtr ctxt, const xmlChar * prefix,
                    const xmlChar * localname)
 {
+    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
+        (ctxt->instate == XML_PARSER_EOF))
+	return;
     ctxt->errNo = XML_ERR_ATTRIBUTE_REDEFINED;
     if (prefix == NULL)
         __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
@@ -171,6 +174,9 @@
 {
     const char *errmsg;
 
+    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
+        (ctxt->instate == XML_PARSER_EOF))
+	return;
     switch (error) {
         case XML_ERR_INVALID_HEX_CHARREF:
             errmsg = "CharRef: invalid hexadecimal value\n";
@@ -371,6 +377,9 @@
 xmlFatalErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
                const char *msg)
 {
+    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
+        (ctxt->instate == XML_PARSER_EOF))
+	return;
     ctxt->errNo = error;
     __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
                     XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, 0, 0, msg);
@@ -395,6 +404,9 @@
 {
     xmlStructuredErrorFunc schannel = NULL;
     
+    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
+        (ctxt->instate == XML_PARSER_EOF))
+	return;
     ctxt->errNo = error;
     if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC))
         schannel = ctxt->sax->serror;
@@ -421,6 +433,10 @@
               const char *msg, const xmlChar *str1)
 {
     xmlStructuredErrorFunc schannel = NULL;
+
+    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
+        (ctxt->instate == XML_PARSER_EOF))
+	return;
     ctxt->errNo = error;
     if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC))
         schannel = ctxt->sax->serror;
@@ -446,6 +462,9 @@
 xmlFatalErrMsgInt(xmlParserCtxtPtr ctxt, xmlParserErrors error,
                   const char *msg, int val)
 {
+    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
+        (ctxt->instate == XML_PARSER_EOF))
+	return;
     ctxt->errNo = error;
     __xmlRaiseError(NULL, NULL, NULL,
                     ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL,
@@ -471,6 +490,9 @@
                   const char *msg, const xmlChar *str1, int val, 
 		  const xmlChar *str2)
 {
+    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
+        (ctxt->instate == XML_PARSER_EOF))
+	return;
     ctxt->errNo = error;
     __xmlRaiseError(NULL, NULL, NULL,
                     ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL,
@@ -494,6 +516,9 @@
 xmlFatalErrMsgStr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
                   const char *msg, const xmlChar * val)
 {
+    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
+        (ctxt->instate == XML_PARSER_EOF))
+	return;
     ctxt->errNo = error;
     __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL,
                     XML_FROM_PARSER, error, XML_ERR_FATAL,
@@ -517,6 +542,9 @@
 xmlErrMsgStr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
                   const char *msg, const xmlChar * val)
 {
+    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
+        (ctxt->instate == XML_PARSER_EOF))
+	return;
     ctxt->errNo = error;
     __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL,
                     XML_FROM_PARSER, error, XML_ERR_ERROR,
@@ -540,6 +568,9 @@
          const xmlChar * info1, const xmlChar * info2,
          const xmlChar * info3)
 {
+    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
+        (ctxt->instate == XML_PARSER_EOF))
+	return;
     ctxt->errNo = error;
     __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error,
                     XML_ERR_ERROR, NULL, 0, (const char *) info1,
@@ -10126,7 +10157,10 @@
  */
 void           
 xmlStopParser(xmlParserCtxtPtr ctxt) {
+    if (ctxt == NULL)
+        return;
     ctxt->instate = XML_PARSER_EOF;
+    ctxt->disableSAX = 1;
     if (ctxt->input != NULL)
 	ctxt->input->cur = BAD_CAST"";
 }
diff --git a/parserInternals.c b/parserInternals.c
index 7d18788..67fbd63 100644
--- a/parserInternals.c
+++ b/parserInternals.c
@@ -105,6 +105,9 @@
 void
 xmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra)
 {
+    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
+        (ctxt->instate == XML_PARSER_EOF))
+	return;
     if (ctxt != NULL) {
         ctxt->errNo = XML_ERR_NO_MEMORY;
         ctxt->instate = XML_PARSER_EOF;
@@ -135,6 +138,9 @@
 __xmlErrEncoding(xmlParserCtxtPtr ctxt, xmlParserErrors error,
                  const char *msg, const xmlChar * str1, const xmlChar * str2)
 {
+    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
+        (ctxt->instate == XML_PARSER_EOF))
+	return;
     if (ctxt != NULL)
         ctxt->errNo = error;
     __xmlRaiseError(NULL, NULL, NULL,
@@ -159,6 +165,9 @@
 static void
 xmlErrInternal(xmlParserCtxtPtr ctxt, const char *msg, const xmlChar * str)
 {
+    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
+        (ctxt->instate == XML_PARSER_EOF))
+	return;
     if (ctxt != NULL)
         ctxt->errNo = XML_ERR_INTERNAL_ERROR;
     __xmlRaiseError(NULL, NULL, NULL,
@@ -185,6 +194,9 @@
 xmlErrEncodingInt(xmlParserCtxtPtr ctxt, xmlParserErrors error,
                   const char *msg, int val)
 {
+    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
+        (ctxt->instate == XML_PARSER_EOF))
+	return;
     if (ctxt != NULL)
         ctxt->errNo = error;
     __xmlRaiseError(NULL, NULL, NULL,
diff --git a/python/libxml.c b/python/libxml.c
index 2ae1856..bf4c652 100644
--- a/python/libxml.c
+++ b/python/libxml.c
@@ -1644,12 +1644,12 @@
     xmlTextReaderErrorFunc f;
     void *arg;
 
-    if (self == NULL) {
+    if (!PyArg_ParseTuple(args, (char *)"O:xmlFreeTextReader", &pyobj_reader))
+        return(NULL);
+    if (!PyCObject_Check(pyobj_reader)) {
 	Py_INCREF(Py_None);
 	return(Py_None);
     }
-    if (!PyArg_ParseTuple(args, (char *)"O:xmlFreeTextReader", &pyobj_reader))
-        return(NULL);
     reader = (xmlTextReaderPtr) PyxmlTextReader_Get(pyobj_reader);
     if (reader == NULL) {
 	Py_INCREF(Py_None);
diff --git a/xmlIO.c b/xmlIO.c
index f93c497..33c544b 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -409,6 +409,9 @@
     void *data = NULL;
     xmlErrorLevel level = XML_ERR_ERROR;
 
+    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
+        (ctxt->instate == XML_PARSER_EOF))
+	return;
     if ((ctxt != NULL) && (ctxt->sax != NULL)) {
         if (ctxt->validate) {
 	    channel = ctxt->sax->error;