summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/quirks.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysa/quirks.c')
-rw-r--r--plugins/pychrysa/quirks.c60
1 files changed, 58 insertions, 2 deletions
diff --git a/plugins/pychrysa/quirks.c b/plugins/pychrysa/quirks.c
index 68f0a2e..2813fb2 100644
--- a/plugins/pychrysa/quirks.c
+++ b/plugins/pychrysa/quirks.c
@@ -30,6 +30,8 @@
#include <pygobject.h>
+#include "helpers.h"
+
@@ -56,6 +58,7 @@ static void pygobject_data_free_fake(PyGObjectData_fake *data)
{
PyGILState_STATE state; /* Etat interne de Python */
GSList *iter; /* Boucle de parcours */
+ GSList *old; /* Sauvegarde avant libération */
//state = pyglib_gil_state_ensure();
@@ -69,9 +72,10 @@ static void pygobject_data_free_fake(PyGObjectData_fake *data)
* On obtient le lien avant la libération via
* pygobject_unwatch_closure()...
*/
+ old = iter;
iter = iter->next;
- g_closure_invalidate((GClosure *)iter->data);
+ g_closure_invalidate((GClosure *)old->data);
}
@@ -122,6 +126,47 @@ void pychrysalide_init_quirks(void)
/******************************************************************************
* *
+* Paramètres : threshold0 = seuil pour la collecte de niveau 0. *
+* threshold1 = seuil pour la collecte de niveau 1. *
+* threshold2 = seuil pour la collecte de niveau 2. *
+* *
+* Description : Modifie les seuils de collecte pour le collecteur de Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void pychrysalide_set_gc_threshold(int threshold0, int threshold1, int threshold2)
+{
+ PyObject *module; /* Module Python "gc" */
+ PyObject *args; /* Arguments pour l'appel */
+ PyObject *value; /* Valeurs obtenues */
+
+ module = PyImport_ImportModule("gc");
+
+ if (threshold0 == 0 && threshold1 == 0 && threshold2 == 0)
+ {
+ args = Py_BuildValue("()");
+ value = run_python_method(module, "disable", args);
+ }
+ else
+ {
+ args = Py_BuildValue("(iii)", threshold0, threshold1, threshold2);
+ value = run_python_method(module, "set_threshold", args);
+ }
+
+ Py_DECREF(value);
+ Py_DECREF(args);
+
+ Py_DECREF(module);
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : obj = instance GLib crée en C. *
* type = type de l'objet Python correspond. *
* *
@@ -139,17 +184,28 @@ void pychrysalide_set_instance_data(GObject *obj, PyTypeObject *type)
data = g_object_get_qdata(obj, pygobject_instance_data_key_fake);
+ Py_INCREF(type);
+
if (data == NULL)
{
data = pygobject_data_new_fake();
+ /**
+ * Dans la majorité des cas, le type est retrouvé depuis un appel à
+ * PyObject_GetAttrString(), qui fournit une nouvelle référence.
+ * Donc nul besoin d'incrémenter encore cette référence.
+ */
data->type = type;
- Py_INCREF(type);
g_object_set_qdata_full(obj, pygobject_instance_data_key_fake,
data, (GDestroyNotify)pygobject_data_free_fake);
}
+ /**
+ * On décharge l'usage du type : le compteur est déjà bien à jour si
+ * le (futur) objet est en mémoire.
+ */
+ else Py_DECREF(type);
}