static int arrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item) { char *key; int n; if (!PyString_Check(ind)) { goto fail; } key = PyString_AS_STRING(ind); n = PyString_GET_SIZE(ind); if (((n==9) && (strncmp(key, "WRITEABLE", n) == 0)) || ((n==1) && (strncmp(key, "W", n) == 0))) { return arrayflags_writeable_set(self, item); } else if (((n==7) && (strncmp(key, "ALIGNED", n) == 0)) || ((n==1) && (strncmp(key, "A", n) == 0))) { return arrayflags_aligned_set(self, item); } else if (((n==12) && (strncmp(key, "UPDATEIFCOPY", n) == 0)) || ((n==1) && (strncmp(key, "U", n) == 0))) { return arrayflags_updateifcopy_set(self, item); } fail: PyErr_SetString(PyExc_KeyError, "Unknown flag"); return -1; }
static int arrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item) { char *key; char buf[16]; int n; if (PyUnicode_Check(ind)) { PyObject *tmp_str; tmp_str = PyUnicode_AsASCIIString(ind); key = PyBytes_AS_STRING(tmp_str); n = PyBytes_GET_SIZE(tmp_str); if (n > 16) n = 16; memcpy(buf, key, n); Py_DECREF(tmp_str); key = buf; } else if (PyBytes_Check(ind)) { key = PyBytes_AS_STRING(ind); n = PyBytes_GET_SIZE(ind); } else { goto fail; } if (((n==9) && (strncmp(key, "WRITEABLE", n) == 0)) || ((n==1) && (strncmp(key, "W", n) == 0))) { return arrayflags_writeable_set(self, item); } else if (((n==7) && (strncmp(key, "ALIGNED", n) == 0)) || ((n==1) && (strncmp(key, "A", n) == 0))) { return arrayflags_aligned_set(self, item); } else if (((n==12) && (strncmp(key, "UPDATEIFCOPY", n) == 0)) || ((n==1) && (strncmp(key, "U", n) == 0))) { return arrayflags_updateifcopy_set(self, item); } else if ((n==6) && (strncmp(key, "MASKNA", n) == 0)) { return arrayflags_maskna_set(self, item); } else if ((n==9) && (strncmp(key, "OWNMASKNA", n) == 0)) { return arrayflags_ownmaskna_set(self, item); } fail: PyErr_SetString(PyExc_KeyError, "Unknown flag"); return -1; }