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 */