]> git.ipfire.org Git - pakfire.git/commitdiff
arch: Add function that returns a list of all supported arches
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Oct 2022 14:44:44 +0000 (14:44 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Oct 2022 14:44:44 +0000 (14:44 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/_pakfiremodule.c
src/libpakfire/arch.c
src/libpakfire/include/pakfire/arch.h
src/libpakfire/libpakfire.sym
src/pakfire/__init__.py

index 6fadebaec4b71e85713a1dee0699afcaa455b4b1..839d0ac76fce10dcc872a46c92d1c60f3435a43b 100644 (file)
@@ -52,9 +52,48 @@ static PyObject* _pakfire_native_arch(void) {
        return PyUnicode_FromString(arch);
 }
 
+static PyObject* _pakfire_supported_arches(void) {
+       int r;
+
+       // Fetch all architectures
+       const char** arches = pakfire_supported_arches();
+       if (!arches) {
+               PyErr_SetFromErrno(PyExc_OSError);
+               return NULL;
+       }
+
+       // Create a new list
+       PyObject* list = PyList_New(0);
+       if (!list)
+               return NULL;
+
+       // Append all architectures
+       for (const char** arch = arches; *arch; arch++) {
+               PyObject* object = PyUnicode_FromString(*arch);
+               if (!object)
+                       goto ERROR;
+
+               // Append to list
+               r = PyList_Append(list, object);
+               if (r) {
+                       Py_DECREF(object);
+                       goto ERROR;
+               }
+
+               Py_DECREF(object);
+       }
+
+       return list;
+
+ERROR:
+       Py_DECREF(list);
+       return NULL;
+}
+
 static PyMethodDef pakfireModuleMethods[] = {
        {"performance_index", (PyCFunction)performance_index, METH_VARARGS, NULL},
        {"native_arch", (PyCFunction)_pakfire_native_arch, METH_NOARGS, NULL },
+       {"supported_arches", (PyCFunction)_pakfire_supported_arches, METH_NOARGS, NULL },
        { NULL, NULL, 0, NULL }
 };
 
index a11bdd8a2e7cd9b9a3eacc8276726d6580d63986..2d28b15944f9b168495a88ccc46dc5a8e78fc05e 100644 (file)
@@ -131,6 +131,31 @@ PAKFIRE_EXPORT int pakfire_arch_supported(const char* name) {
        return 0;
 }
 
+const char** __pakfire_supported_arches = NULL;
+
+PAKFIRE_EXPORT const char** pakfire_supported_arches() {
+       unsigned int counter = 0;
+
+       if (!__pakfire_supported_arches) {
+               for (const struct pakfire_arch* arch = PAKFIRE_ARCHES; arch->name; arch++) {
+                       __pakfire_supported_arches = reallocarray(__pakfire_supported_arches,
+                               counter + 1, sizeof(*__pakfire_supported_arches));
+
+                       // Exit if the allocation failed
+                       if (!__pakfire_supported_arches)
+                               return NULL;
+
+                       __pakfire_supported_arches[counter++] = arch->name;
+               }
+
+               // Sentinel
+               if (__pakfire_supported_arches)
+                       __pakfire_supported_arches[counter] = NULL;
+       }
+
+       return __pakfire_supported_arches;
+}
+
 const char* pakfire_arch_platform(const char* name) {
        const struct pakfire_arch* arch = pakfire_arch_find(name);
 
index c1ffa130f00cfa49e782a6c84ca4c9ce068eed3c..268c1b68bf104500d1a3860e4ff805dadeb15149 100644 (file)
@@ -22,6 +22,7 @@
 #define PAKFIRE_ARCH_H
 
 int pakfire_arch_supported(const char* name);
+const char** pakfire_supported_arches(void);
 const char* pakfire_arch_native(void);
 
 #ifdef PAKFIRE_PRIVATE
index 4d472743fe317b2a53a07890cd5678bd7a52a0d6..a433327d574d8082d827ebd916c877d16fef5895 100644 (file)
@@ -48,6 +48,7 @@ global:
        # arch
        pakfire_arch_native;
        pakfire_arch_supported;
+       pakfire_supported_arches;
 
        # archive
        pakfire_archive_extract;
index 8b281b0fc548b7fbfc9beb46532b8a3482456f57..ebe61a268202540313948ed1d2db053bcaea55fc 100644 (file)
@@ -19,7 +19,7 @@
 #                                                                             #
 ###############################################################################
 
-from ._pakfire import Pakfire
+from ._pakfire import Pakfire, native_arch, supported_arches
 
 from .__version__ import PAKFIRE_VERSION as __version__