WidgetFactory.cpp fails with latest shibokon2

Having trouble installing or compiling FreeCAD? Get help here.
jkmac0
Posts: 1
Joined: Sat Nov 11, 2017 3:40 pm

WidgetFactory.cpp fails with latest shibokon2

Postby jkmac0 » Sat Nov 11, 2017 3:52 pm

I am trying to re-compile on Gentoo using QT5, using a modified freecad.9999 ebuild.
I am pulling in pyside2 and shiboken2 from the qt overlay.
Freecad is failing to build with the following error

Code: Select all

/var/tmp/portage/media-gfx/freecad-9999/work/freecad-9999/src/Gui/WidgetFactory.cpp:78:26: fatal error: conversions.h: No such file or directory
 # include <conversions.h>
on checking pyside-setup.git conversions.h has been removed recently from shiboken2

http://code.qt.io/cgit/pyside/pyside-se ... 4066630e18

I will try an older commit of shiboken2 to compile for now.
User avatar
looo
Posts: 3175
Joined: Mon Nov 11, 2013 5:29 pm

Re: WidgetFactory.cpp fails with latest shibokon2

Postby looo » Mon Nov 20, 2017 10:10 pm

I am seeing the same issue with conda.
please help with my conda-packaging efforts: https://liberapay.com/looooo/
minimalistic blog: https://looooo.github.io/mini-blog/
wmayer
Site Admin
Posts: 15471
Joined: Thu Feb 19, 2009 10:32 am

Re: WidgetFactory.cpp fails with latest shibokon2

Postby wmayer » Tue Nov 21, 2017 7:49 am

Does it work to replace the line with

Code: Select all

#include <sbkconverter.h>
User avatar
looo
Posts: 3175
Joined: Mon Nov 11, 2013 5:29 pm

Re: WidgetFactory.cpp fails with latest shibokon2

Postby looo » Tue Nov 21, 2017 9:39 am

replacing <conversions.h> with <sbkconverter.h> :

Code: Select all

~/projects/FreeCAD/src/Gui/WidgetFactory.cpp:81:27: fatal error: typeresolver.h: No such file or directory
 # include <typeresolver.h>
commenting out # include <typesolver.h> :

Code: Select all

~/projects/FreeCAD/src/Gui/WidgetFactory.cpp:119:19: error: ‘Converter’ is not a class template
 template<> struct Converter<Base::Quantity>
                   ^
