<commit_before>/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 *
 * Heavily based on code from Rhythmbox and Gedit.
 *
 * Copyright (C) 2005 <NAME>
 * Copyright (C) 2007 <NAME>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301  USA.
 *
 * Saturday 19th May 2007: <NAME>: Add exception clause.
 * See license_change file for details.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <Python.h>
#include <pygobject.h>
#include <pygtk/pygtk.h>

#include <signal.h>

#include <gmodule.h>

#include "totem-plugin.h"
#include "totem-python-module.h"
#include "totem-python-plugin.h"

#if PY_VERSION_HEX < 0x02050000
typedef int Py_ssize_t;
#define PY_SSIZE_T_MAX INT_MAX
#define PY_SSIZE_T_MIN INT_MIN
#endif

#define TOTEM_PYTHON_MODULE_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), \
						 TOTEM_TYPE_PYTHON_MODULE, \
						 TotemPythonModulePrivate))

typedef struct
{
	gchar *module;
	gchar *path;
	GType type;
} TotemPythonModulePrivate;

enum
{
	PROP_0,
	PROP_PATH,
	PROP_MODULE
};

#ifndef PYGOBJECT_CAN_MARSHAL_GVALUE
static PyObject *
pyg_value_g_value_as_pyobject (const GValue *value)
{
	return pyg_value_as_pyobject((GValue *)g_value_get_boxed(value), FALSE);
}

static int
pyg_value_g_value_from_pyobject (GValue *value, PyObject *obj)
{
	GType type;
	GValue obj_value = { 0, };
	
	type = pyg_type_from_object((PyObject *) obj->ob_type);
	if (! type) {
		PyErr_Clear();
		return -1;
	}
	g_value_init(&obj_value, type);
	if (pyg_value_from_pyobject(&obj_value, obj) == -1) {
		g_value_unset(&obj_value);
		return -1;
	}
	g_value_set_boxed(value, &obj_value);
	g_value_unset(&obj_value);
	return 0;
}
#endif /* PYGOBJECT_CAN_MARSHAL_GVALUE */

/* Exported by Totem Python module */
void pytotem_register_classes (PyObject *d);
void pytotem_add_constants (PyObject *module, const gchar *strip_prefix);
extern PyMethodDef pytotem_functions[];

/* We retreive this to check for correct class hierarchy */
static PyTypeObject *PyTotemPlugin_Type;

G_DEFINE_TYPE (TotemPythonModule, totem_python_module, G_TYPE_TYPE_MODULE);

static void
totem_python_module_init_python (void)
{
	PyObject *pygtk, *mdict, *require;
	PyObject *totem, *gtk, *pygtk_version, *pygtk_required_version;
	PyObject *gettext, *install, *gettext_args;
	PyObject *sys_path;
	struct sigaction old_sigint;
	gint res;
	const char *argv[] = { "totem", NULL };
	GList *paths;

	if (Py_IsInitialized ()) {
		g_warning ("Python should only be initialized once, since it's in class_init");
		g_return_if_reached ();
	}

	/* Hack to make python not overwrite SIGINT: this is needed to avoid
	 * the crash reported on gedit bug #326191 */

	/* Save old handler */
	res = sigaction (SIGINT, NULL, &old_sigint);
	if (res != 0) {
		g_warning ("Error initializing Python interpreter: cannot get "
		           "handler to SIGINT signal (%s)",
		           strerror (errno));

		return;
	}

	/* Python initialization */
	Py_Initialize ();

	/* Restore old handler */
	res = sigaction (SIGINT, &old_sigint, NULL);
	if (res != 0) {
		g_warning ("Error initializing Python interpreter: cannot restore "
		           "handler to SIGINT signal (%s)",
		           strerror (errno));
		return;<commit_msg>Bug 590566 – Compiler warning in totem-python-module.c<commit_after>/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 *
 * Heavily based on code from Rhythmbox and Gedit.
 *
 * Copyright (C) 2005 <NAME>
 * Copyright (C) 2007 <NAME>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301  USA.
 *
 * Saturday 19th May 2007: <NAME>: Add exception clause.
 * See license_change file for details.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <Python.h>
#include <pygobject.h>
#include <pygtk/pygtk.h>

#include <signal.h>

#include <gmodule.h>

#include "totem-plugin.h"
#include "totem-python-module.h"
#include "totem-python-plugin.h"

#if PY_VERSION_HEX < 0x02050000
typedef int Py_ssize_t;
#define PY_SSIZE_T_MAX INT_MAX
#define PY_SSIZE_T_MIN INT_MIN
#endif

#define TOTEM_PYTHON_MODULE_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), \
						 TOTEM_TYPE_PYTHON_MODULE, \
						 TotemPythonModulePrivate))

