After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 620060 - Don't assume we are initialized if python is
Don't assume we are initialized if python is
Status: RESOLVED FIXED
Product: libpeas
Classification: Platform
Component: python
git master
Other Linux
: Normal normal
: ---
Assigned To: libpeas-maint
libpeas-maint
Depends on: 617600
Blocks:
 
 
Reported: 2010-05-30 00:31 UTC by Steve Frécinaux
Modified: 2010-06-27 19:24 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Don't assume the python plugin loader has been initialized if python has been (3.71 KB, patch)
2010-05-30 07:47 UTC, Garrett Regier
rejected Details | Review
[Python] Don't assume libpeas's stuff is initialized if python is. (1.63 KB, patch)
2010-06-27 18:13 UTC, Steve Frécinaux
committed Details | Review
[Python] Don't finalize python if we didn't initialize it. (1.49 KB, patch)
2010-06-27 18:13 UTC, Steve Frécinaux
committed Details | Review

Description Steve Frécinaux 2010-05-30 00:31:35 UTC
+++ This bug was initially created as a clone of Bug #617600 +++

If python is initialized the python loaded assumes that it is, even if it is not the case.

This causes issues when using gtkparasite which has its own python console that is initialized before libpeas has the chance.
Comment 1 Garrett Regier 2010-05-30 07:47:03 UTC
Created attachment 162298 [details] [review]
Don't assume the python plugin loader has been initialized if python has been

Thanks for the reminder
Comment 2 Steve Frécinaux 2010-05-30 15:05:56 UTC
Review of attachment 162298 [details] [review]:

There is something that bugs me in this patch: you don't alter the cases where we check for Py_IsInitialized(), like in peas_python_shutdown(). But, since this last function will Finalize() the python interpreter, it is going to break things if you launch gtkparasite but can't init pygobject or gettext, because in this case peas_python_shutdown() will call Py_Finalize() and exit the interpreter... 

You can probably check against the status instead (or in addition) of Py_IsInitialized at the other places as well?

::: loaders/python/peas-plugin-loader-python.c
@@ +39,3 @@
+  PEAS_PYTHON_STATUS_FAILED,
+  PEAS_PYTHON_STATUS_SUCCESS
+} PeasPythonStatusType;

IMHO you should rename the statuses STATUS_NOT_RUN, etc, to make the code using this enum shorter (this would be similar to what's done for properties), or maybe INIT_NOT_RUN, INIT_FAILED, INIT_SUCCESS?

@@ +393,1 @@
      ends with success */

Please rewrap the comment text to avoid being wider than 80 chars

@@ +414,3 @@
   /* Python initialization */
+  if (!Py_IsInitialized ())
+    Py_Initialize ();

Shouldn't you also protect PySys_SetArgv ?
Comment 3 Steve Frécinaux 2010-06-27 18:13:43 UTC
Created attachment 164760 [details] [review]
[Python] Don't assume libpeas's stuff is initialized if python is.

We need to ensure we run our own initialization function even if python
has already been initialized by someone else (either our host
application or something like gtkparasite).
Comment 4 Steve Frécinaux 2010-06-27 18:13:48 UTC
Created attachment 164761 [details] [review]
[Python] Don't finalize python if we didn't initialize it.

This is to avoid weird effects on other components that might be using
python if we didn't initialize it ourselves.