~/projects/FreeCAD/src/Gui/WidgetFactory.cpp:120:1: error: explicit specialization of non-template ‘Shiboken::Converter’
 {
 ^
~/projects/FreeCAD/src/Gui/WidgetFactory.cpp: In function ‘PyObject* toPythonFuncQuantity(const void*)’:
~/projects/FreeCAD/src/Gui/WidgetFactory.cpp:142:22: error: ‘Shiboken::Converter’ is not a template
     return Shiboken::Converter<Base::Quantity>::toPython(const_cast<void*>(cpp));
                      ^
~/projects/FreeCAD/src/Gui/WidgetFactory.cpp: In function ‘void (* toCppPointerCheckFuncQuantity(PyObject*))(PyObject*, void*)’:
~/projects/FreeCAD/src/Gui/WidgetFactory.cpp:151:19: error: ‘Shiboken::Converter’ is not a template
     if (Shiboken::Converter<Base::Quantity>::isConvertible(obj))
                   ^
~/projects/FreeCAD/src/Gui/WidgetFactory.cpp: In member function ‘Py::Object Gui::PythonWrapper::fromQIcon(const QIcon*)’:
~/projects/FreeCAD/src/Gui/WidgetFactory.cpp:301:23: error: ‘createWrapper’ is not a member of ‘Shiboken’
     PyObject* pyobj = Shiboken::createWrapper<QIcon>(icon, true);
                       ^
~/projects/FreeCAD/src/Gui/WidgetFactory.cpp:301:52: error: expected primary-expression before ‘>’ token
     PyObject* pyobj = Shiboken::createWrapper<QIcon>(icon, true);
please help with my conda-packaging efforts: https://liberapay.com/looooo/
minimalistic blog: https://looooo.github.io/mini-blog/
wmayer
Site Admin
Posts: 15471
Joined: Thu Feb 19, 2009 10:32 am

Re: WidgetFactory.cpp fails with latest shibokon2

Postby wmayer » Tue Nov 21, 2017 10:06 am

OK, then the API has significantly changed and it's not solved by including a different header file.
User avatar
looo
Posts: 3175
Joined: Mon Nov 11, 2013 5:29 pm

Re: WidgetFactory.cpp fails with latest shibokon2

Postby looo » Wed Dec 06, 2017 9:12 pm

I already asked twice in the pyside gitter chat. Any ideas how to solve this problem?
please help with my conda-packaging efforts: https://liberapay.com/looooo/
minimalistic blog: https://looooo.github.io/mini-blog/
paradon
Posts: 2
Joined: Thu Dec 28, 2017 11:41 pm

Re: WidgetFactory.cpp fails with latest shibokon2

Postby paradon » Fri Dec 29, 2017 3:41 am

I spent this morning playing with this...

Further to the link posted by jkmac0 in the original message; it looks like WidgetFactory is using a very, very old API (superceded in 2011):

https://groups.google.com/d/msg/pyside/ ... isDT5rzW8J
https://wiki.qt.io/PySide_Shiboken_Type ... Converters

This is the first time I'm looking at either the FreeCAD source or PySide, so I don't really understand how this is intended to be used... but, from briefly looking at the vague documentation I can find for PySide - it looks like there should be an associated .xml file somewhere to define the types for generating the Python bindings.

This XML doesn't appear anywhere in the FreeCAD source tree, so my best guess is this code doesn't actually do anything anyway...

The below patch comments out the relevant bits of code and gets this to compile for me (on ArchLinux). Note that there are still several blocks enclosed by #ifdef HAVE_SHIBOKEN that I've left in - I have no idea if they're needed or not, but they didn't break the compile.

On the first attempt I had a segfault on startup with a message "type '_io._IOBase' participates in gc and is a base type but has inappropriate tp_free slot". Just for kicks I decided to recompile against Python3 instead of 2.7, and so far it appears to be working.

Code: Select all

diff --git a/src/Gui/WidgetFactory.cpp b/src/Gui/WidgetFactory.cpp
index e9182de6d..39c088ece 100644
--- a/src/Gui/WidgetFactory.cpp
+++ b/src/Gui/WidgetFactory.cpp
@@ -60,7 +60,6 @@
 # include <basewrapper.h>
 # include <sbkconverter.h>
 # include <sbkmodule.h>
-# include <typeresolver.h>
 # include <shiboken.h>
 # ifdef HAVE_PYSIDE
 # include <pyside_qtcore_python.h>
@@ -77,7 +76,6 @@ PyTypeObject** SbkPySide_QtGuiTypes=NULL;
 # include <basewrapper.h>
 # include <sbkconverter.h>
 # include <sbkmodule.h>
-# include <typeresolver.h>
 # include <shiboken.h>
 # ifdef HAVE_PYSIDE2
 # define HAVE_PYSIDE
@@ -113,7 +111,7 @@ PyTypeObject** SbkPySide2_QtWidgetsTypes=NULL;
 
 using namespace Gui;
 
-#if defined (HAVE_SHIBOKEN)
+#if 0 // defined (HAVE_SHIBOKEN)^M
 namespace Shiboken {
 template<> struct Converter<Base::Quantity>
 {
@@ -206,7 +204,7 @@ void registerTypes()
 
 PythonWrapper::PythonWrapper()
 {
-#if defined (HAVE_SHIBOKEN)
+#if 0 // defined (HAVE_SHIBOKEN)^M
     static bool init = false;
     if (!init) {
         init = true;
@@ -296,7 +294,7 @@ QObject* PythonWrapper::toQObject(const Py::Object& pyobject)
 
 Py::Object PythonWrapper::fromQIcon(const QIcon* icon)
 {
-#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
+#if 0 // defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)^M
     PyObject* pyobj = Shiboken::createWrapper<QIcon>(icon, true);
     if (pyobj)
         return Py::asObject(pyobj);
User avatar
looo
Posts: 3175
Joined: Mon Nov 11, 2013 5:29 pm

Re: WidgetFactory.cpp fails with latest shibokon2

Postby looo » Fri Dec 29, 2017 10:34 am

great!, thanks for having a look at this. I have added your patch to my master and currently trying to build it with circle-ci. [1] It would be nice to create a PR on github, so the ci could check if there is no problem with older builds of pyside/pyside2.

[1] https://circleci.com/gh/looooo/FreeCAD/128
please help with my conda-packaging efforts: https://liberapay.com/looooo/
minimalistic blog: https://looooo.github.io/mini-blog/
wmayer
Site Admin
Posts: 15471
Joined: Thu Feb 19, 2009 10:32 am

Re: WidgetFactory.cpp fails with latest shibokon2

Postby wmayer » Fri Dec 29, 2017 11:32 am

I spent this morning playing with this...

Further to the link posted by jkmac0 in the original message; it looks like WidgetFactory is using a very, very old API (superceded in 2011):
The PySide2 libs have been built in December 2016 and with that version everything compiles fine. So, the build failure must be caused by changes on PySide2/shiboken2 within the last 12 months.
This is the first time I'm looking at either the FreeCAD source or PySide, so I don't really understand how this is intended to be used... but, from briefly looking at the vague documentation I can find for PySide - it looks like there should be an associated .xml file somewhere to define the types for generating the Python bindings.

This XML doesn't appear anywhere in the FreeCAD source tree, so my best guess is this code doesn't actually do anything anyway...
Why do you expect to find .xml files there? The code in WidgetFactory.cpp is not supposed to create Python wrappers but to use them for a lot of Qt classes.
I have added your patch to my master and currently trying to build it with circle-ci. [1] It would be nice to create a PR on github, so the ci could check if there is no problem with older builds of pyside/pyside2.
The change currently takes out the conversion between Python and QIcon which is used in some places. I wonder if this change is really necessary.
paradon
Posts: 2
Joined: Thu Dec 28, 2017 11:41 pm

Re: WidgetFactory.cpp fails with latest shibokon2

Postby paradon » Fri Dec 29, 2017 12:00 pm

wmayer wrote:
Fri Dec 29, 2017 11:32 am
The PySide2 libs have been built in December 2016 and with that version everything compiles fine. So, the build failure must be caused by changes on PySide2/shiboken2 within the last 12 months.
Yes, the opening message of this thread links to the exact PySide commit that breaks compile, two months ago:
This commit is titled "Remove dead / unused code regarding type conversions".

wmayer wrote:
Fri Dec 29, 2017 11:32 am
Why do you expect to find .xml files there? The code in WidgetFactory.cpp is not supposed to create Python wrappers but to use them for a lot of Qt classes.
This link here contains an example template (of "the old way") which looks suspiciously like some of the code I commented in WidgetFactory.cpp was copy-pasted from it. It shows an associated XML snippet which I'd presumed was meant to be parsed as part of the build process...

https://wiki.qt.io/PySide_Shiboken_Type ... Converters

However, as I said, this is my first look at either FreeCAD or PySide/Shiboken, so I'm really just guessing here.

wmayer wrote:
Fri Dec 29, 2017 11:32 am
The change currently takes out the conversion between Python and QIcon which is used in some places. I wonder if this change is really necessary.
Yes, this is just a fairly brutal tearing out of blocks of code that failed compile. I wouldn't be suprised if I accidentally removed something I shouldn't've, and I don't think this patch should be applied to master without a bit more careful review by someone that understands the codebase.