python-loader.c (gnumeric-1.12.49.tar.xz) | : | python-loader.c (gnumeric-1.12.50.tar.xz) | ||
---|---|---|---|---|
skipping to change at line 175 | skipping to change at line 175 | |||
_("Execution of module \"%s\" failed."), | _("Execution of module \"%s\" failed."), | |||
loader_python->module_name); | loader_python->module_name); | |||
gnm_python_destroy_interpreter (py_object, py_interpreter_info); | gnm_python_destroy_interpreter (py_object, py_interpreter_info); | |||
g_object_unref (py_object); | g_object_unref (py_object); | |||
return; | return; | |||
} | } | |||
(void) fclose (f); | (void) fclose (f); | |||
modules = PyImport_GetModuleDict (); | modules = PyImport_GetModuleDict (); | |||
g_return_if_fail (modules != NULL); | g_return_if_fail (modules != NULL); | |||
main_module = PyDict_GetItemString (modules, (char *) "__main__"); | main_module = PyDict_GetItemString (modules, "__main__"); | |||
g_return_if_fail (main_module != NULL); | g_return_if_fail (main_module != NULL); | |||
main_module_dict = PyModule_GetDict (main_module); | main_module_dict = PyModule_GetDict (main_module); | |||
g_return_if_fail (main_module_dict != NULL); | g_return_if_fail (main_module_dict != NULL); | |||
loader_python->py_object = py_object; | loader_python->py_object = py_object; | |||
loader_python->py_interpreter_info = py_interpreter_info; | loader_python->py_interpreter_info = py_interpreter_info; | |||
loader_python->main_module = main_module; | loader_python->main_module = main_module; | |||
loader_python->main_module_dict = main_module_dict; | loader_python->main_module_dict = main_module_dict; | |||
} | } | |||
static void | static void | |||
skipping to change at line 244 | skipping to change at line 244 | |||
if (input_wrapper == NULL) { | if (input_wrapper == NULL) { | |||
g_warning ("%s", py_exc_to_string ()); | g_warning ("%s", py_exc_to_string ()); | |||
gnm_python_clear_error_if_needed (SERVICE_GET_LOADER (service)->p y_object); | gnm_python_clear_error_if_needed (SERVICE_GET_LOADER (service)->p y_object); | |||
} | } | |||
if (input_wrapper != NULL && | if (input_wrapper != NULL && | |||
loader_data->python_func_file_probe != NULL) { | loader_data->python_func_file_probe != NULL) { | |||
/* wrapping adds a reference */ | /* wrapping adds a reference */ | |||
g_object_unref (input); | g_object_unref (input); | |||
probe_result = PyObject_CallFunction | probe_result = PyObject_CallFunction | |||
(loader_data->python_func_file_probe, | (loader_data->python_func_file_probe, | |||
(char *) "O", input_wrapper); | "O", input_wrapper); | |||
Py_DECREF (input_wrapper); | ||||
} | } | |||
Py_XDECREF (input_wrapper); | ||||
if (probe_result != NULL) { | if (probe_result != NULL) { | |||
result = PyObject_IsTrue (probe_result); | result = PyObject_IsTrue (probe_result); | |||
Py_DECREF (probe_result); | Py_DECREF (probe_result); | |||
} else { | } else { | |||
PyErr_Clear (); | PyErr_Clear (); | |||
result = FALSE; | result = FALSE; | |||
} | } | |||
return result; | return result; | |||
} | } | |||
skipping to change at line 290 | skipping to change at line 290 | |||
SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service)); | SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service)); | |||
sheet = sheet_new (wb_view_get_workbook (wb_view), _("Some name"), | sheet = sheet_new (wb_view_get_workbook (wb_view), _("Some name"), | |||
gnm_sheet_get_max_cols (old_sheet), | gnm_sheet_get_max_cols (old_sheet), | |||
gnm_sheet_get_max_rows (old_sheet)); | gnm_sheet_get_max_rows (old_sheet)); | |||
input_wrapper = pygobject_new (G_OBJECT (input)); | input_wrapper = pygobject_new (G_OBJECT (input)); | |||
if (input_wrapper != NULL) { | if (input_wrapper != NULL) { | |||
/* wrapping adds a reference */ | /* wrapping adds a reference */ | |||
g_object_unref (input); | g_object_unref (input); | |||
open_result = PyObject_CallFunction | open_result = PyObject_CallFunction | |||
(loader_data->python_func_file_open, | (loader_data->python_func_file_open, | |||
(char *) "NO", | "NO", | |||
pygobject_new (G_OBJECT (sheet)), input_wrapper); | pygobject_new (G_OBJECT (sheet)), input_wrapper); | |||
Py_DECREF (input_wrapper); | Py_DECREF (input_wrapper); | |||
} | } | |||
if (open_result != NULL) { | if (open_result != NULL) { | |||
Py_DECREF (open_result); | Py_DECREF (open_result); | |||
workbook_sheet_attach (wb_view_get_workbook (wb_view), sheet); | workbook_sheet_attach (wb_view_get_workbook (wb_view), sheet); | |||
} else { | } else { | |||
go_io_error_string (io_context, py_exc_to_string ()); | go_io_error_string (io_context, py_exc_to_string ()); | |||
gnm_python_clear_error_if_needed (SERVICE_GET_LOADER (service)->p y_object); | gnm_python_clear_error_if_needed (SERVICE_GET_LOADER (service)->p y_object); | |||
g_object_unref (sheet); | g_object_unref (sheet); | |||
skipping to change at line 338 | skipping to change at line 338 | |||
GOPluginServiceFileOpenerCallbacks *cbs; | GOPluginServiceFileOpenerCallbacks *cbs; | |||
ServiceLoaderDataFileOpener *loader_data; | ServiceLoaderDataFileOpener *loader_data; | |||
cbs = go_plugin_service_get_cbs (service); | cbs = go_plugin_service_get_cbs (service); | |||
cbs->plugin_func_file_probe = gplp_func_file_probe; | cbs->plugin_func_file_probe = gplp_func_file_probe; | |||
cbs->plugin_func_file_open = (gpointer) gplp_func_file_open; | cbs->plugin_func_file_open = (gpointer) gplp_func_file_open; | |||
loader_data = g_new (ServiceLoaderDataFileOpener, 1); | loader_data = g_new (ServiceLoaderDataFileOpener, 1); | |||
loader_data->python_func_file_probe = python_func_file_probe; | loader_data->python_func_file_probe = python_func_file_probe; | |||
loader_data->python_func_file_open = python_func_file_open; | loader_data->python_func_file_open = python_func_file_open; | |||
if (python_func_file_probe != NULL) | Py_XINCREF (loader_data->python_func_file_probe); | |||
Py_INCREF (loader_data->python_func_file_probe); | ||||
Py_INCREF (loader_data->python_func_file_open); | Py_INCREF (loader_data->python_func_file_open); | |||
g_object_set_data_full | g_object_set_data_full | |||
(G_OBJECT (service), "loader_data", loader_data, | (G_OBJECT (service), "loader_data", loader_data, | |||
(GDestroyNotify) gplp_loader_data_opener_free); | (GDestroyNotify) gplp_loader_data_opener_free); | |||
} else { | } else { | |||
*ret_error = go_error_info_new_printf ( | *ret_error = go_error_info_new_printf ( | |||
_("Python file \"%s\" has invalid format."), | _("Python file \"%s\" has invalid format."), | |||
loader_python->module_name); | loader_python->module_name); | |||
go_error_info_add_details (*ret_error, | go_error_info_add_details (*ret_error, | |||
go_error_info_new_printf ( | go_error_info_new_printf ( | |||
skipping to change at line 399 | skipping to change at line 398 | |||
saver_data = g_object_get_data (G_OBJECT (service), "loader_data"); | saver_data = g_object_get_data (G_OBJECT (service), "loader_data"); | |||
SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service)); | SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service)); | |||
py_workbook = pygobject_new (G_OBJECT (wb_view_get_workbook (wb_view))); | py_workbook = pygobject_new (G_OBJECT (wb_view_get_workbook (wb_view))); | |||
output_wrapper = pygobject_new (G_OBJECT (output)); | output_wrapper = pygobject_new (G_OBJECT (output)); | |||
if (output_wrapper != NULL) { | if (output_wrapper != NULL) { | |||
/* wrapping adds a reference */ | /* wrapping adds a reference */ | |||
g_object_unref (output); | g_object_unref (output); | |||
save_result = PyObject_CallFunction | save_result = PyObject_CallFunction | |||
(saver_data->python_func_file_save, | (saver_data->python_func_file_save, | |||
(char *) "NO", py_workbook, output_wrapper); | "NO", py_workbook, output_wrapper); | |||
Py_DECREF (output_wrapper); | Py_DECREF (output_wrapper); | |||
} | } | |||
if (save_result != NULL) { | if (save_result != NULL) { | |||
Py_DECREF (save_result); | Py_DECREF (save_result); | |||
} else { | } else { | |||
go_io_error_string (io_context, py_exc_to_string ()); | go_io_error_string (io_context, py_exc_to_string ()); | |||
gnm_python_clear_error_if_needed (SERVICE_GET_LOADER (service)->p y_object); | gnm_python_clear_error_if_needed (SERVICE_GET_LOADER (service)->p y_object); | |||
} | } | |||
} | } | |||
skipping to change at line 490 | skipping to change at line 489 | |||
g_return_val_if_fail (ei != NULL, NULL); | g_return_val_if_fail (ei != NULL, NULL); | |||
g_return_val_if_fail (ei->func_call != NULL, NULL); | g_return_val_if_fail (ei->func_call != NULL, NULL); | |||
g_return_val_if_fail (args != NULL, NULL); | g_return_val_if_fail (args != NULL, NULL); | |||
fndef = ei->func_call->func; | fndef = ei->func_call->func; | |||
service = (GOPluginService *)g_object_get_data (G_OBJECT (fndef), SERVICE _KEY); | service = (GOPluginService *)g_object_get_data (G_OBJECT (fndef), SERVICE _KEY); | |||
loader_data = g_object_get_data (G_OBJECT (service), "loader_data"); | loader_data = g_object_get_data (G_OBJECT (service), "loader_data"); | |||
SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service)); | SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service)); | |||
fn_info_tuple = PyDict_GetItemString (loader_data->python_fn_info_dict, | fn_info_tuple = PyDict_GetItemString (loader_data->python_fn_info_dict, | |||
(gchar *) gnm_func_get_name (fndef, | gnm_func_get_name (fndef, FALSE)); | |||
FALSE)); | g_assert (fn_info_tuple != NULL && PyTuple_Check (fn_info_tuple)); | |||
g_assert (fn_info_tuple != NULL); | ||||
python_fn = PyTuple_GetItem (fn_info_tuple, 2); | python_fn = PyTuple_GetItem (fn_info_tuple, 2); | |||
gnm_func_count_args (fndef, &min_n_args, &max_n_args); | gnm_func_count_args (fndef, &min_n_args, &max_n_args); | |||
for (n_args = min_n_args; n_args < max_n_args && args[n_args] != NULL; n_ args++) { | for (n_args = min_n_args; n_args < max_n_args && args[n_args] != NULL; n_ args++) { | |||
; | ; | |||
} | } | |||
return call_python_function (python_fn, ei->pos, n_args, args); | return call_python_function (python_fn, ei->pos, n_args, args); | |||
} | } | |||
static GnmValue * | static GnmValue * | |||
call_python_function_nodes (GnmFuncEvalInfo *ei, | call_python_function_nodes (GnmFuncEvalInfo *ei, | |||
skipping to change at line 520 | skipping to change at line 519 | |||
GnmValue *ret_value; | GnmValue *ret_value; | |||
g_return_val_if_fail (ei != NULL, NULL); | g_return_val_if_fail (ei != NULL, NULL); | |||
g_return_val_if_fail (ei->func_call != NULL, NULL); | g_return_val_if_fail (ei->func_call != NULL, NULL); | |||
fndef = ei->func_call->func; | fndef = ei->func_call->func; | |||
service = (GOPluginService *)g_object_get_data (G_OBJECT (fndef), SERVICE _KEY); | service = (GOPluginService *)g_object_get_data (G_OBJECT (fndef), SERVICE _KEY); | |||
loader_data = g_object_get_data (G_OBJECT (service), "loader_data"); | loader_data = g_object_get_data (G_OBJECT (service), "loader_data"); | |||
SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service)); | SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service)); | |||
python_fn = PyDict_GetItemString (loader_data->python_fn_info_dict, | python_fn = PyDict_GetItemString (loader_data->python_fn_info_dict, | |||
(gchar *) gnm_func_get_name (fndef, FAL SE)); | gnm_func_get_name (fndef, FALSE)); | |||
values = g_new (GnmValue *, argc); | values = g_new (GnmValue *, argc); | |||
for (i = 0; i < argc; i++) { | for (i = 0; i < argc; i++) { | |||
values[i] = gnm_expr_eval (argv[i], ei->pos, GNM_EXPR_EVAL_PERMIT _NON_SCALAR); | values[i] = gnm_expr_eval (argv[i], ei->pos, GNM_EXPR_EVAL_PERMIT _NON_SCALAR); | |||
} | } | |||
ret_value = call_python_function (python_fn, ei->pos, argc, | ret_value = call_python_function (python_fn, ei->pos, argc, | |||
(GnmValue const * const *)values); | (GnmValue const * const *)values); | |||
for (i = 0; i < argc; i++) { | for (i = 0; i < argc; i++) { | |||
value_release (values[i]); | value_release (values[i]); | |||
} | } | |||
skipping to change at line 549 | skipping to change at line 548 | |||
} | } | |||
static GnmFuncHelp const * | static GnmFuncHelp const * | |||
python_function_get_gnumeric_help (PyObject *python_fn_info_dict, PyObject *pyth on_fn, | python_function_get_gnumeric_help (PyObject *python_fn_info_dict, PyObject *pyth on_fn, | |||
const gchar *fn_name) | const gchar *fn_name) | |||
{ | { | |||
gchar *help_attr_name; | gchar *help_attr_name; | |||
PyObject *cobject_help_value; | PyObject *cobject_help_value; | |||
PyObject *python_arg_names; | PyObject *python_arg_names; | |||
PyObject *fn_info_obj; | PyObject *fn_info_obj; | |||
GnmFuncHelp const *res = NULL; | ||||
fn_info_obj = PyDict_GetItemString (python_fn_info_dict, (gchar *) fn_nam | fn_info_obj = PyDict_GetItemString (python_fn_info_dict, fn_name); | |||
e); | python_arg_names = PyTuple_Check (fn_info_obj) | |||
python_arg_names = PyTuple_GetItem (fn_info_obj, 1); | ? PyTuple_GetItem (fn_info_obj, 1) | |||
: NULL; | ||||
help_attr_name = g_strdup_printf ("_CGnumericHelp_%s", fn_name); | help_attr_name = g_strdup_printf ("_CGnumericHelp_%s", fn_name); | |||
cobject_help_value = PyDict_GetItemString (python_fn_info_dict, help_attr _name); | cobject_help_value = PyDict_GetItemString (python_fn_info_dict, help_attr _name); | |||
if (cobject_help_value == NULL) { | if (cobject_help_value == NULL) { | |||
PyObject *python_fn_help = | PyObject *python_fn_help = | |||
PyFunction_Check (python_fn) | PyFunction_Check (python_fn) | |||
? ((PyFunctionObject *) python_fn)->func_doc | ? ((PyFunctionObject *) python_fn)->func_doc | |||
: NULL; | : NULL; | |||
if (python_fn_help != NULL && PyUnicode_Check (python_fn_help)) { | if (python_fn_help != NULL && PyUnicode_Check (python_fn_help)) { | |||
guint n = 0; | guint n = 0; | |||
skipping to change at line 657 | skipping to change at line 659 | |||
n++; | n++; | |||
new_help = g_renew (GnmFuncHelp, new_help, n); | new_help = g_renew (GnmFuncHelp, new_help, n); | |||
new_help[n-1].type = GNM_FUNC_HELP_END; | new_help[n-1].type = GNM_FUNC_HELP_END; | |||
new_help[n-1].text = NULL; | new_help[n-1].text = NULL; | |||
cobject_help_value = PyCapsule_New (new_help, "FuncHelp", FuncHelpDestructor); | cobject_help_value = PyCapsule_New (new_help, "FuncHelp", FuncHelpDestructor); | |||
PyDict_SetItemString (python_fn_info_dict, help_attr_name , cobject_help_value); | PyDict_SetItemString (python_fn_info_dict, help_attr_name , cobject_help_value); | |||
} | } | |||
} | } | |||
g_free (help_attr_name); | g_free (help_attr_name); | |||
if (cobject_help_value == NULL) | ||||
return NULL; | ||||
return (GnmFuncHelp const *) PyCapsule_GetPointer (cobject_help_value, "F | if (cobject_help_value) { | |||
uncHelp"); | res = (GnmFuncHelp const *) PyCapsule_GetPointer (cobject_help_va | |||
lue, "FuncHelp"); | ||||
Py_DECREF (cobject_help_value); | ||||
} | ||||
return res; | ||||
} | } | |||
static void | static void | |||
gplp_func_load_stub (GOPluginService *service, | gplp_func_load_stub (GOPluginService *service, | |||
GnmFunc *func) | GnmFunc *func) | |||
{ | { | |||
ServiceLoaderDataFunctionGroup *loader_data; | ServiceLoaderDataFunctionGroup *loader_data; | |||
PyObject *fn_info_obj; | PyObject *fn_info_obj; | |||
char const *name; | char const *name; | |||
g_return_if_fail (GNM_IS_PLUGIN_SERVICE_FUNCTION_GROUP (service)); | g_return_if_fail (GNM_IS_PLUGIN_SERVICE_FUNCTION_GROUP (service)); | |||
g_return_if_fail (GNM_IS_FUNC (func)); | g_return_if_fail (GNM_IS_FUNC (func)); | |||
name = gnm_func_get_name (func, FALSE); | name = gnm_func_get_name (func, FALSE); | |||
loader_data = g_object_get_data (G_OBJECT (service), "loader_data"); | loader_data = g_object_get_data (G_OBJECT (service), "loader_data"); | |||
SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service)); | SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service)); | |||
fn_info_obj = PyDict_GetItemString (loader_data->python_fn_info_dict, | fn_info_obj = PyDict_GetItemString (loader_data->python_fn_info_dict, | |||
(gchar *)name); | name); | |||
if (fn_info_obj == NULL) { | if (fn_info_obj == NULL) { | |||
gnm_python_clear_error_if_needed (SERVICE_GET_LOADER (service)->p y_object); | gnm_python_clear_error_if_needed (SERVICE_GET_LOADER (service)->p y_object); | |||
return; | return; | |||
} | } | |||
if (PyTuple_Check (fn_info_obj)) { | if (PyTuple_Check (fn_info_obj)) { | |||
PyObject *python_args; | PyObject *python_args; | |||
PyObject *python_fn; | PyObject *python_fn; | |||
if (PyTuple_Size (fn_info_obj) == 3 && | if (PyTuple_Size (fn_info_obj) == 3 && | |||
skipping to change at line 783 | skipping to change at line 788 | |||
GOErrorInfo **ret_error) | GOErrorInfo **ret_error) | |||
{ | { | |||
ServiceLoaderDataFunctionGroup *loader_data; | ServiceLoaderDataFunctionGroup *loader_data; | |||
g_return_if_fail (GNM_IS_PYTHON_PLUGIN_LOADER (loader)); | g_return_if_fail (GNM_IS_PYTHON_PLUGIN_LOADER (loader)); | |||
g_return_if_fail (GNM_IS_PLUGIN_SERVICE_FUNCTION_GROUP (service)); | g_return_if_fail (GNM_IS_PLUGIN_SERVICE_FUNCTION_GROUP (service)); | |||
GO_INIT_RET_ERROR_INFO (ret_error); | GO_INIT_RET_ERROR_INFO (ret_error); | |||
loader_data = g_object_get_data (G_OBJECT (service), "loader_data"); | loader_data = g_object_get_data (G_OBJECT (service), "loader_data"); | |||
SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service)); | SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service)); | |||
Py_DECREF (loader_data->python_fn_info_dict); | Py_CLEAR (loader_data->python_fn_info_dict); | |||
} | } | |||
typedef struct { | typedef struct { | |||
PyObject *ui_actions; | PyObject *ui_actions; | |||
} ServiceLoaderDataUI; | } ServiceLoaderDataUI; | |||
static void | static void | |||
gplp_loader_data_ui_free (ServiceLoaderDataUI *loader_data) | gplp_loader_data_ui_free (ServiceLoaderDataUI *loader_data) | |||
{ | { | |||
Py_DECREF (loader_data->ui_actions); | Py_DECREF (loader_data->ui_actions); | |||
skipping to change at line 824 | skipping to change at line 829 | |||
fn = PyDict_GetItemString (loader_data->ui_actions, action->id); | fn = PyDict_GetItemString (loader_data->ui_actions, action->id); | |||
if (fn == NULL) { | if (fn == NULL) { | |||
*ret_error = go_error_info_new_printf (_("Unknown action: %s"), | *ret_error = go_error_info_new_printf (_("Unknown action: %s"), | |||
action->id); | action->id); | |||
return; | return; | |||
} else if (!PyCallable_Check (fn)) { | } else if (!PyCallable_Check (fn)) { | |||
*ret_error = go_error_info_new_printf ( | *ret_error = go_error_info_new_printf ( | |||
_("Not a valid function for action: %s"), action->id); | _("Not a valid function for action: %s"), action->id); | |||
return; | return; | |||
} | } | |||
ret = PyObject_CallFunction (fn, (char *) "N", | ret = PyObject_CallFunction (fn, "N", | |||
pygobject_new (G_OBJECT (WBC_GTK (wbc)))); | pygobject_new (G_OBJECT (WBC_GTK (wbc)))); | |||
if (ret == NULL) { | if (ret == NULL) { | |||
*ret_error = go_error_info_new_str (py_exc_to_string ()); | *ret_error = go_error_info_new_str (py_exc_to_string ()); | |||
PyErr_Clear (); | PyErr_Clear (); | |||
} else { | } else { | |||
Py_DECREF (ret); | Py_DECREF (ret); | |||
} | } | |||
} | } | |||
static void | static void | |||
End of changes. 15 change blocks. | ||||
21 lines changed or deleted | 24 lines changed or added |