summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Roberts <Ademan555@gmail.com>2011-02-17 13:56:32 -0800
committerArmin Ronacher <armin.ronacher@active-4.com>2011-02-17 23:12:35 +0100
commit0dff0a079d55abd0e441d55693b605ff6d69c50a (patch)
treea7f00b585fa066d99774e8b6a396d33f2e28ef9d
parent414929fec00bab788181115fe6a76252985aa6c8 (diff)
downloadmarkupsafe-0dff0a079d55abd0e441d55693b605ff6d69c50a.tar.gz
Changed PyUnicodeObject struct access into official CPython Macro uses. The macros evaluate to the same code, but this makes it possible to use with PyPy.
Signed-off-by: Armin Ronacher <armin.ronacher@active-4.com>
-rw-r--r--markupsafe/_speedups.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/markupsafe/_speedups.c b/markupsafe/_speedups.c
index 8b0325e..2a09b42 100644
--- a/markupsafe/_speedups.c
+++ b/markupsafe/_speedups.c
@@ -12,7 +12,7 @@
#include <Python.h>
#define ESCAPED_CHARS_TABLE_SIZE 63
-#define UNICHR(x) (((PyUnicodeObject*)PyUnicode_DecodeASCII(x, strlen(x), NULL))->str);
+#define UNICHR(x) (PyUnicode_AS_UNICODE((PyUnicodeObject*)PyUnicode_DecodeASCII(x, strlen(x), NULL)));
#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
typedef int Py_ssize_t;
@@ -56,8 +56,8 @@ static PyObject*
escape_unicode(PyUnicodeObject *in)
{
PyUnicodeObject *out;
- Py_UNICODE *inp = in->str;
- const Py_UNICODE *inp_end = in->str + in->length;
+ Py_UNICODE *inp = PyUnicode_AS_UNICODE(in);
+ const Py_UNICODE *inp_end = PyUnicode_AS_UNICODE(in) + PyUnicode_GET_SIZE(in);
Py_UNICODE *next_escp;
Py_UNICODE *outp;
Py_ssize_t delta=0, erepl=0, delta_len=0;
@@ -77,12 +77,12 @@ escape_unicode(PyUnicodeObject *in)
return (PyObject*)in;
}
- out = (PyUnicodeObject*)PyUnicode_FromUnicode(NULL, in->length + delta);
+ out = (PyUnicodeObject*)PyUnicode_FromUnicode(NULL, PyUnicode_GET_SIZE(in) + delta);
if (!out)
return NULL;
- outp = out->str;
- inp = in->str;
+ outp = PyUnicode_AS_UNICODE(out);
+ inp = PyUnicode_AS_UNICODE(in);
while (erepl-- > 0) {
/* look for the next substitution */
next_escp = inp;
@@ -108,7 +108,7 @@ escape_unicode(PyUnicodeObject *in)
inp = next_escp + 1;
}
if (inp < inp_end)
- Py_UNICODE_COPY(outp, inp, in->length - (inp - in->str));
+ Py_UNICODE_COPY(outp, inp, PyUnicode_GET_SIZE(in) - (inp - PyUnicode_AS_UNICODE(in)));
return (PyObject*)out;
}