From: Michael Tremer Date: Sat, 10 Apr 2021 15:12:37 +0000 (+0000) Subject: util: Make pakfire_split_string private X-Git-Tag: 0.9.28~1285^2~379 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=603ca1e03d99df3ef09ede4cb6094df5caff1745;p=pakfire.git util: Make pakfire_split_string private Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/package.c b/src/_pakfire/package.c index ddf4ba63b..13d7c0b9d 100644 --- a/src/_pakfire/package.c +++ b/src/_pakfire/package.c @@ -292,22 +292,7 @@ static void Package_set_url(PackageObject* self, PyObject* value) { static PyObject* Package_get_groups(PackageObject* self) { const char* s = pakfire_package_get_groups(self->package); - PyObject* list = PyList_New(0); - - char** groups = pakfire_split_string(s, ','); - char* group; - - while ((group = *groups++) != NULL) { - PyObject* item = PyUnicode_FromString(group); - PyList_Append(list, item); - free(group); - - Py_DECREF(item); - } - - free(groups); - - return list; + return PyUnicode_FromString(s); } static int Package_set_groups(PackageObject* self, PyObject* value) { diff --git a/src/libpakfire/include/pakfire/util.h b/src/libpakfire/include/pakfire/util.h index 6bae7f203..8c64a75b0 100644 --- a/src/libpakfire/include/pakfire/util.h +++ b/src/libpakfire/include/pakfire/util.h @@ -27,8 +27,6 @@ #include -char** pakfire_split_string(const char* s, char delim); - char* pakfire_generate_uuid(); #ifdef PAKFIRE_PRIVATE @@ -44,6 +42,7 @@ int pakfire_string_endswith(const char* s, const char* suffix); char* pakfire_unquote_in_place(char* s); int pakfire_string_partition(const char* s, const char* delim, char** s1, char** s2); char* pakfire_string_replace(const char* s, const char* pattern, const char* repl); +char** pakfire_split_string(const char* s, char delim); char* pakfire_format_size(double size); char* pakfire_format_date(time_t t); diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index f5775e714..30cf0ba89 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -407,7 +407,6 @@ global: # util pakfire_generate_uuid; - pakfire_split_string; local: *; diff --git a/src/libpakfire/util.c b/src/libpakfire/util.c index 8bdcb46d9..d2cf57215 100644 --- a/src/libpakfire/util.c +++ b/src/libpakfire/util.c @@ -194,6 +194,39 @@ ERROR: return result; } +char** pakfire_split_string(const char* s, char delim) { + // Copy string to stack and count spaces + char buffer[strlen(s) + 2]; + + size_t count = 1; + for (unsigned int i = 0; i < strlen(s) + 1; i++) { + buffer[i] = s[i]; + + if (s[i] == delim) { + buffer[i] = '\0'; + count++; + } + } + + // Allocate an array of sufficient size + char** ret = malloc(sizeof(*ret) * (count + 1)); + + // Copy strings to heap one by one + unsigned int i = 0; + char* p = buffer; + while (*p) { + ret[i++] = strdup(p); + + // Move pointer to the next string + p += strlen(p) + 1; + } + + // Terminate array + ret[count] = NULL; + + return ret; +} + char* pakfire_format_size(double size) { char string[STRING_SIZE]; const char* units[] = {" ", "k", "M", "G", "T", NULL}; @@ -332,39 +365,6 @@ int pakfire_read_file_into_buffer(FILE* f, char** buffer, size_t* len) { return 0; } -PAKFIRE_EXPORT char** pakfire_split_string(const char* s, char delim) { - // Copy string to stack and count spaces - char buffer[strlen(s) + 2]; - - size_t count = 1; - for (unsigned int i = 0; i < strlen(s) + 1; i++) { - buffer[i] = s[i]; - - if (s[i] == delim) { - buffer[i] = '\0'; - count++; - } - } - - // Allocate an array of sufficient size - char** ret = malloc(sizeof(*ret) * (count + 1)); - - // Copy strings to heap one by one - unsigned int i = 0; - char* p = buffer; - while (*p) { - ret[i++] = strdup(p); - - // Move pointer to the next string - p += strlen(p) + 1; - } - - // Terminate array - ret[count] = NULL; - - return ret; -} - PAKFIRE_EXPORT char* pakfire_generate_uuid() { uuid_t uuid;