| 4932 | } |
| 4933 | |
| 4934 | static PyObject *Str_concat(PyObject *self, PyObject *other) { |
| 4935 | struct sz_string_view_t self_str, other_str; |
| 4936 | |
| 4937 | // Validate and convert `self` and `other` |
| 4938 | if (!sz_py_export_string_like(self, &self_str.start, &self_str.length) || |
| 4939 | !sz_py_export_string_like(other, &other_str.start, &other_str.length)) { |
| 4940 | wrap_current_exception("Both operands must be string-like"); |
| 4941 | return NULL; |
| 4942 | } |
| 4943 | |
| 4944 | // Allocate a new Str instance |
| 4945 | Str *result_str = PyObject_New(Str, &StrType); |
| 4946 | if (result_str == NULL) { return NULL; } |
| 4947 | |
| 4948 | // Calculate the total length of the new string |
| 4949 | result_str->parent = NULL; |
| 4950 | result_str->memory.length = self_str.length + other_str.length; |
| 4951 | |
| 4952 | // Allocate memory for the new string |
| 4953 | result_str->memory.start = malloc(result_str->memory.length); |
| 4954 | if (result_str->memory.start == NULL) { |
| 4955 | PyErr_SetString(PyExc_MemoryError, "Unable to allocate memory for string concatenation"); |
| 4956 | return NULL; |
| 4957 | } |
| 4958 | |
| 4959 | // Perform the string concatenation |
| 4960 | sz_copy(result_str->memory.start, self_str.start, self_str.length); |
| 4961 | sz_copy(result_str->memory.start + self_str.length, other_str.start, other_str.length); |
| 4962 | |
| 4963 | return (PyObject *)result_str; |
| 4964 | } |
| 4965 | |
| 4966 | static PySequenceMethods Str_as_sequence = { |
| 4967 | .sq_length = Str_len, // |
nothing calls this directly
no test coverage detected
searching dependent graphs…