commit:     a860484b6e8c8d107255f2105796ae7f58812e9f
Author:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Thu Feb 29 19:38:20 2024 +0000
Commit:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Thu Feb 29 19:38:20 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=a860484b

Drop portage.util.libc extension module

This was originally added as a workaround for musl, where
ctypes.util.find_library fails.

Instead, we now try to load "libc.so" as a fallback and can just rely on
ctypes to call tolower() and toupper().

Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>

 lib/portage/util/locale.py |  9 +++----
 src/meson.build            |  9 -------
 src/portage_util_libc.c    | 67 ----------------------------------------------
 3 files changed, 3 insertions(+), 82 deletions(-)

diff --git a/lib/portage/util/locale.py b/lib/portage/util/locale.py
index d0edeb4afe..f45d761760 100644
--- a/lib/portage/util/locale.py
+++ b/lib/portage/util/locale.py
@@ -43,12 +43,9 @@ def _check_locale(silent):
     """
     The inner locale check function.
     """
-    try:
-        from portage.util import libc
-    except ImportError:
-        (libc, _) = load_libc()
-        if libc is None:
-            return None
+    (libc, _) = load_libc()
+    if libc is None:
+        return None
 
     lc = list(range(ord("a"), ord("z") + 1))
     uc = list(range(ord("A"), ord("Z") + 1))

diff --git a/src/meson.build b/src/meson.build
index cbc7aa611c..6a36724ceb 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -2,14 +2,6 @@
 # and for development. Meson does not allow you to build in-place and Python
 # cannot create a single namespace from two identically-named paths.
 
-libc_ext = py.extension_module(
-    'libc',
-    'portage_util_libc.c',
-    dependencies : py.dependency(),
-    subdir : 'portage' / 'util',
-    install : true
-)
-
 whirlpool_ext = py.extension_module(
     '_whirlpool',
     'portage_util__whirlpool.c',
@@ -21,7 +13,6 @@ whirlpool_ext = py.extension_module(
 run_command(
     [
         'ln', '-srnf',
-        libc_ext.full_path(),
         whirlpool_ext.full_path(),
         meson.project_source_root() / 'lib' / 'portage' / 'util/'
     ],

diff --git a/src/portage_util_libc.c b/src/portage_util_libc.c
deleted file mode 100644
index 12b2440c72..0000000000
--- a/src/portage_util_libc.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/* Copyright 2005-2020 Gentoo Authors
- * Distributed under the terms of the GNU General Public License v2
- */
-
-#include <Python.h>
-#include <stdlib.h>
-#include <ctype.h>
-
-static PyObject * _libc_tolower(PyObject *, PyObject *);
-static PyObject * _libc_toupper(PyObject *, PyObject *);
-
-static PyMethodDef LibcMethods[] = {
-       {
-               .ml_name = "tolower",
-               .ml_meth = _libc_tolower,
-               .ml_flags = METH_VARARGS,
-               .ml_doc = "Convert to lower case using system locale."
-
-       },
-       {
-               .ml_name = "toupper",
-               .ml_meth = _libc_toupper,
-               .ml_flags = METH_VARARGS,
-               .ml_doc = "Convert to upper case using system locale."
-       },
-       {NULL, NULL, 0, NULL}
-};
-
-static struct PyModuleDef moduledef = {
-       PyModuleDef_HEAD_INIT,
-       .m_name = "libc",
-       .m_doc = "Module for converting case using the system locale",
-       .m_size = -1,
-       .m_methods = LibcMethods,
-};
-
-PyMODINIT_FUNC
-PyInit_libc(void)
-{
-       PyObject *m;
-       m = PyModule_Create(&moduledef);
-       return m;
-}
-
-
-static PyObject *
-_libc_tolower(PyObject *self, PyObject *args)
-{
-       int c;
-
-       if (!PyArg_ParseTuple(args, "i", &c))
-               return NULL;
-
-       return Py_BuildValue("i", tolower(c));
-}
-
-
-static PyObject *
-_libc_toupper(PyObject *self, PyObject *args)
-{
-       int c;
-
-       if (!PyArg_ParseTuple(args, "i", &c))
-               return NULL;
-
-       return Py_BuildValue("i", toupper(c));
-}

Reply via email to