From b274787c5b13f330435ddc37a70fb81ede33ff39 Mon Sep 17 00:00:00 2001 From: calvin Date: Fri, 8 Dec 2006 22:07:23 +0000 Subject: [PATCH] prepare for Py_ssize_t conversion git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@3530 e7d03fd6-7b0d-0410-9947-9c21f3af8025 --- linkcheck/HtmlParser/htmllex.l | 5 +++-- linkcheck/HtmlParser/htmlparse.y | 4 ++-- linkcheck/HtmlParser/htmlsax.h | 7 +++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/linkcheck/HtmlParser/htmllex.l b/linkcheck/HtmlParser/htmllex.l index 7a91653a..bfb3a890 100644 --- a/linkcheck/HtmlParser/htmllex.l +++ b/linkcheck/HtmlParser/htmllex.l @@ -57,7 +57,8 @@ CHECK_NULL(pencoding = PyObject_GetAttrString(yyextra->parser, "encoding")); \ encoding = PyString_AsString(pencoding); \ if (encoding==NULL) { Py_DECREF(pencoding); return T_ERROR; } \ - (a) = PyUnicode_Decode(yyextra->tmp_buf, strlen(yyextra->tmp_buf), \ + (a) = PyUnicode_Decode(yyextra->tmp_buf, \ + (Py_ssize_t)strlen(yyextra->tmp_buf), \ encoding, "ignore"); \ Py_DECREF(pencoding); \ CHECK_NULL(a); \ @@ -65,7 +66,7 @@ #define PYSTRING_TMP_ASCII(a) \ CHECK_NULL((a) = PyUnicode_Decode(yyextra->tmp_buf, \ - strlen(yyextra->tmp_buf), "ascii", "ignore")) + (Py_ssize_t)strlen(yyextra->tmp_buf), "ascii", "ignore")) /* set return value from tmp_buf */ #define SETLVAL_UNICODE { \ diff --git a/linkcheck/HtmlParser/htmlparse.y b/linkcheck/HtmlParser/htmlparse.y index 4dc45aa8..3d8052eb 100644 --- a/linkcheck/HtmlParser/htmlparse.y +++ b/linkcheck/HtmlParser/htmlparse.y @@ -630,8 +630,8 @@ static PyObject* parser_flush (parser_object* self, PyObject* args) { int error = 0; const char* enc = PyString_AsString(self->encoding); PyObject* s = PyUnicode_Decode(self->userData->buf, - strlen(self->userData->buf), - enc, "ignore"); + (Py_ssize_t)strlen(self->userData->buf), + enc, "ignore"); PyObject* callback = NULL; PyObject* result = NULL; /* reset buffer */ diff --git a/linkcheck/HtmlParser/htmlsax.h b/linkcheck/HtmlParser/htmlsax.h index a5bd3e11..e1db466c 100644 --- a/linkcheck/HtmlParser/htmlsax.h +++ b/linkcheck/HtmlParser/htmlsax.h @@ -31,6 +31,13 @@ #error please install Python >= 2.4 #endif +/* See http://www.python.org/dev/peps/pep-0353/#conversion-guidelines */ +#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) +typedef int Py_ssize_t; +#define PY_SSIZE_T_MAX INT_MAX +#define PY_SSIZE_T_MIN INT_MIN +#endif + /* user_data type for SAX calls */ typedef struct { /* the Python SAX object to issue callbacks */