MCPcopy Create free account
hub / github.com/numpy/numpy / _append_field_name

Function _append_field_name

numpy/core/src/multiarray/buffer.c:96–133  ·  view source on GitHub ↗

* Append a PEP3118-formatted field name, ":name:", to str */

Source from the content-addressed store, hash-verified

94 * Append a PEP3118-formatted field name, ":name:", to str
95 */
96static int
97_append_field_name(_tmp_string_t *str, PyObject *name)
98{
99 int ret = -1;
100 char *p;
101 Py_ssize_t len;
102 PyObject *tmp;
103 /* FIXME: XXX -- should it use UTF-8 here? */
104 tmp = PyUnicode_AsUTF8String(name);
105 if (tmp == NULL || PyBytes_AsStringAndSize(tmp, &p, &len) < 0) {
106 PyErr_Clear();
107 PyErr_SetString(PyExc_ValueError, "invalid field name");
108 goto fail;
109 }
110 if (_append_char(str, ':') < 0) {
111 goto fail;
112 }
113 while (len > 0) {
114 if (*p == ':') {
115 PyErr_SetString(PyExc_ValueError,
116 "':' is not an allowed character in buffer "
117 "field names");
118 goto fail;
119 }
120 if (_append_char(str, *p) < 0) {
121 goto fail;
122 }
123 ++p;
124 --len;
125 }
126 if (_append_char(str, ':') < 0) {
127 goto fail;
128 }
129 ret = 0;
130fail:
131 Py_XDECREF(tmp);
132 return ret;
133}
134
135/*
136 * Return non-zero if a type is aligned in each item in the given array,

Callers 1

_buffer_format_stringFunction · 0.85

Calls 1

_append_charFunction · 0.85

Tested by

no test coverage detected