Correctly declare all variables at beginning of block.

This commit is contained in:
Bastian Kleineidam 2011-04-16 15:25:51 +02:00
parent 0897652669
commit 4c98c463dc
2 changed files with 35 additions and 33 deletions

View file

@ -70,7 +70,7 @@
/* Line 189 of yacc.c */
#line 1 "htmlparse.y"
/* Copyright (C) 2000-2011 Bastian Kleineidam
/* Copyright (C) 2000-2010 Bastian Kleineidam
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -2206,9 +2206,13 @@ static PyObject* parser_flush (parser_object* self, PyObject* args) {
Py_CLEAR(self->userData->tmp_attrname);
self->userData->bufpos = 0;
if (strlen(self->userData->buf)) {
/* set line, col */
int error = 0;
int i;
PyObject* callback = NULL;
PyObject* result = NULL;
const char* enc;
PyObject* s;
/* set line, col */
for (i=0; i<strlen(self->userData->buf); ++i) {
if (self->userData->buf[i] == '\n') {
++(self->userData->lineno);
@ -2216,21 +2220,18 @@ static PyObject* parser_flush (parser_object* self, PyObject* args) {
}
else ++(self->userData->column);
}
const char* enc = PyString_AsString(self->encoding);
PyObject* s = PyUnicode_Decode(self->userData->buf,
(Py_ssize_t)strlen(self->userData->buf),
enc, "ignore");
PyObject* callback = NULL;
PyObject* result = NULL;
/* reset buffer */
CLEAR_BUF(self->userData->buf);
if (s == NULL) { error = 1; goto finish_flush; }
if (PyObject_HasAttrString(self->handler, "characters") == 1) {
callback = PyObject_GetAttrString(self->handler, "characters");
if (callback == NULL) { error = 1; goto finish_flush; }
result = PyObject_CallFunction(callback, "O", s);
if (result == NULL) { error = 1; goto finish_flush; }
}
enc = PyString_AsString(self->encoding);
s = PyUnicode_Decode(self->userData->buf,
(Py_ssize_t)strlen(self->userData->buf), enc, "ignore");
/* reset buffer */
CLEAR_BUF(self->userData->buf);
if (s == NULL) { error = 1; goto finish_flush; }
if (PyObject_HasAttrString(self->handler, "characters") == 1) {
callback = PyObject_GetAttrString(self->handler, "characters");
if (callback == NULL) { error = 1; goto finish_flush; }
result = PyObject_CallFunction(callback, "O", s);
if (result == NULL) { error = 1; goto finish_flush; }
}
finish_flush:
Py_XDECREF(callback);
Py_XDECREF(result);

View file

@ -626,9 +626,13 @@ static PyObject* parser_flush (parser_object* self, PyObject* args) {
Py_CLEAR(self->userData->tmp_attrname);
self->userData->bufpos = 0;
if (strlen(self->userData->buf)) {
/* set line, col */
int error = 0;
int i;
PyObject* callback = NULL;
PyObject* result = NULL;
const char* enc;
PyObject* s;
/* set line, col */
for (i=0; i<strlen(self->userData->buf); ++i) {
if (self->userData->buf[i] == '\n') {
++(self->userData->lineno);
@ -636,21 +640,18 @@ static PyObject* parser_flush (parser_object* self, PyObject* args) {
}
else ++(self->userData->column);
}
const char* enc = PyString_AsString(self->encoding);
PyObject* s = PyUnicode_Decode(self->userData->buf,
(Py_ssize_t)strlen(self->userData->buf),
enc, "ignore");
PyObject* callback = NULL;
PyObject* result = NULL;
/* reset buffer */
CLEAR_BUF(self->userData->buf);
if (s == NULL) { error = 1; goto finish_flush; }
if (PyObject_HasAttrString(self->handler, "characters") == 1) {
callback = PyObject_GetAttrString(self->handler, "characters");
if (callback == NULL) { error = 1; goto finish_flush; }
result = PyObject_CallFunction(callback, "O", s);
if (result == NULL) { error = 1; goto finish_flush; }
}
enc = PyString_AsString(self->encoding);
s = PyUnicode_Decode(self->userData->buf,
(Py_ssize_t)strlen(self->userData->buf), enc, "ignore");
/* reset buffer */
CLEAR_BUF(self->userData->buf);
if (s == NULL) { error = 1; goto finish_flush; }
if (PyObject_HasAttrString(self->handler, "characters") == 1) {
callback = PyObject_GetAttrString(self->handler, "characters");
if (callback == NULL) { error = 1; goto finish_flush; }
result = PyObject_CallFunction(callback, "O", s);
if (result == NULL) { error = 1; goto finish_flush; }
}
finish_flush:
Py_XDECREF(callback);
Py_XDECREF(result);