Bug 1778000 - Python scripting assertion failure
Summary: Python scripting assertion failure
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: kig
Version: 31
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Kevin Kofler
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-11-28 23:11 UTC by Maurizio Paolini
Modified: 2020-01-12 01:41 UTC (History)
5 users (show)

Fixed In Version: kig-19.08.3-3.fc30 kig-19.08.3-3.fc31
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-01-12 01:14:49 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
kig file reproducing the problem (1.50 KB, application/xml)
2019-11-28 23:14 UTC, Maurizio Paolini
no flags Details


Links
System ID Private Priority Status Summary Last Updated
KDE Software Compilation 401512 0 'NOR' 'UNCONFIRMED' 'kig crashes with simple python script with a failing assertion' 2019-11-28 23:18:04 UTC
Red Hat Bugzilla 1529346 0 unspecified CLOSED Cannot use python scripting when compiling from source 2021-02-22 00:41:40 UTC

Description Maurizio Paolini 2019-11-28 23:11:24 UTC
[This is identical to a previous bug closed by EOL, see links]

Description of problem:

My box is a fully updated fedora 27.  I need to install kig from the Git
tree.  Cmake correctly finds the optional python scripting extension and it
compiles with no problem.
However when trying to enter a python script with one argument kig crashes
with the message:

