Mercurial > cpython-lru_cache-weakref
comparison Modules/arraymodule.c @ 4634:9facbab152cd legacy-trunk
Removed some unneeded header files and reedited with a fixed-width font
from emacs as per recomendation from GvR
| author | Roger E. Masse <rmasse@newcnri.cnri.reston.va.us> |
|---|---|
| date | Mon, 09 Dec 1996 22:24:19 +0000 |
| parents | 7df5d4cf8277 |
| children | 911040e1bb11 |
comparison
equal
deleted
inserted
replaced
| 4633:3f10f998a587 | 4634:9facbab152cd |
|---|---|
| 33 | 33 |
| 34 /* An array is a uniform list -- all items have the same type. | 34 /* An array is a uniform list -- all items have the same type. |
| 35 The item type is restricted to simple C types like int or float */ | 35 The item type is restricted to simple C types like int or float */ |
| 36 | 36 |
| 37 #include "Python.h" | 37 #include "Python.h" |
| 38 #include "modsupport.h" | 38 |
| 39 #include "ceval.h" | |
| 40 #ifdef STDC_HEADERS | 39 #ifdef STDC_HEADERS |
| 41 #include <stddef.h> | 40 #include <stddef.h> |
| 42 #else | 41 #else |
| 43 #include <sys/types.h> /* For size_t */ | 42 #include <sys/types.h> /* For size_t */ |
| 44 #endif | 43 #endif |
| 325 return -1; | 324 return -1; |
| 326 } | 325 } |
| 327 if ((*self->ob_descr->setitem)(self, -1, v) < 0) | 326 if ((*self->ob_descr->setitem)(self, -1, v) < 0) |
| 328 return -1; | 327 return -1; |
| 329 items = self->ob_item; | 328 items = self->ob_item; |
| 330 PyMem_RESIZE(items, char, (self->ob_size+1) * self->ob_descr->itemsize); | 329 PyMem_RESIZE(items, char, |
| 330 (self->ob_size+1) * self->ob_descr->itemsize); | |
| 331 if (items == NULL) { | 331 if (items == NULL) { |
| 332 PyErr_NoMemory(); | 332 PyErr_NoMemory(); |
| 333 return -1; | 333 return -1; |
| 334 } | 334 } |
| 335 if (where < 0) | 335 if (where < 0) |
| 778 PyErr_BadArgument(); | 778 PyErr_BadArgument(); |
| 779 return NULL; | 779 return NULL; |
| 780 } | 780 } |
| 781 for (i = 0; i < self->ob_size; i++) { | 781 for (i = 0; i < self->ob_size; i++) { |
| 782 if (PyObject_Compare(self->ob_item[i], args) == 0) { | 782 if (PyObject_Compare(self->ob_item[i], args) == 0) { |
| 783 if (array_ass_slice(self, i, i+1, (PyObject *)NULL) != 0) | 783 if (array_ass_slice(self, i, i+1, |
| 784 (PyObject *)NULL) != 0) | |
| 784 return NULL; | 785 return NULL; |
| 785 Py_INCREF(Py_None); | 786 Py_INCREF(Py_None); |
| 786 return Py_None; | 787 return Py_None; |
| 787 } | 788 } |
| 788 | 789 |
| 943 PyErr_NoMemory(); | 944 PyErr_NoMemory(); |
| 944 return NULL; | 945 return NULL; |
| 945 } | 946 } |
| 946 self->ob_item = item; | 947 self->ob_item = item; |
| 947 self->ob_size += n; | 948 self->ob_size += n; |
| 948 memcpy(item + (self->ob_size - n) * itemsize, str, itemsize*n); | 949 memcpy(item + (self->ob_size - n) * itemsize, |
| 950 str, itemsize*n); | |
| 949 } | 951 } |
| 950 Py_INCREF(Py_None); | 952 Py_INCREF(Py_None); |
| 951 return Py_None; | 953 return Py_None; |
| 952 } | 954 } |
| 953 | 955 |
| 995 return PyInt_FromLong((long)a->ob_descr->itemsize); | 997 return PyInt_FromLong((long)a->ob_descr->itemsize); |
| 996 } | 998 } |
| 997 if (strcmp(name, "__members__") == 0) { | 999 if (strcmp(name, "__members__") == 0) { |
| 998 PyObject *list = PyList_New(2); | 1000 PyObject *list = PyList_New(2); |
| 999 if (list) { | 1001 if (list) { |
| 1000 PyList_SetItem(list, 0, PyString_FromString("typecode")); | 1002 PyList_SetItem(list, 0, |
| 1001 PyList_SetItem(list, 1, PyString_FromString("itemsize")); | 1003 PyString_FromString("typecode")); |
| 1004 PyList_SetItem(list, 1, | |
| 1005 PyString_FromString("itemsize")); | |
| 1002 if (PyErr_Occurred()) { | 1006 if (PyErr_Occurred()) { |
| 1003 Py_DECREF(list); | 1007 Py_DECREF(list); |
| 1004 list = NULL; | 1008 list = NULL; |
| 1005 } | 1009 } |
| 1006 } | 1010 } |
| 1080 PyString_ConcatAndDel(&s, PyString_FromString("])")); | 1084 PyString_ConcatAndDel(&s, PyString_FromString("])")); |
| 1081 return s; | 1085 return s; |
| 1082 } | 1086 } |
| 1083 | 1087 |
| 1084 static PySequenceMethods array_as_sequence = { | 1088 static PySequenceMethods array_as_sequence = { |
| 1085 (inquiry)array_length, /*sq_length*/ | 1089 (inquiry)array_length, /*sq_length*/ |
| 1086 (binaryfunc)array_concat, /*sq_concat*/ | 1090 (binaryfunc)array_concat, /*sq_concat*/ |
| 1087 (intargfunc)array_repeat, /*sq_repeat*/ | 1091 (intargfunc)array_repeat, /*sq_repeat*/ |
| 1088 (intargfunc)array_item, /*sq_item*/ | 1092 (intargfunc)array_item, /*sq_item*/ |
| 1089 (intintargfunc)array_slice, /*sq_slice*/ | 1093 (intintargfunc)array_slice, /*sq_slice*/ |
| 1090 (intobjargproc)array_ass_item, /*sq_ass_item*/ | 1094 (intobjargproc)array_ass_item, /*sq_ass_item*/ |
| 1091 (intintobjargproc)array_ass_slice, /*sq_ass_slice*/ | 1095 (intintobjargproc)array_ass_slice, /*sq_ass_slice*/ |
| 1092 }; | 1096 }; |
| 1093 | 1097 |
| 1095 PyObject_HEAD_INIT(&PyType_Type) | 1099 PyObject_HEAD_INIT(&PyType_Type) |
| 1096 0, | 1100 0, |
| 1097 "array", | 1101 "array", |
| 1098 sizeof(arrayobject), | 1102 sizeof(arrayobject), |
| 1099 0, | 1103 0, |
| 1100 (destructor)array_dealloc, /*tp_dealloc*/ | 1104 (destructor)array_dealloc, /*tp_dealloc*/ |
| 1101 (printfunc)array_print, /*tp_print*/ | 1105 (printfunc)array_print, /*tp_print*/ |
| 1102 (getattrfunc)array_getattr, /*tp_getattr*/ | 1106 (getattrfunc)array_getattr, /*tp_getattr*/ |
| 1103 0, /*tp_setattr*/ | 1107 0, /*tp_setattr*/ |
| 1104 (cmpfunc)array_compare, /*tp_compare*/ | 1108 (cmpfunc)array_compare, /*tp_compare*/ |
| 1105 (reprfunc)array_repr, /*tp_repr*/ | 1109 (reprfunc)array_repr, /*tp_repr*/ |
| 1106 0, /*tp_as_number*/ | 1110 0, /*tp_as_number*/ |
| 1107 &array_as_sequence, /*tp_as_sequence*/ | 1111 &array_as_sequence, /*tp_as_sequence*/ |
| 1121 PyErr_Clear(); | 1125 PyErr_Clear(); |
| 1122 if (!PyArg_Parse(args, "(cO)", &c, &initial)) | 1126 if (!PyArg_Parse(args, "(cO)", &c, &initial)) |
| 1123 return NULL; | 1127 return NULL; |
| 1124 if (!PyList_Check(initial) && !PyString_Check(initial)) { | 1128 if (!PyList_Check(initial) && !PyString_Check(initial)) { |
| 1125 PyErr_SetString(PyExc_TypeError, | 1129 PyErr_SetString(PyExc_TypeError, |
| 1126 "array initializer must be list or string"); | 1130 "array initializer must be list or string"); |
| 1127 return NULL; | 1131 return NULL; |
| 1128 } | 1132 } |
| 1129 } | 1133 } |
| 1130 for (descr = descriptors; descr->typecode != '\0'; descr++) { | 1134 for (descr = descriptors; descr->typecode != '\0'; descr++) { |
| 1131 if (descr->typecode == c) { | 1135 if (descr->typecode == c) { |
| 1159 Py_DECREF(v); | 1163 Py_DECREF(v); |
| 1160 } | 1164 } |
| 1161 return a; | 1165 return a; |
| 1162 } | 1166 } |
| 1163 } | 1167 } |
| 1164 PyErr_SetString(PyExc_ValueError, "bad typecode (must be c, b, h, l, f or d)"); | 1168 PyErr_SetString(PyExc_ValueError, |
| 1169 "bad typecode (must be c, b, h, l, f or d)"); | |
| 1165 return NULL; | 1170 return NULL; |
| 1166 } | 1171 } |
| 1167 | 1172 |
| 1168 static PyMethodDef a_methods[] = { | 1173 static PyMethodDef a_methods[] = { |
| 1169 {"array", a_array}, | 1174 {"array", a_array}, |
