summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2011-10-07 18:55:35 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2011-10-07 18:55:35 (GMT)
commitc47adb04b30feea670e87b28efb286db11babaa6 (patch)
tree7b7a3c7fa6227d578a4f1bddac23163170a95c10 /Modules
parentdd07732af5793d7cd6fcd59c470f519709ff3eec (diff)
downloadcpython-c47adb04b30feea670e87b28efb286db11babaa6.zip
cpython-c47adb04b30feea670e87b28efb286db11babaa6.tar.gz
cpython-c47adb04b30feea670e87b28efb286db11babaa6.tar.bz2
Change PyUnicode_KIND to 1,2,4. Drop _KIND_SIZE and _CHARACTER_SIZE.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_io/textio.c44
-rw-r--r--Modules/_json.c4
-rw-r--r--Modules/_sre.c2
3 files changed, 23 insertions, 27 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index 880a5f0..aa29ffb 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -291,9 +291,7 @@ _PyIncrementalNewlineDecoder_decode(PyObject *_self,
kind = PyUnicode_KIND(modified);
out = PyUnicode_DATA(modified);
PyUnicode_WRITE(kind, PyUnicode_DATA(modified), 0, '\r');
- memcpy(out + PyUnicode_KIND_SIZE(kind, 1),
- PyUnicode_DATA(output),
- PyUnicode_KIND_SIZE(kind, output_len));
+ memcpy(out + kind, PyUnicode_DATA(output), kind * output_len);
Py_DECREF(output);
output = modified; /* output remains ready */
self->pendingcr = 0;
@@ -336,7 +334,7 @@ _PyIncrementalNewlineDecoder_decode(PyObject *_self,
for the \r *byte* with the libc's optimized memchr.
*/
if (seennl == SEEN_LF || seennl == 0) {
- only_lf = (memchr(in_str, '\r', PyUnicode_KIND_SIZE(kind, len)) == NULL);
+ only_lf = (memchr(in_str, '\r', kind * len) == NULL);
}
if (only_lf) {
@@ -344,7 +342,7 @@ _PyIncrementalNewlineDecoder_decode(PyObject *_self,
(there's nothing else to be done, even when in translation mode)
*/
if (seennl == 0 &&
- memchr(in_str, '\n', PyUnicode_KIND_SIZE(kind, len)) != NULL) {
+ memchr(in_str, '\n', kind * len) != NULL) {
Py_ssize_t i = 0;
for (;;) {
Py_UCS4 c;
@@ -403,7 +401,7 @@ _PyIncrementalNewlineDecoder_decode(PyObject *_self,
when there is something to translate. On the other hand,
we already know there is a \r byte, so chances are high
that something needs to be done. */
- translated = PyMem_Malloc(PyUnicode_KIND_SIZE(kind, len));
+ translated = PyMem_Malloc(kind * len);
if (translated == NULL) {
PyErr_NoMemory();
goto error;
@@ -1576,15 +1574,14 @@ textiowrapper_read(textio *self, PyObject *args)
static char *
find_control_char(int kind, char *s, char *end, Py_UCS4 ch)
{
- int size = PyUnicode_KIND_SIZE(kind, 1);
for (;;) {
while (PyUnicode_READ(kind, s, 0) > ch)
- s += size;
+ s += kind;
if (PyUnicode_READ(kind, s, 0) == ch)
return s;
if (s == end)
return NULL;
- s += size;
+ s += kind;
}
}
@@ -1593,14 +1590,13 @@ _PyIO_find_line_ending(
int translated, int universal, PyObject *readnl,
int kind, char *start, char *end, Py_ssize_t *consumed)
{
- int size = PyUnicode_KIND_SIZE(kind, 1);
- Py_ssize_t len = ((char*)end - (char*)start)/size;
+ Py_ssize_t len = ((char*)end - (char*)start)/kind;
if (translated) {
/* Newlines are already translated, only search for \n */
char *pos = find_control_char(kind, start, end, '\n');
if (pos != NULL)
- return (pos - start)/size + 1;
+ return (pos - start)/kind + 1;
else {
*consumed = len;
return -1;
@@ -1616,20 +1612,20 @@ _PyIO_find_line_ending(
/* Fast path for non-control chars. The loop always ends
since the Unicode string is NUL-terminated. */
while (PyUnicode_READ(kind, s, 0) > '\r')
- s += size;
+ s += kind;
if (s >= end) {
*consumed = len;
return -1;
}
ch = PyUnicode_READ(kind, s, 0);
- s += size;
+ s += kind;
if (ch == '\n')
- return (s - start)/size;
+ return (s - start)/kind;
if (ch == '\r') {
if (PyUnicode_READ(kind, s, 0) == '\n')
- return (s - start)/size + 1;
+ return (s - start)/kind + 1;
else
- return (s - start)/size;
+ return (s - start)/kind;
}
}
}
@@ -1642,13 +1638,13 @@ _PyIO_find_line_ending(
if (readnl_len == 1) {
char *pos = find_control_char(kind, start, end, nl[0]);
if (pos != NULL)
- return (pos - start)/size + 1;
+ return (pos - start)/kind + 1;
*consumed = len;
return -1;
}
else {
char *s = start;
- char *e = end - (readnl_len - 1)*size;
+ char *e = end - (readnl_len - 1)*kind;
char *pos;
if (e < s)
e = s;
@@ -1662,14 +1658,14 @@ _PyIO_find_line_ending(
break;
}
if (i == readnl_len)
- return (pos - start)/size + readnl_len;
- s = pos + size;
+ return (pos - start)/kind + readnl_len;
+ s = pos + kind;
}
pos = find_control_char(kind, e, end, nl[0]);
if (pos == NULL)
*consumed = len;
else
- *consumed = (pos - start)/size;
+ *consumed = (pos - start)/kind;
return -1;
}
}
@@ -1738,8 +1734,8 @@ _textiowrapper_readline(textio *self, Py_ssize_t limit)
endpos = _PyIO_find_line_ending(
self->readtranslate, self->readuniversal, self->readnl,
kind,
- ptr + PyUnicode_KIND_SIZE(kind, start),
- ptr + PyUnicode_KIND_SIZE(kind, line_len),
+ ptr + kind * start,
+ ptr + kind * line_len,
&consumed);
if (endpos >= 0) {
endpos += start;
diff --git a/Modules/_json.c b/Modules/_json.c
index 0f550c1..e49d1b2 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -365,7 +365,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
APPEND_OLD_CHUNK
chunk = PyUnicode_FromKindAndData(
kind,
- (char*)buf + PyUnicode_KIND_SIZE(kind, end),
+ (char*)buf + kind * end,
next - end);
if (chunk == NULL) {
goto bail;
@@ -931,7 +931,7 @@ _match_number_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t start, Py_
if (custom_func) {
/* copy the section we determined to be a number */
numstr = PyUnicode_FromKindAndData(kind,
- (char*)str + PyUnicode_KIND_SIZE(kind, start),
+ (char*)str + kind * start,
idx - start);
if (numstr == NULL)
return NULL;
diff --git a/Modules/_sre.c b/Modules/_sre.c
index c685bae..395a120 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -1669,7 +1669,7 @@ getstring(PyObject* string, Py_ssize_t* p_length,
return NULL;
ptr = PyUnicode_DATA(string);
*p_length = PyUnicode_GET_LENGTH(string);
- *p_charsize = PyUnicode_CHARACTER_SIZE(string);
+ *p_charsize = PyUnicode_KIND(string);
*p_logical_charsize = 4;
return ptr;
}