kig: /usr/include/boost/python/object_core.hpp:425: boost::python::api::object_base::~object_base(): Assertion `Py_REFCNT(m_ptr) > 0' failed.


Additional info:

I filed this bug upstream: https://bugs.kde.org/show_bug.cgi?id=401512
which got no response

Comment 1 Maurizio Paolini 2019-11-28 23:14:38 UTC
Created attachment 1640539 [details]
kig file reproducing the problem

Kig file containing a python script.

Comment 2 Kevin Kofler 2019-11-28 23:18:04 UTC
Fedora cannot fix bugs in upstream code, if you are not even using a Fedora package. The bug is already filed upstream as it should, so closing this bug report.

We can reopen this bug if and when you can reproduce it using a Fedora package (kig >= 19.08.1-3, which ships Python 3 scripting support). Note that we cannot support Python 2 scripting anymore because the Python SIG is aggressively deprecating Python 2.

Comment 3 Kevin Kofler 2019-11-29 18:26:51 UTC
Looks like this also happens with the kig-19.08.3-1.fc31 package, so I am reopening this, though I am not sure whether I will be able to fix it.

Comment 4 Maurizio Paolini 2019-11-30 12:34:31 UTC
Actually, I realise that it makes no sense in trying to debug this since python scripting seems completely broken upstream... there can even
be NO relation at all between the problem upstream and the crash downstream.  I will try to focus a little bit on the Git sources and see if
I can do something there.

Hence we can close this bug and see what happens.

Comment 5 Kevin Kofler 2019-11-30 12:45:22 UTC
Then let's close it as an upstream issue. If you can come up with a fix or find one somewhere, please let me know so that I can apply it. Technically, I can even commit it upstream (I have KDE developer access), but would rather not mess too much with projects that I do not maintain upstream. (I am supposed to maintain Kompare and libkomparediff2 and that's it.)

Comment 6 Maurizio Paolini 2019-12-16 15:29:51 UTC
Sorry for inserting text into a CLOSED bug... however it is just to mention that I have a workaround for the bug upstream that "fixes" the python scripting bug.  I am not sure this is a real fix, because of my zero-experience about boost.  However without this fix the upstream git source seems completely broken with respect to the use of scripting, in the sense that we have a crash as soon as a script with one or more arguments is defined!

--------------------------------------------------------------------------------------------------
$ git diff
diff --git a/scripting/python_scripter.cc b/scripting/python_scripter.cc
index 62a7409b..57e09255 100644
--- a/scripting/python_scripter.cc
+++ b/scripting/python_scripter.cc
@@ -531,6 +531,10 @@ ObjectImp* PythonScripter::calc( CompiledPythonScript& script, const Args& args
     };
     tuple argstup( argstuph );
 
+// workaround?
+//
+    Py_INCREF (argstup.ptr());
+
     handle<> reth( PyEval_CallObject( calcfunc.ptr(), argstup.ptr() ) );
 //    object resulto = calcfunc( argstup );
 //    handle<> reth( PyEval_CallObject( calcfunc.ptr(), args ) );
--------------------------------------------------------------------------------------------------

I also added this same comment in the upstream bug report https://bugs.kde.org/show_bug.cgi?id=401512 but I am not very optimistic about a fix at that level very soon, so a possibility could be to incorporate this in the fedora packaging.

This is only a *first step*, however, since the upstream kig seems to be still based on version 2.7 of python whereas kig in fedora has been
patched against version 3 of python.  Using python script with the "fedora" kig version kig-19.08.3-1.fc31.x86_64 causes a crash that *could be* unrelated to the upstream bug.

Comment 7 Kevin Kofler 2019-12-16 17:03:46 UTC
It makes sense to increment the reference count. I guess the non-workaround version of the fix would also Py_DECREF the reference once it is no longer needed though, in order to avoid leaking memory.

We don't actually apply any patch that is not already in the upstream git master in order to build for Python 3. But it may be that the code compiles against Python 3 but does not run properly. Have you tried building an RPM with your workaround? I can do a build for you to test.

Comment 8 Maurizio Paolini 2019-12-16 20:44:26 UTC
I just tried to build an rpm for my fedora 31 box starting from the https://bodhi.fedoraproject.org/updates/FEDORA-2019-cd4008c5ce
build that you provided recently.
It still crashes when asked to open the example kig file that creates a simple script... however there is a BIG improvement:
kig now works when I create a sample script!  But if I save the resulting construction and load the saved file kig crashes.

I also tried again the original kig-19.08.3-1.fc31.x86_64.rpm rpm just to be sure of the improvement: it does not crash upon creation
of the script, but it crashes as soon as I move the point that I used as argument to the script.
This is the same behaviour as with the upstream compiled kig.

Finally I tried again the result of compiling from sources just to check that it is able to correctly read a kig file with an object constructed via scripting, and it works fine (based on python 2.7).

I hope this helps...

Comment 9 Maurizio Paolini 2019-12-16 21:39:44 UTC
BTW, I should also have write access to the kig code upstream, since I was one of the developpers time ago.  Perhaps if nothing happens
on bugs.kde.org I could just take the chance...

Comment 10 Kevin Kofler 2019-12-23 08:37:20 UTC
Looks like we need this one, too: https://cgit.kde.org/kig.git/commit/?id=d72f33a14c22480b28c0f35d53293826f6ec787b

Comment 11 Kevin Kofler 2019-12-23 10:01:19 UTC
So, after looking at the code and the documentation, I suspect the issue is not really the reference count of the tuple itself, but of the individual arguments, which would explain why you do not hit this assertion if the function has no arguments.

Comment 12 Maurizio Paolini 2019-12-23 15:48:17 UTC
(In reply to Kevin Kofler from comment #10)
> Looks like we need this one, too:
> https://cgit.kde.org/kig.git/commit/
> ?id=d72f33a14c22480b28c0f35d53293826f6ec787b

Really?!?  This seems to be a patch to pykig.py, which is 'python-related', but completely
disjoint to python-scripting.  I call it 'outside' scripting: a way to directly produce a kig file
with a construction described in a python script.  It comes handy to generate complex structures
like tassellations or fractals.

Comment 13 Kevin Kofler 2019-12-23 15:56:06 UTC
Ah OK, thanks for clearing that up. But what is sure is that pykig was not working with the switch to Python 3 and without that patch. :-)

I also applied Franco Pasquarelli's version of the refcount patch and the coordinate precision dialog fix from upstream. I hope that that build will work better, but I have to wait for Koji now, it seems to be completely swamped.

Comment 14 Maurizio Paolini 2019-12-23 16:01:58 UTC
(In reply to Kevin Kofler from comment #13)
> Ah OK, thanks for clearing that up. But what is sure is that pykig was not
> working with the switch to Python 3 and without that patch. :-)

Indeed!!!

> I also applied Franco Pasquarelli's version of the refcount patch and the
> coordinate precision dialog fix from upstream. I hope that that build will
> work better, but I have to wait for Koji now, it seems to be completely
> swamped.

Thank you for your time... it seems that things are now moving :-)  Probably I will
not be able try the new version before Christmas vacation (2nd week of january)

Comment 15 Fedora Update System 2019-12-23 18:25:54 UTC
FEDORA-2019-cd4008c5ce has been submitted as an update to Fedora 31. https://bodhi.fedoraproject.org/updates/FEDORA-2019-cd4008c5ce

Comment 16 Fedora Update System 2019-12-23 18:25:54 UTC
FEDORA-2019-cd4008c5ce has been submitted as an update to Fedora 31. https://bodhi.fedoraproject.org/updates/FEDORA-2019-cd4008c5ce

Comment 17 Fedora Update System 2019-12-23 18:27:51 UTC
FEDORA-2019-78e69740a0 has been submitted as an update to Fedora 30. https://bodhi.fedoraproject.org/updates/FEDORA-2019-78e69740a0

Comment 18 Maurizio Paolini 2019-12-23 22:03:33 UTC
Wonderful!  I tried kig-19.08.3-3.fc31.x86_64.rpm against a simple python script and it works! Phew!

Comment 19 Fedora Update System 2020-01-03 21:32:08 UTC
kig-19.08.3-3.fc30 has been pushed to the Fedora 30 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2019-78e69740a0

Comment 20 Fedora Update System 2020-01-04 22:20:59 UTC
kig-19.08.3-3.fc31 has been pushed to the Fedora 31 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2019-cd4008c5ce

Comment 21 Fedora Update System 2020-01-12 01:14:49 UTC
kig-19.08.3-3.fc30 has been pushed to the Fedora 30 stable repository. If problems still persist, please make note of it in this bug report.

Comment 22 Fedora Update System 2020-01-12 01:41:10 UTC
kig-19.08.3-3.fc31 has been pushed to the Fedora 31 stable repository. If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.