typedef struct
{
	gchar *module;
	gchar *path;
	GType type;
} TotemPythonModulePrivate;

enum
{
	PROP_0,
	PROP_PATH,
	PROP_MODULE
};

#ifndef PYGOBJECT_CAN_MARSHAL_GVALUE
static PyObject *
pyg_value_g_value_as_pyobject (const GValue *value)
{
	return pyg_value_as_pyobject((GValue *)g_value_get_boxed(value), FALSE);
}

static int
pyg_value_g_value_from_pyobject (GValue *value, PyObject *obj)
{
	GType type;
	GValue obj_value = { 0, };
	
	type = pyg_type_from_object((PyObject *) obj->ob_type);
	if (! type) {
		PyErr_Clear();
		return -1;
	}
	g_value_init(&obj_value, type);
	if (pyg_value_from_pyobject(&obj_value, obj) == -1) {
		g_value_unset(&obj_value);
		return -1;
	}
	g_value_set_boxed(value, &obj_value);
	g_value_unset(&obj_value);
	return 0;
}
#endif /* PYGOBJECT_CAN_MARSHAL_GVALUE */

/* Exported by Totem Python module */
void pytotem_register_classes (PyObject *d);
void pytotem_add_constants (PyObject *module, const gchar *strip_prefix);
extern PyMethodDef pytotem_functions[];

/* We retreive this to check for correct class hierarchy */
static PyTypeObject *PyTotemPlugin_Type;

G_DEFINE_TYPE (TotemPythonModule, totem_python_module, G_TYPE_TYPE_MODULE);

static void
totem_python_module_init_python (void)
{
	PyObject *pygtk, *mdict, *require;
	PyObject *totem, *gtk, *pygtk_version, *pygtk_required_version;
	PyObject *gettext, *install, *gettext_args;
	PyObject *sys_path;
	struct sigaction old_sigint;
	gint res;
	char *argv[] = { "totem", NULL };
	GList *paths;

	if (Py_IsInitialized ()) {
		g_warning ("Python should only be initialized once, since it's in class_init");
		g_return_if_reached ();
	}

	/* Hack to make python not overwrite SIGINT: this is needed to avoid
	 * the crash reported on gedit bug #326191 */

	/* Save old handler */
	res = sigaction (SIGINT, NULL, &old_sigint);
	if (res != 0) {
		g_warning ("Error initializing Python interpreter: cannot get "
		           "handler to SIGINT signal (%s)",
		           strerror (errno));

		return;
	}

	/* Python initialization */
	Py_Initialize ();

	/* Restore old handler */
	res = sigaction (SIGINT, &old_sigint, NULL);
	if (res != 0) {
		g_warning ("Error initializing Python interpreter: cannot restore "
		           "handler to SIGINT signal (%s)",
		           strerror (errno));
		return;
{'fraction_non_alphanumeric': 0.10456005138086064, 'fraction_numerical': 0.013872832369942197, 'mean_word_length': 4.3882352941176475, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1059870', 'n_tokens_mistral': 2855, 'n_tokens_neox': 2664, 'n_words': 820}