diff options
Diffstat (limited to 'Modules/pyexpat.c')
| -rw-r--r-- | Modules/pyexpat.c | 26 | 
1 files changed, 9 insertions, 17 deletions
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index 9a6da737fb..2dafbb03a5 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -91,7 +91,7 @@ static struct HandlerInfo handler_info[64];   * false on an exception.   */  static int -set_error_attr(PyObject *err, char *name, int value) +set_error_attr(PyObject *err, const char *name, int value)  {      PyObject *v = PyLong_FromLong(value); @@ -218,7 +218,7 @@ flag_error(xmlparseobject *self)  }  static PyObject* -call_with_frame(char *funcname, int lineno, PyObject* func, PyObject* args, +call_with_frame(const char *funcname, int lineno, PyObject* func, PyObject* args,                  xmlparseobject *self)  {      PyObject *res; @@ -747,7 +747,8 @@ pyexpat_xmlparser_Parse_impl(xmlparseobject *self, PyObject *data,          s += MAX_CHUNK_SIZE;          slen -= MAX_CHUNK_SIZE;      } -    assert(MAX_CHUNK_SIZE < INT_MAX && slen < INT_MAX); +    Py_BUILD_ASSERT(MAX_CHUNK_SIZE <= INT_MAX); +    assert(slen <= INT_MAX);      rc = XML_Parse(self->itself, s, (int)slen, isfinal);  done: @@ -765,7 +766,7 @@ readinst(char *buf, int buf_size, PyObject *meth)  {      PyObject *str;      Py_ssize_t len; -    char *ptr; +    const char *ptr;      str = PyObject_CallFunction(meth, "n", buf_size);      if (str == NULL) @@ -1225,12 +1226,8 @@ xmlparse_dealloc(xmlparseobject *self)      self->itself = NULL;      if (self->handlers != NULL) { -        PyObject *temp; -        for (i = 0; handler_info[i].name != NULL; i++) { -            temp = self->handlers[i]; -            self->handlers[i] = NULL; -            Py_XDECREF(temp); -        } +        for (i = 0; handler_info[i].name != NULL; i++) +            Py_CLEAR(self->handlers[i]);          PyMem_Free(self->handlers);          self->handlers = NULL;      } @@ -1344,7 +1341,6 @@ sethandler(xmlparseobject *self, PyObject *name, PyObject* v)      int handlernum = handlername2int(name);      if (handlernum >= 0) {          xmlhandler c_handler = NULL; -        PyObject *temp = self->handlers[handlernum];          if (v == Py_None) {              /* If this is the character data handler, and a character @@ -1366,8 +1362,7 @@ sethandler(xmlparseobject *self, PyObject *name, PyObject* v)              Py_INCREF(v);              c_handler = handler_info[handlernum].handler;          } -        self->handlers[handlernum] = v; -        Py_XDECREF(temp); +        Py_XSETREF(self->handlers[handlernum], v);          handler_info[handlernum].setter(self->itself, c_handler);          return 1;      } @@ -1897,15 +1892,12 @@ static void  clear_handlers(xmlparseobject *self, int initial)  {      int i = 0; -    PyObject *temp;      for (; handler_info[i].name != NULL; i++) {          if (initial)              self->handlers[i] = NULL;          else { -            temp = self->handlers[i]; -            self->handlers[i] = NULL; -            Py_XDECREF(temp); +            Py_CLEAR(self->handlers[i]);              handler_info[i].setter(self->itself, NULL);          }      }  | 
