comparison Modules/arraymodule.c @ 41587:15b810e21fe9

Get rid of all #ifdef Py_USING_UNICODE (it is always present now). (With the help of unifdef from freshmeat.)
author Guido van Rossum <guido@python.org>
date Thu, 03 May 2007 17:49:24 +0000
parents 06145fbc7ab9
children bab8a9c7f49e
comparison
equal deleted inserted replaced
41586:368fed9af761 41587:15b810e21fe9
168 if (i >= 0) 168 if (i >= 0)
169 ((char *)ap->ob_item)[i] = x; 169 ((char *)ap->ob_item)[i] = x;
170 return 0; 170 return 0;
171 } 171 }
172 172
173 #ifdef Py_USING_UNICODE
174 static PyObject * 173 static PyObject *
175 u_getitem(arrayobject *ap, Py_ssize_t i) 174 u_getitem(arrayobject *ap, Py_ssize_t i)
176 { 175 {
177 return PyUnicode_FromUnicode(&((Py_UNICODE *) ap->ob_item)[i], 1); 176 return PyUnicode_FromUnicode(&((Py_UNICODE *) ap->ob_item)[i], 1);
178 } 177 }
192 } 191 }
193 if (i >= 0) 192 if (i >= 0)
194 ((Py_UNICODE *)ap->ob_item)[i] = p[0]; 193 ((Py_UNICODE *)ap->ob_item)[i] = p[0];
195 return 0; 194 return 0;
196 } 195 }
197 #endif
198 196
199 static PyObject * 197 static PyObject *
200 h_getitem(arrayobject *ap, Py_ssize_t i) 198 h_getitem(arrayobject *ap, Py_ssize_t i)
201 { 199 {
202 return PyInt_FromLong((long) ((short *)ap->ob_item)[i]); 200 return PyInt_FromLong((long) ((short *)ap->ob_item)[i]);
392 /* Description of types */ 390 /* Description of types */
393 static struct arraydescr descriptors[] = { 391 static struct arraydescr descriptors[] = {
394 {'c', sizeof(char), c_getitem, c_setitem}, 392 {'c', sizeof(char), c_getitem, c_setitem},
395 {'b', sizeof(char), b_getitem, b_setitem}, 393 {'b', sizeof(char), b_getitem, b_setitem},
396 {'B', sizeof(char), BB_getitem, BB_setitem}, 394 {'B', sizeof(char), BB_getitem, BB_setitem},
397 #ifdef Py_USING_UNICODE
398 {'u', sizeof(Py_UNICODE), u_getitem, u_setitem}, 395 {'u', sizeof(Py_UNICODE), u_getitem, u_setitem},
399 #endif
400 {'h', sizeof(short), h_getitem, h_setitem}, 396 {'h', sizeof(short), h_getitem, h_setitem},
401 {'H', sizeof(short), HH_getitem, HH_setitem}, 397 {'H', sizeof(short), HH_getitem, HH_setitem},
402 {'i', sizeof(int), i_getitem, i_setitem}, 398 {'i', sizeof(int), i_getitem, i_setitem},
403 {'I', sizeof(int), II_getitem, II_setitem}, 399 {'I', sizeof(int), II_getitem, II_setitem},
404 {'l', sizeof(long), l_getitem, l_setitem}, 400 {'l', sizeof(long), l_getitem, l_setitem},
1428 Convert the array to an array of machine values and return the string\n\ 1424 Convert the array to an array of machine values and return the string\n\
1429 representation."); 1425 representation.");
1430 1426
1431 1427
1432 1428
1433 #ifdef Py_USING_UNICODE
1434 static PyObject * 1429 static PyObject *
1435 array_fromunicode(arrayobject *self, PyObject *args) 1430 array_fromunicode(arrayobject *self, PyObject *args)
1436 { 1431 {
1437 Py_UNICODE *ustr; 1432 Py_UNICODE *ustr;
1438 Py_ssize_t n; 1433 Py_ssize_t n;
1489 Convert the array to a unicode string. The array must be\n\ 1484 Convert the array to a unicode string. The array must be\n\
1490 a type 'u' array; otherwise a ValueError is raised. Use\n\ 1485 a type 'u' array; otherwise a ValueError is raised. Use\n\
1491 array.tostring().decode() to obtain a unicode string from\n\ 1486 array.tostring().decode() to obtain a unicode string from\n\
1492 an array of some other type."); 1487 an array of some other type.");
1493 1488
1494 #endif /* Py_USING_UNICODE */
1495 1489
1496 1490
1497 static PyObject * 1491 static PyObject *
1498 array_get_typecode(arrayobject *a, void *closure) 1492 array_get_typecode(arrayobject *a, void *closure)
1499 { 1493 {
1534 fromfile_doc}, 1528 fromfile_doc},
1535 {"fromlist", (PyCFunction)array_fromlist, METH_O, 1529 {"fromlist", (PyCFunction)array_fromlist, METH_O,
1536 fromlist_doc}, 1530 fromlist_doc},
1537 {"fromstring", (PyCFunction)array_fromstring, METH_VARARGS, 1531 {"fromstring", (PyCFunction)array_fromstring, METH_VARARGS,
1538 fromstring_doc}, 1532 fromstring_doc},
1539 #ifdef Py_USING_UNICODE
1540 {"fromunicode", (PyCFunction)array_fromunicode, METH_VARARGS, 1533 {"fromunicode", (PyCFunction)array_fromunicode, METH_VARARGS,
1541 fromunicode_doc}, 1534 fromunicode_doc},
1542 #endif
1543 {"index", (PyCFunction)array_index, METH_O, 1535 {"index", (PyCFunction)array_index, METH_O,
1544 index_doc}, 1536 index_doc},
1545 {"insert", (PyCFunction)array_insert, METH_VARARGS, 1537 {"insert", (PyCFunction)array_insert, METH_VARARGS,
1546 insert_doc}, 1538 insert_doc},
1547 {"pop", (PyCFunction)array_pop, METH_VARARGS, 1539 {"pop", (PyCFunction)array_pop, METH_VARARGS,
1560 tofile_doc}, 1552 tofile_doc},
1561 {"tolist", (PyCFunction)array_tolist, METH_NOARGS, 1553 {"tolist", (PyCFunction)array_tolist, METH_NOARGS,
1562 tolist_doc}, 1554 tolist_doc},
1563 {"tostring", (PyCFunction)array_tostring, METH_NOARGS, 1555 {"tostring", (PyCFunction)array_tostring, METH_NOARGS,
1564 tostring_doc}, 1556 tostring_doc},
1565 #ifdef Py_USING_UNICODE
1566 {"tounicode", (PyCFunction)array_tounicode, METH_NOARGS, 1557 {"tounicode", (PyCFunction)array_tounicode, METH_NOARGS,
1567 tounicode_doc}, 1558 tounicode_doc},
1568 #endif
1569 {"write", (PyCFunction)array_tofile, METH_O, 1559 {"write", (PyCFunction)array_tofile, METH_O,
1570 tofile_doc}, 1560 tofile_doc},
1571 {NULL, NULL} /* sentinel */ 1561 {NULL, NULL} /* sentinel */
1572 }; 1562 };
1573 1563
1585 return PyString_FromString(buf); 1575 return PyString_FromString(buf);
1586 } 1576 }
1587 1577
1588 if (typecode == 'c') 1578 if (typecode == 'c')
1589 v = array_tostring(a, NULL); 1579 v = array_tostring(a, NULL);
1590 #ifdef Py_USING_UNICODE
1591 else if (typecode == 'u') 1580 else if (typecode == 'u')
1592 v = array_tounicode(a, NULL); 1581 v = array_tounicode(a, NULL);
1593 #endif
1594 else 1582 else
1595 v = array_tolist(a, NULL); 1583 v = array_tolist(a, NULL);
1596 t = PyObject_Repr(v); 1584 t = PyObject_Repr(v);
1597 Py_XDECREF(v); 1585 Py_XDECREF(v);
1598 1586
1897 if (v == NULL) { 1885 if (v == NULL) {
1898 Py_DECREF(a); 1886 Py_DECREF(a);
1899 return NULL; 1887 return NULL;
1900 } 1888 }
1901 Py_DECREF(v); 1889 Py_DECREF(v);
1902 #ifdef Py_USING_UNICODE
1903 } else if (initial != NULL && PyUnicode_Check(initial)) { 1890 } else if (initial != NULL && PyUnicode_Check(initial)) {
1904 Py_ssize_t n = PyUnicode_GET_DATA_SIZE(initial); 1891 Py_ssize_t n = PyUnicode_GET_DATA_SIZE(initial);
1905 if (n > 0) { 1892 if (n > 0) {
1906 arrayobject *self = (arrayobject *)a; 1893 arrayobject *self = (arrayobject *)a;
1907 char *item = self->ob_item; 1894 char *item = self->ob_item;
1914 self->ob_item = item; 1901 self->ob_item = item;
1915 self->ob_size = n / sizeof(Py_UNICODE); 1902 self->ob_size = n / sizeof(Py_UNICODE);
1916 memcpy(item, PyUnicode_AS_DATA(initial), n); 1903 memcpy(item, PyUnicode_AS_DATA(initial), n);
1917 self->allocated = self->ob_size; 1904 self->allocated = self->ob_size;
1918 } 1905 }
1919 #endif
1920 } 1906 }
1921 if (it != NULL) { 1907 if (it != NULL) {
1922 if (array_iter_extend((arrayobject *)a, it) == -1) { 1908 if (array_iter_extend((arrayobject *)a, it) == -1) {
1923 Py_DECREF(it); 1909 Py_DECREF(it);
1924 Py_DECREF(a); 1910 Py_DECREF(a);