profanity icon indicating copy to clipboard operation
profanity copied to clipboard

Syntax error in src/plugins/python_plugins.c

Open atsecsysad opened this issue 7 months ago • 4 comments

Expected Behavior

Profanity 0.15 compiles.

Current Behavior

It does not compile out of the box, due to a syntax error.

Possible Solution

Patch ...srv/plugins/python_plugins.c to correct erroneous in-line call to Py_XDECREF.

Steps to Reproduce (for bugs)

  1. Line 91: loaded_modules = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)Py_XDECREF);

  2. Run: ./bootstrap.sh && ./configure && make

  3. Result: make all-am make[1]: Entering directory '/tmp/profanity-0.15.0' depbase=echo src/plugins/python_plugins.o | sed 's|[^/]*$|.deps/&|;s|\.o$||';
    gcc -DHAVE_CONFIG_H -I. -I./src -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -Wall -Wno-deprecated-declarations -std=gnu99 -ggdb3 -pthread -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -pthread -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/x86_64-linux-gnu -pthread -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/x86_64-linux-gnu -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/python3.10 -DTHEMES_PATH=""/usr/local/share/profanity/themes"" -DICONS_PATH=""/usr/local/share/profanity/icons"" -DGLOBAL_PYTHON_PLUGINS_PATH=""/usr/local/share/profanity/plugins"" -DGLOBAL_C_PLUGINS_PATH=""/usr/local/lib/profanity/plugins"" -pthread -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/x86_64-linux-gnu -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -DLIBXMPP_VERSION_MAJOR=0 -DLIBXMPP_VERSION_MINOR=14 -I/usr/local/include -I./src -pthread -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/x86_64-linux-gnu -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -DLIBXMPP_VERSION_MAJOR=0 -DLIBXMPP_VERSION_MINOR=14 -I/usr/local/include -MT src/plugins/python_plugins.o -MD -MP -MF $depbase.Tpo -c -o src/plugins/python_plugins.o src/plugins/python_plugins.c &&
    mv -f $depbase.Tpo $depbase.Po src/plugins/python_plugins.c: In function ‘python_env_init’: src/plugins/python_plugins.c:98:91: error: ‘Py_XDECREF’ undeclared (first use in this function); did you mean ‘Py_DecRef’? 98 | loaded_modules = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)Py_XDECREF); | ^~~~~~~~~~ | Py_DecRef src/plugins/python_plugins.c:98:91: note: each undeclared identifier is reported only once for each function it appears in At top level: src/plugins/python_plugins.c:79:1: warning: ‘_unref_module’ defined but not used [-Wunused-function] 79 | _unref_module(PyObject* module) | ^~~~~~~~~~~~~ make[1]: *** [Makefile:2086: src/plugins/python_plugins.o] Error 1 make[1]: Leaving directory '/tmp/profanity-0.15.0' make: *** [Makefile:1303: all] Error 2

  4. Profanity version 0.14.0 correctly implements a small wrapper for Py_XDECREF: static void _unref_module(PyObject* module) { Py_XDECREF(module); } ... same line causing issue from Profanity 0.14.0 calls correct wrapper _unref_module: loaded_modules = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_unref_module);

  5. After re-adding wrapper function, and changing the offending line, Profanity 0.15.0 actually compiles.

Context

The issue seems relevant, since Ubuntu 22.04 does not provide a remotely recent version of Profanity for use (version 0.11 in apt packages upstream which is absurdly old).

Environment

  • Ubuntu 22.04 LTS
  • profanity -v is lrrelevant here. It won't compile.
  • profanity 0.15.0 is the desired version for compilation.
  • Glib 2.72.4-0ubuntu2.4 (also irrelevant here).
  • libstrophe 0.14.0 (Custom install; libstrophe 0.11 is present in upstream).

I spent a day or two on this, because I love Profanity that much! While I'm not an advanced coder this is what I tracked down. Naturally there may be a better solution, but it does seem as though this is a legitimate syntax error given that Py_XDECREF is used all over the place elsewhere, and is clearly functioning correctly in those instances. This one just seems like during the "rage cleaning" as the previous check-in post indicates, the person was a bit .. Over-eager perhaps in cleaning up unnecessary code.

atsecsysad avatar May 14 '25 17:05 atsecsysad

This was changed in https://github.com/profanity-im/profanity/commit/c0da36c48d9878c7e90a796d97f5670fd686d7aa. We could change this back for 0.15.1 and I would also like to point you to https://profanity-im.github.io/blog/post/distrobox/ in the meantime

jubalh avatar Jun 04 '25 06:06 jubalh

😬 I'll have a look at it.

sjaeckel avatar Jun 04 '25 10:06 sjaeckel

This was changed in c0da36c. We could change this back for 0.15.1 and I would also like to point you to https://profanity-im.github.io/blog/post/distrobox/ in the meantime

Great suggestion. I'm familiar with, and work with Docker/Podman but this is the first time I've encountered distro-box. Does this software change the workflow associated with Docker ?? The dockerfiles that I tried in the repo do not create an image with a profanity binary present. I went ahead and fixed the Debian/Ubuntu images, although I didn't touch others. Let me know if you'd like me to send a pull request for the modifications I made, but I assumed that I'm by no means an expert on Docker, and thus didn't want to come off as too "pushy".

😬 I'll have a look at it.

Thanks! I originally went down the Python rabbit hole, then while writing you this response realized it's probably GCC that's the issue. Version Info:

Python versions

Ubuntu 22.04 LTS (Base OS): 3.10.6-1~22.04.1 (dpkg -l ...) python --version: 3.10.12

Debian container (debian:testing): 3.13.3-2 (dpkg -l |grep...) python --version: 3.13.3

Ubuntu container (ubuntu:latest): 3.12.3-1ubuntu0.5 (dpkg -l ...) python --version: 3.12.3

GCC versions Ubuntu 22.04 LTS (Base OS): gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

Debian:Testing container: gcc (Debian 14.2.0-19) 14.2.0

Ubuntu:latest container: gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0

I think 11.4 just .. doesn't understand what the call to Py_XDECREF even is.... Still, if you wish to remain backwards compat with at least Ubuntu 22.04 then you'll need to consider re-introducing the wrapper function at least for this piece.

atsecsysad avatar Jun 04 '25 21:06 atsecsysad

The docker files were supposed to be only for our CI to run the tests. But it seems you are already the second person who wants to use them for running Profanity :) If you want you can send a PR to make them fit for that purpose. We will then review and discuss there.

jubalh avatar Jun 05 '25 04:06 jubalh