Commit e9075ebc authored by Morten Welinder's avatar Morten Welinder

GnmFunc: fix python loader and function defintion

parent 0c2226ff
......@@ -36,6 +36,8 @@
#include <Python.h>
#include <pygobject.h>
#define SERVICE_KEY "python-loader::service"
typedef struct {
GObject base;
......@@ -471,7 +473,7 @@ call_python_function_args (GnmFuncEvalInfo *ei, GnmValue const * const *args)
g_return_val_if_fail (args != NULL, NULL);
fndef = ei->func_call->func;
service = (GOPluginService *)g_object_get_data (G_OBJECT (fndef), "service");
service = (GOPluginService *)g_object_get_data (G_OBJECT (fndef), SERVICE_KEY);
loader_data = g_object_get_data (G_OBJECT (service), "loader_data");
SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service));
fn_info_tuple = PyDict_GetItemString (loader_data->python_fn_info_dict,
......@@ -501,7 +503,7 @@ call_python_function_nodes (GnmFuncEvalInfo *ei,
g_return_val_if_fail (ei->func_call != NULL, NULL);
fndef = ei->func_call->func;
service = (GOPluginService *)g_object_get_data (G_OBJECT (fndef), "service");
service = (GOPluginService *)g_object_get_data (G_OBJECT (fndef), SERVICE_KEY);
loader_data = g_object_get_data (G_OBJECT (service), "loader_data");
SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service));
python_fn = PyDict_GetItemString (loader_data->python_fn_info_dict,
......@@ -673,15 +675,11 @@ gplp_func_load_stub (GOPluginService *service,
PyString_Check (python_args) &&
(python_fn = PyTuple_GetItem (fn_info_obj, 2)) != NULL &&
PyCallable_Check (python_fn)) {
func->fn.args.func = &call_python_function_args;
func->fn.args.arg_spec = PyString_AsString (python_args);
gnm_func_set_fixargs (func, call_python_function_args, PyString_AsString (python_args));
func->help = python_function_get_gnumeric_help (
loader_data->python_fn_info_dict, python_fn, name);
func->linker = NULL;
func->impl_status = GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC;
func->test_status = GNM_FUNC_TEST_STATUS_UNKNOWN;
gnm_func_set_function_type (func, GNM_FUNC_TYPE_ARGS);
g_object_set_data (G_OBJECT (func), "service", service);
gnm_func_set_impl_status (func, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC);
g_object_set_data (G_OBJECT (func), SERVICE_KEY, service);
return;
}
......@@ -690,14 +688,11 @@ gplp_func_load_stub (GOPluginService *service,
}
if (PyCallable_Check (fn_info_obj)) {
gnm_func_set_varargs (func, call_python_function_nodes);
func->help = python_function_get_gnumeric_help (
loader_data->python_fn_info_dict, fn_info_obj, name);
func->fn.nodes = &call_python_function_nodes;
func->linker = NULL;
func->impl_status = GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC;
func->test_status = GNM_FUNC_TEST_STATUS_UNKNOWN;
gnm_func_set_function_type (func, GNM_FUNC_TYPE_NODES);
g_object_set_data (G_OBJECT (func), "service", service);
gnm_func_set_impl_status (func, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC);
g_object_set_data (G_OBJECT (func), SERVICE_KEY, service);
return;
}
......
......@@ -137,9 +137,8 @@ gnm_func_load_stub (GnmFunc *func)
if (func->fn_type == GNM_FUNC_TYPE_STUB) {
static GnmFuncHelp const no_help[] = { { GNM_FUNC_HELP_END } };
func->help = no_help;
gnm_func_set_varargs (func, error_function_no_full_info);
func->help = no_help;
}
}
......@@ -656,6 +655,31 @@ gnm_func_set_function_group (GnmFunc *func, GnmFuncGroup *group)
func->flags &= ~GNM_FUNC_IS_PLACEHOLDER;
}
void
gnm_func_set_from_desc (GnmFunc *func, GnmFuncDescriptor const *desc)
{
g_return_if_fail (GNM_IS_FUNC (func));
g_return_if_fail (desc != NULL);
// Not setting name, localized_name. Also not setting things not present
// in desc, such as translation domain.
if (desc->fn_args != NULL) {
gnm_func_set_fixargs (func, desc->fn_args, desc->arg_spec);
} else if (desc->fn_nodes != NULL) {
if (desc->arg_spec && *desc->arg_spec)
g_warning ("Arg spec for node function -- why?");
gnm_func_set_varargs (func, desc->fn_nodes);
} else {
gnm_func_set_stub (func);
return;
}
func->help = desc->help ? desc->help : NULL;
func->flags = desc->flags;
func->impl_status = desc->impl_status;
func->test_status = desc->test_status;
}
/**
......@@ -682,25 +706,16 @@ gnm_func_add (GnmFuncGroup *fn_group,
NULL);
gnm_func_set_translation_domain (func, tdomain);
func->help = desc->help ? desc->help : NULL;
func->flags = desc->flags;
func->impl_status = desc->impl_status;
func->test_status = desc->test_status;
gnm_func_set_from_desc (func, desc);
if (desc->fn_args != NULL) {
gnm_func_set_fixargs (func, desc->fn_args, desc->arg_spec);
} else if (desc->fn_nodes != NULL) {
if (desc->arg_spec && *desc->arg_spec)
g_warning ("Arg spec for node function -- why?");
gnm_func_set_varargs (func, desc->fn_nodes);
} else {
if (func->fn_type == GNM_FUNC_TYPE_STUB) {
g_warning ("Invalid function has neither args nor nodes handler");
g_object_unref (func);
return NULL;
}
func->fn_group = fn_group;
gnm_func_group_add_func (fn_group, func);
gnm_func_set_function_group (func, fn_group);
if (!(func->flags & GNM_FUNC_IS_WORKBOOK_LOCAL))
g_hash_table_insert (functions_by_name,
(gpointer)(func->name), func);
......@@ -1801,6 +1816,9 @@ static void
gnm_func_init (GnmFunc *func)
{
func->tdomain = go_string_new (GETTEXT_PACKAGE);
func->flags = GNM_FUNC_SIMPLE;
func->impl_status = GNM_FUNC_IMPL_STATUS_UNIMPLEMENTED;
func->test_status = GNM_FUNC_TEST_STATUS_UNKNOWN;
}
static void
......
......@@ -259,6 +259,8 @@ GSList *gnm_func_lookup_prefix (char const *prefix, Workbook *scope,
GnmFunc *gnm_func_add (GnmFuncGroup *group,
GnmFuncDescriptor const *descriptor,
const char *tdomain);
void gnm_func_set_from_desc (GnmFunc *func, GnmFuncDescriptor const *desc);
GnmFunc *gnm_func_add_placeholder (Workbook *scope,
char const *name,
char const *type);
......
......@@ -774,18 +774,7 @@ gnm_plugin_loader_module_func_load_stub (GOPluginService *service,
return; // Failed
desc = loader_data->module_fn_info_array + GPOINTER_TO_INT (index_ptr);
func->help = desc->help ? desc->help : NULL;
gnm_func_set_impl_status (func, desc->impl_status);
gnm_func_set_test_status (func, desc->test_status);
gnm_func_set_flags (func, desc->flags);
if (desc->fn_args != NULL) {
gnm_func_set_fixargs (func, desc->fn_args, desc->arg_spec);
} else if (desc->fn_nodes != NULL) {
gnm_func_set_varargs (func, desc->fn_nodes);
} else {
g_warning ("Invalid function descriptor with no function");
}
gnm_func_set_from_desc (func, desc);
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment