gcc-python-plugin
gcc-python-plugin copied to clipboard
Cannot build in Ubuntu with gcc-7 and gcc-8
Hi, I'm trying to compile the gcc-python-plugin. I tried with both gcc-7 and gcc-8. I'm using Python 3.8 and building with
make PYTHON=python3.8 PYTHON_CONFIG=python3.8-config
The first problem is related to this error:
gcc-python-wrapper.c:188:1: error: converting to non-pointer type ‘long int’ from NULL [-Werror=conversion-null]
};
^
cc1plus: all warnings being treated as errors
make: *** [Makefile:168: gcc-python-wrapper.o] Error 1
I thought a workaround is to replace -Werror with -Wno-error in the Makefile.
This generates the python.so but fails in the demo as follows
cc1: error: cannot load plugin /home/canedo/MINDSIGHT/gcc-python-plugin/python.so
/home/canedo/gcc-python-plugin/python.so: undefined symbol: PyExc_NotImplementedError
make[1]: *** [Makefile:303: demo] Error 1
Any hints would be highly appreciated. Thanks.
I believe these are incompatibilities with Python 3.8, which hopefully have been fixed by cdb70205bd5854c455dc1af205e9d5f7ce4afb66 and 4deefc840e69e3c2c42f8a50963b8fb69c17efee. That said, I'm still seeing: TypeError: 'gcc.WrapperMeta' object is not iterable (with Python 3.8 and gcc 10) which I'm investigating.
I'm still seeing: TypeError: 'gcc.WrapperMeta' object is not iterable (with Python 3.8 and gcc 10) which I'm investigating.
I took a quick look at this, and I have a patch (see below).
The issue is that the Python MRO is freeing an object it is using. This started to happen with the change
commit 2e9954d3472a23919b96323fcd5bb6c1d6927155
Author: Jeroen Demeyer <[email protected]>
Date: Mon Jun 17 13:53:21 2019 +0200
bpo-36922: use Py_TPFLAGS_METHOD_DESCRIPTOR in lookup_maybe_method() (GH-13865)
(which later was cherry-picked to the Python 3.8 branch). I do not understand how the Python MRO works, but this looks unrelated to what gcc-python-plugin does, and seems to just be an optimization... So it seemed likely to me that the plugin sets some flags inconsistently...
And I found one place that looked suspicious. Changing this as in the patch
--- a/generate-gimple-c.py
+++ b/generate-gimple-c.py
@@ -231,7 +231,7 @@ PyGccGimple_get_block(struct PyGccGimple *self, void *closure)
tp_str = '(reprfunc)PyGccGimple_str',
tp_hash = '(hashfunc)PyGccGimple_hash',
tp_richcompare = 'PyGccGimple_richcompare',
- tp_flags = 'Py_TPFLAGS_BASETYPE',
+ tp_flags = '(Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE)',
)
methods = PyMethodTable('PyGccGimple_methods', [])
methods.add_method('walk_tree',
makes the plugin work again, although I have only tested with some simple scripts (using Python 3.9 and GCC 8.5).
Oh nice to see this patch, I did not see that before, my solution was to strip out the entire metaclass #192 I am going to try your patch as well.
The Python problem giving us gcc.WrapperMeta errors was fixed in Python 3.9.13, and all versions of 3.10 seem to work too.