* Append a PEP3118-formatted field name, ":name:", to str */
| 94 | * Append a PEP3118-formatted field name, ":name:", to str |
| 95 | */ |
| 96 | static 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; |
| 130 | fail: |
| 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, |
no test coverage detected