gplugin/gplugin

Silence warnings from Python files

2021-09-29, Elliott Sales de Andrade
4a32fb36235b
Parents ac20fdcbfd10
Children 19dfb7e4f207
Silence warnings from Python files

The `Python.h` header must be included first to appease the preprocessor.
Additionally, it includes ``, ``, ``, ``,
`` and ``, so we don't have to.

Also:

* Mark Python code as `ssize_t` clean
We don't use any `#` format variants, but it's best to define this for any future usage.

* Remove unused struct members from Python loader

* Simplify `gplugin_python3_filename_to_module`
I believe the call to `g_utf8_strrchr` was in error, as the second argument is
length in bytes, but `g_utf8_strlen` returns length in characters, which is
shorter. In any case, it accepts -1 anyway, so there's no need to count the
length.

Testing Done:
Compile and `ninja test`

Reviewed at https://reviews.imfreedom.org/r/960/
--- a/python3/gplugin-python3-loader.c Tue Sep 28 02:59:16 2021 -0500
+++ b/python3/gplugin-python3-loader.c Wed Sep 29 16:12:22 2021 -0500
@@ -15,13 +15,13 @@
* License along with this library; if not, see <https://www.gnu.org/licenses/>.
*/
-#include "gplugin-python3-loader.h"
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
-#include <stdlib.h>
+#include "gplugin-python3-loader.h"
#include <glib/gi18n-lib.h>
-#include <Python.h>
#include <pygobject.h>
#include "gplugin-python3-plugin.h"
@@ -29,9 +29,6 @@
struct _GPluginPython3Loader {
GPluginLoader parent;
-
- PyThreadState *py_thread_state;
- guint gc_id;
};
G_DEFINE_DYNAMIC_TYPE(
--- a/python3/gplugin-python3-plugin.c Tue Sep 28 02:59:16 2021 -0500
+++ b/python3/gplugin-python3-plugin.c Wed Sep 29 16:12:22 2021 -0500
@@ -15,9 +15,10 @@
* License along with this library; if not, see <https://www.gnu.org/licenses/>.
*/
-#include "gplugin-python3-plugin.h"
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
-#include <Python.h>
+#include "gplugin-python3-plugin.h"
/******************************************************************************
* Typedefs
@@ -26,7 +27,6 @@
GObject parent;
PyObject *module;
- PyObject *query;
PyObject *load;
PyObject *unload;
--- a/python3/gplugin-python3-test-pygobject.c Tue Sep 28 02:59:16 2021 -0500
+++ b/python3/gplugin-python3-test-pygobject.c Wed Sep 29 16:12:22 2021 -0500
@@ -15,11 +15,11 @@
* License along with this library; if not, see <https://www.gnu.org/licenses/>.
*/
-#include <stdio.h>
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
#include <glib.h>
-#include <Python.h>
#include <pygobject.h>
gint
--- a/python3/gplugin-python3-utils.c Tue Sep 28 02:59:16 2021 -0500
+++ b/python3/gplugin-python3-utils.c Wed Sep 29 16:12:22 2021 -0500
@@ -15,14 +15,13 @@
* License along with this library; if not, see <https://www.gnu.org/licenses/>.
*/
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+
#include "gplugin-python3-utils.h"
-#include <string.h>
-
#include <gplugin.h>
-#include <Python.h>
-
gchar *
gplugin_python3_filename_to_module(const gchar *filename)
{
@@ -35,15 +34,13 @@
base = g_path_get_basename(filename);
/* now find the last . for the extension */
- e = g_utf8_strrchr(base, g_utf8_strlen(base, -1), g_utf8_get_char("."));
+ e = g_utf8_strrchr(base, -1, g_utf8_get_char("."));
if(e == NULL) {
return base;
}
/* now copy the module name into r */
- r = g_malloc(e - base + 1);
- memcpy(r, base, e - base);
- r[e - base] = 0;
+ r = g_strndup(base, e - base);
/* free the basename */
g_free(base);
--- a/python3/tests/test-python3-utils.c Tue Sep 28 02:59:16 2021 -0500
+++ b/python3/tests/test-python3-utils.c Wed Sep 29 16:12:22 2021 -0500
@@ -15,9 +15,10 @@
* License along with this library; if not, see <https://www.gnu.org/licenses/>.
*/
-#include <glib.h>
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
-#include <Python.h>
+#include <glib.h>
#include "gplugin-python3-utils.h"