py-gnumeric.c (gnumeric-1.12.49.tar.xz) | : | py-gnumeric.c (gnumeric-1.12.50.tar.xz) | ||
---|---|---|---|---|
skipping to change at line 34 | skipping to change at line 34 | |||
#include <goffice/goffice.h> | #include <goffice/goffice.h> | |||
#include <glib/gi18n-lib.h> | #include <glib/gi18n-lib.h> | |||
#include <Python.h> | #include <Python.h> | |||
#define NO_IMPORT_PYGOBJECT | #define NO_IMPORT_PYGOBJECT | |||
#include <pygobject.h> | #include <pygobject.h> | |||
static PyObject *GnmModule = NULL; | static PyObject *GnmModule = NULL; | |||
static PyTypeObject py_Boolean_object_type; | ||||
typedef struct _py_Boolean_object py_Boolean_object; | ||||
static PyObject *py_new_Boolean_object (gboolean value); | ||||
static gboolean py_Boolean_as_gboolean (py_Boolean_object *self); | ||||
static PyTypeObject py_CellRef_object_type; | static PyTypeObject py_CellRef_object_type; | |||
typedef struct _py_CellRef_object py_CellRef_object; | typedef struct _py_CellRef_object py_CellRef_object; | |||
static PyTypeObject py_RangeRef_object_type; | static PyTypeObject py_RangeRef_object_type; | |||
typedef struct _py_RangeRef_object py_RangeRef_object; | typedef struct _py_RangeRef_object py_RangeRef_object; | |||
static PyObject *py_new_RangeRef_object (GnmRangeRef const *range_ref); | static PyObject *py_new_RangeRef_object (GnmRangeRef const *range_ref); | |||
static GnmRangeRef *py_RangeRef_as_RangeRef (py_RangeRef_object *self); | static GnmRangeRef *py_RangeRef_as_RangeRef (py_RangeRef_object *self); | |||
typedef struct _py_GnumericFunc_object py_GnumericFunc_object; | typedef struct _py_GnumericFunc_object py_GnumericFunc_object; | |||
static PyTypeObject py_GnumericFunc_object_type; | static PyTypeObject py_GnumericFunc_object_type; | |||
skipping to change at line 81 | skipping to change at line 76 | |||
- get_description | - get_description | |||
Module Gnumeric: | Module Gnumeric: | |||
Attributes: | Attributes: | |||
- TRUE/FALSE (values of type Boolean) | - TRUE/FALSE (values of type Boolean) | |||
- GnumericError (exception), GnumericError* (std exception values) | - GnumericError (exception), GnumericError* (std exception values) | |||
- functions (dictionary containing all Gnumeric functions) | - functions (dictionary containing all Gnumeric functions) | |||
*/ | */ | |||
// Like PyDict_SetItemString, but takes ownership of val | ||||
static void | ||||
gnm_py_dict_store (PyObject *dict, const char *key, PyObject *val) | ||||
{ | ||||
PyDict_SetItemString (dict, key, val); | ||||
Py_DECREF (val); | ||||
} | ||||
#define GNUMERIC_MODULE \ | #define GNUMERIC_MODULE \ | |||
(PyImport_AddModule ((char *) "Gnumeric")) | (PyImport_AddModule ("Gnumeric")) | |||
#define GNUMERIC_MODULE_GET(key) \ | #define GNUMERIC_MODULE_GET(key) \ | |||
PyDict_GetItemString (PyModule_GetDict (GNUMERIC_MODULE), (char *) (key)) | PyDict_GetItemString (PyModule_GetDict (GNUMERIC_MODULE), (key)) | |||
#define GNUMERIC_MODULE_SET(key, val) \ | #define GNUMERIC_MODULE_SET(key, val) \ | |||
PyDict_SetItemString (PyModule_GetDict (GNUMERIC_MODULE), (char *) (key), val) | gnm_py_dict_store (PyModule_GetDict (GNUMERIC_MODULE), (key), val) | |||
#define SET_EVAL_POS(val) \ | #define SET_EVAL_POS(val) \ | |||
GNUMERIC_MODULE_SET ("Gnumeric_eval_pos", PyCapsule_New (val, "eval_pos", NULL)) | GNUMERIC_MODULE_SET ("Gnumeric_eval_pos", PyCapsule_New (val, "eval_pos", NULL)) | |||
#define UNSET_EVAL_POS \ | #define UNSET_EVAL_POS \ | |||
PyDict_DelItemString (PyModule_GetDict (GNUMERIC_MODULE), "Gnumeric_eval_ pos") | PyDict_DelItemString (PyModule_GetDict (GNUMERIC_MODULE), "Gnumeric_eval_ pos") | |||
static GnmValue * | static GnmValue * | |||
py_obj_to_gnm_value (const GnmEvalPos *eval_pos, PyObject *py_val) | py_obj_to_gnm_value (const GnmEvalPos *eval_pos, PyObject *py_val) | |||
{ | { | |||
PyObject *py_val_type; | PyObject *py_val_type; | |||
GnmValue *ret_val; | GnmValue *ret_val; | |||
g_return_val_if_fail (eval_pos != NULL, NULL); | g_return_val_if_fail (eval_pos != NULL, NULL); | |||
g_return_val_if_fail (py_val != NULL, NULL); | g_return_val_if_fail (py_val != NULL, NULL); | |||
py_val_type = PyObject_Type (py_val); | py_val_type = PyObject_Type (py_val); | |||
if (py_val_type == NULL) { | if (py_val_type == NULL) { | |||
PyErr_Clear (); | PyErr_Clear (); | |||
ret_val = value_new_empty (); | ret_val = value_new_empty (); | |||
} else if (py_val == Py_None) { | } else if (py_val == Py_None) { | |||
ret_val = value_new_empty (); | ret_val = value_new_empty (); | |||
} else if (py_val_type == (PyObject *) &py_Boolean_object_type) { | } else if (PyBool_Check (py_val)) { | |||
ret_val = value_new_bool (py_Boolean_as_gboolean ((py_Boolean_obj | ret_val = value_new_bool (py_val == Py_True); | |||
ect *) py_val)); | ||||
} else if (PyLong_Check (py_val)) { | } else if (PyLong_Check (py_val)) { | |||
ret_val = value_new_int ((gint) PyLong_AsLong (py_val)); | ret_val = value_new_float ((gnm_float)PyLong_AsLong (py_val)); | |||
} else if (PyFloat_Check (py_val)) { | } else if (PyFloat_Check (py_val)) { | |||
ret_val = value_new_float ((gnm_float) PyFloat_AsDouble (py_val)) ; | ret_val = value_new_float ((gnm_float) PyFloat_AsDouble (py_val)) ; | |||
} else if (PyUnicode_Check (py_val)) { | } else if (PyUnicode_Check (py_val)) { | |||
ret_val = value_new_string (PyUnicode_AsUTF8 (py_val)); | ret_val = value_new_string (PyUnicode_AsUTF8 (py_val)); | |||
} else if (py_val_type == (PyObject *) &py_RangeRef_object_type) { | } else if (py_val_type == (PyObject *) &py_RangeRef_object_type) { | |||
GnmRangeRef *range_ref; | GnmRangeRef *range_ref; | |||
range_ref = py_RangeRef_as_RangeRef ((py_RangeRef_object *) py_va l); | range_ref = py_RangeRef_as_RangeRef ((py_RangeRef_object *) py_va l); | |||
ret_val = value_new_cellrange_unsafe (&range_ref->a, &range_ref-> b); | ret_val = value_new_cellrange_unsafe (&range_ref->a, &range_ref-> b); | |||
} else if (PyList_Check (py_val)) { | } else if (PyList_Check (py_val)) { | |||
skipping to change at line 227 | skipping to change at line 230 | |||
} | } | |||
static PyObject * | static PyObject * | |||
gnm_value_to_py_obj (const GnmEvalPos *eval_pos, const GnmValue *val) | gnm_value_to_py_obj (const GnmEvalPos *eval_pos, const GnmValue *val) | |||
{ | { | |||
PyObject *py_val = NULL; | PyObject *py_val = NULL; | |||
g_return_val_if_fail (eval_pos != NULL, NULL); | g_return_val_if_fail (eval_pos != NULL, NULL); | |||
g_return_val_if_fail (val != NULL, NULL); | g_return_val_if_fail (val != NULL, NULL); | |||
switch (val->v_any.type) { | switch (val->v_any.type) { | |||
case VALUE_BOOLEAN: | case VALUE_BOOLEAN: | |||
py_val = py_new_Boolean_object (value_get_as_checked_bool (val)); | py_val = value_get_as_checked_bool (val) ? Py_True : Py_False; | |||
Py_INCREF (py_val); | ||||
break; | break; | |||
case VALUE_FLOAT: | case VALUE_FLOAT: | |||
py_val = PyFloat_FromDouble (value_get_as_float (val)); | py_val = PyFloat_FromDouble (value_get_as_float (val)); | |||
break; | break; | |||
case VALUE_STRING: | case VALUE_STRING: | |||
py_val = PyUnicode_FromString (value_peek_string (val)); | py_val = PyUnicode_FromString (value_peek_string (val)); | |||
break; | break; | |||
case VALUE_CELLRANGE: | case VALUE_CELLRANGE: | |||
py_val = py_new_RangeRef_object (&val->v_range.cell); | py_val = py_new_RangeRef_object (&val->v_range.cell); | |||
break; | break; | |||
skipping to change at line 363 | skipping to change at line 367 | |||
PyErr_Clear (); | PyErr_Clear (); | |||
} | } | |||
if (eval_pos_set) { | if (eval_pos_set) { | |||
UNSET_EVAL_POS; | UNSET_EVAL_POS; | |||
} | } | |||
return ret_value; | return ret_value; | |||
} | } | |||
/* | /* | |||
* Boolean | ||||
*/ | ||||
struct _py_Boolean_object { | ||||
PyObject_HEAD | ||||
gboolean value; | ||||
}; | ||||
static gboolean | ||||
py_Boolean_as_gboolean (py_Boolean_object *self) | ||||
{ | ||||
return self->value; | ||||
} | ||||
static PyObject * | ||||
py_Boolean_object_str (py_Boolean_object *self) | ||||
{ | ||||
return PyUnicode_FromString (self->value ? "True" : "False"); | ||||
} | ||||
static void | ||||
py_Boolean_object_dealloc (py_Boolean_object *self) | ||||
{ | ||||
PyObject_Del (self); | ||||
} | ||||
static PyObject * | ||||
py_new_Boolean_object (gboolean value) | ||||
{ | ||||
py_Boolean_object *self; | ||||
self = PyObject_NEW (py_Boolean_object, &py_Boolean_object_type); | ||||
if (self == NULL) { | ||||
return NULL; | ||||
} | ||||
self->value = value; | ||||
return (PyObject *) self; | ||||
} | ||||
static PyTypeObject py_Boolean_object_type = { | ||||
PyVarObject_HEAD_INIT(NULL, 0) | ||||
.tp_name = (char *) "Boolean", | ||||
.tp_basicsize = sizeof (py_Boolean_object), | ||||
.tp_dealloc = (destructor) &py_Boolean_object_dealloc, | ||||
.tp_str = (reprfunc) py_Boolean_object_str | ||||
}; | ||||
/* | ||||
* CellRef | * CellRef | |||
*/ | */ | |||
/* | /* | |||
* FIXME: The sheet and cells the GnmCellRef refer to may be deleted | * FIXME: The sheet and cells the GnmCellRef refer to may be deleted | |||
* behind our backs. | * behind our backs. | |||
*/ | */ | |||
struct _py_CellRef_object { | struct _py_CellRef_object { | |||
PyObject_HEAD | PyObject_HEAD | |||
skipping to change at line 444 | skipping to change at line 399 | |||
return &self->cell_ref; | return &self->cell_ref; | |||
} | } | |||
#endif | #endif | |||
static PyObject * | static PyObject * | |||
py_CellRef_object_getattr (py_CellRef_object *self, gchar *name) | py_CellRef_object_getattr (py_CellRef_object *self, gchar *name) | |||
{ | { | |||
PyObject *result; | PyObject *result; | |||
if (strcmp (name, "col") == 0) { | if (strcmp (name, "col") == 0) { | |||
result = Py_BuildValue ((char *) "i", self->cell_ref.col); | result = PyLong_FromLong (self->cell_ref.col); | |||
} else if (strcmp (name, "row") == 0) { | } else if (strcmp (name, "row") == 0) { | |||
result = Py_BuildValue ((char *) "i", self->cell_ref.row); | result = PyLong_FromLong (self->cell_ref.row); | |||
} else if (strcmp (name, "sheet") == 0) { | } else if (strcmp (name, "sheet") == 0) { | |||
if (self->cell_ref.sheet) | if (self->cell_ref.sheet) | |||
result = pygobject_new (G_OBJECT (self->cell_ref.sheet)); | result = pygobject_new (G_OBJECT (self->cell_ref.sheet)); | |||
else { | else { | |||
Py_INCREF (Py_None); | Py_INCREF (Py_None); | |||
result = Py_None; | result = Py_None; | |||
} | } | |||
} else if (strcmp (name, "col_relative") == 0) { | } else if (strcmp (name, "col_relative") == 0) { | |||
result = Py_BuildValue ((char *) "i", | result = PyBool_FromLong (self->cell_ref.col_relative); | |||
self->cell_ref.col_relative ? 1 : 0); | ||||
} else if (strcmp (name, "row_relative") == 0) { | } else if (strcmp (name, "row_relative") == 0) { | |||
result = Py_BuildValue ((char *) "i", | result = PyBool_FromLong (self->cell_ref.row_relative); | |||
self->cell_ref.row_relative ? 1 : 0); | ||||
} else { | } else { | |||
result = PyObject_CallMethod ((PyObject *) self, name, NULL); | result = PyObject_CallMethod ((PyObject *) self, name, NULL); | |||
} | } | |||
return result; | return result; | |||
} | } | |||
static void | static void | |||
py_CellRef_object_dealloc (py_CellRef_object *self) | py_CellRef_object_dealloc (py_CellRef_object *self) | |||
{ | { | |||
skipping to change at line 489 | skipping to change at line 442 | |||
if (self == NULL) { | if (self == NULL) { | |||
return NULL; | return NULL; | |||
} | } | |||
self->cell_ref = *cell_ref; | self->cell_ref = *cell_ref; | |||
return (PyObject *) self; | return (PyObject *) self; | |||
} | } | |||
static PyTypeObject py_CellRef_object_type = { | static PyTypeObject py_CellRef_object_type = { | |||
PyVarObject_HEAD_INIT(NULL, 0) | PyVarObject_HEAD_INIT(NULL, 0) | |||
.tp_name = (char *) "CellRef", | .tp_name = "CellRef", | |||
.tp_basicsize = sizeof (py_CellRef_object), | .tp_basicsize = sizeof (py_CellRef_object), | |||
.tp_dealloc = (destructor) &py_CellRef_object_dealloc, | .tp_dealloc = (destructor) &py_CellRef_object_dealloc, | |||
.tp_getattr = (getattrfunc) &py_CellRef_object_getattr, | .tp_getattr = (getattrfunc) &py_CellRef_object_getattr, | |||
.tp_methods = py_CellRef_object_methods | .tp_methods = py_CellRef_object_methods | |||
}; | }; | |||
/* | /* | |||
* RangeRef | * RangeRef | |||
*/ | */ | |||
skipping to change at line 514 | skipping to change at line 467 | |||
struct _py_RangeRef_object { | struct _py_RangeRef_object { | |||
PyObject_HEAD | PyObject_HEAD | |||
GnmRangeRef range_ref; | GnmRangeRef range_ref; | |||
}; | }; | |||
static PyObject * | static PyObject * | |||
py_RangeRef_get_tuple_method (py_RangeRef_object *self, PyObject *args); | py_RangeRef_get_tuple_method (py_RangeRef_object *self, PyObject *args); | |||
static struct PyMethodDef py_RangeRef_object_methods[] = { | static struct PyMethodDef py_RangeRef_object_methods[] = { | |||
{(char *) "get_tuple", (PyCFunction) py_RangeRef_get_tuple_method, | {"get_tuple", (PyCFunction) py_RangeRef_get_tuple_method, METH_VARARGS}, | |||
METH_VARARGS}, | ||||
{NULL, NULL} | {NULL, NULL} | |||
}; | }; | |||
static GnmRangeRef * | static GnmRangeRef * | |||
py_RangeRef_as_RangeRef (py_RangeRef_object *self) | py_RangeRef_as_RangeRef (py_RangeRef_object *self) | |||
{ | { | |||
return &self->range_ref; | return &self->range_ref; | |||
} | } | |||
static PyObject * | static PyObject * | |||
py_RangeRef_get_tuple_method (py_RangeRef_object *self, PyObject *args) | py_RangeRef_get_tuple_method (py_RangeRef_object *self, PyObject *args) | |||
{ | { | |||
if (!PyArg_ParseTuple (args, (char *) ":get_tuple")) { | if (!PyArg_ParseTuple (args, ":get_tuple")) { | |||
return NULL; | return NULL; | |||
} | } | |||
return Py_BuildValue ((char *) "(O&O&)", | return Py_BuildValue ("(O&O&)", | |||
py_new_CellRef_object, &self->range_ref.a, | py_new_CellRef_object, &self->range_ref.a, | |||
py_new_CellRef_object, &self->range_ref.b); | py_new_CellRef_object, &self->range_ref.b); | |||
} | } | |||
static PyObject * | static PyObject * | |||
py_RangeRef_object_getattr (py_RangeRef_object *self, gchar *name) | py_RangeRef_object_getattr (py_RangeRef_object *self, gchar *name) | |||
{ | { | |||
if (strcmp (name, "start") == 0) { | if (strcmp (name, "start") == 0) { | |||
return py_new_CellRef_object (&self->range_ref.a); | return py_new_CellRef_object (&self->range_ref.a); | |||
} else if (strcmp (name, "end") == 0) { | } else if (strcmp (name, "end") == 0) { | |||
skipping to change at line 571 | skipping to change at line 523 | |||
if (self == NULL) { | if (self == NULL) { | |||
return NULL; | return NULL; | |||
} | } | |||
self->range_ref = *range_ref; | self->range_ref = *range_ref; | |||
return (PyObject *) self; | return (PyObject *) self; | |||
} | } | |||
static PyTypeObject py_RangeRef_object_type = { | static PyTypeObject py_RangeRef_object_type = { | |||
PyVarObject_HEAD_INIT(NULL, 0) | PyVarObject_HEAD_INIT(NULL, 0) | |||
.tp_name = (char *) "RangeRef", | .tp_name = "RangeRef", | |||
.tp_basicsize = sizeof (py_RangeRef_object), | .tp_basicsize = sizeof (py_RangeRef_object), | |||
.tp_dealloc = (destructor) &py_RangeRef_object_dealloc, | .tp_dealloc = (destructor) &py_RangeRef_object_dealloc, | |||
.tp_getattr = (getattrfunc) &py_RangeRef_object_getattr, | .tp_getattr = (getattrfunc) &py_RangeRef_object_getattr, | |||
.tp_methods = py_RangeRef_object_methods /* */ | .tp_methods = py_RangeRef_object_methods /* */ | |||
}; | }; | |||
/* | /* | |||
* GnmStyle | * GnmStyle | |||
*/ | */ | |||
skipping to change at line 641 | skipping to change at line 593 | |||
*self->eval_pos = *opt_eval_pos; | *self->eval_pos = *opt_eval_pos; | |||
} else { | } else { | |||
self->eval_pos = NULL; | self->eval_pos = NULL; | |||
} | } | |||
return (PyObject *) self; | return (PyObject *) self; | |||
} | } | |||
static PyTypeObject py_GnumericFunc_object_type = { | static PyTypeObject py_GnumericFunc_object_type = { | |||
PyVarObject_HEAD_INIT(NULL,0) | PyVarObject_HEAD_INIT(NULL,0) | |||
.tp_name = (char *) "GnumericFunc", | .tp_name = "GnumericFunc", | |||
.tp_basicsize = sizeof (py_GnumericFunc_object), | .tp_basicsize = sizeof (py_GnumericFunc_object), | |||
.tp_dealloc = (destructor) &py_GnumericFunc_object_dealloc, | .tp_dealloc = (destructor) &py_GnumericFunc_object_dealloc, | |||
.tp_call = (ternaryfunc) py_GnumericFunc_call | .tp_call = (ternaryfunc) py_GnumericFunc_call | |||
}; | }; | |||
/* | /* | |||
* GnumericFuncDict | * GnumericFuncDict | |||
*/ | */ | |||
struct _py_GnumericFuncDict_object { | struct _py_GnumericFuncDict_object { | |||
PyObject_HEAD | PyObject_HEAD | |||
PyObject *module_dict; | // PyObject *module_dict; | |||
}; | }; | |||
static PyObject * | static PyObject * | |||
py_GnumericFuncDict_subscript (py_GnumericFuncDict_object *self, PyObject *key) | py_GnumericFuncDict_subscript (py_GnumericFuncDict_object *self, PyObject *key) | |||
{ | { | |||
gchar *fn_name; | gchar *fn_name; | |||
GnmFunc *fn_def; | GnmFunc *fn_def; | |||
if (!PyArg_Parse(key, (char *) "s", &fn_name)) { | if (!PyArg_Parse(key, "s", &fn_name)) { | |||
return NULL; | return NULL; | |||
} | } | |||
fn_def = gnm_func_lookup (fn_name, NULL); | fn_def = gnm_func_lookup (fn_name, NULL); | |||
if (fn_def == NULL) { | if (fn_def == NULL) { | |||
/* Py_INCREF (key); FIXME?? */ | /* Py_INCREF (key); FIXME?? */ | |||
PyErr_SetObject (PyExc_KeyError, key); | PyErr_SetObject (PyExc_KeyError, key); | |||
return NULL; | return NULL; | |||
} | } | |||
skipping to change at line 685 | skipping to change at line 637 | |||
static void | static void | |||
py_GnumericFuncDict_object_dealloc (py_GnumericFuncDict_object *self) | py_GnumericFuncDict_object_dealloc (py_GnumericFuncDict_object *self) | |||
{ | { | |||
PyObject_Del (self); | PyObject_Del (self); | |||
} | } | |||
static PyObject * | static PyObject * | |||
py_new_GnumericFuncDict_object (PyObject *module_dict) | py_new_GnumericFuncDict_object (PyObject *module_dict) | |||
{ | { | |||
py_GnumericFuncDict_object *self; | return (PyObject*) PyObject_NEW (py_GnumericFuncDict_object, &py_Gnumeric | |||
FuncDict_object_type); | ||||
self = PyObject_NEW (py_GnumericFuncDict_object, &py_GnumericFuncDict_obj | ||||
ect_type); | ||||
if (self == NULL) { | ||||
return NULL; | ||||
} | ||||
self->module_dict = module_dict; | ||||
return (PyObject *) self; | ||||
} | } | |||
PyMappingMethods py_GnumericFuncDict_mapping_methods = { | PyMappingMethods py_GnumericFuncDict_mapping_methods = { | |||
0, /* mp_length */ | .mp_length = NULL, | |||
(binaryfunc) py_GnumericFuncDict_subscript, /* mp_subscript */ | .mp_subscript = (binaryfunc) py_GnumericFuncDict_subscript, | |||
0 /* mp_ass_subscript */ | .mp_ass_subscript = NULL | |||
}; | }; | |||
static PyTypeObject py_GnumericFuncDict_object_type = { | static PyTypeObject py_GnumericFuncDict_object_type = { | |||
PyVarObject_HEAD_INIT(NULL, 0) | PyVarObject_HEAD_INIT(NULL, 0) | |||
.tp_name = (char *) "GnumericFuncDict", | .tp_name = "GnumericFuncDict", | |||
.tp_basicsize = sizeof (py_GnumericFuncDict_object), | .tp_basicsize = sizeof (py_GnumericFuncDict_object), | |||
.tp_dealloc = (destructor) &py_GnumericFuncDict_object_dealloc, | .tp_dealloc = (destructor) &py_GnumericFuncDict_object_dealloc, | |||
.tp_as_mapping = &py_GnumericFuncDict_mapping_methods | .tp_as_mapping = &py_GnumericFuncDict_mapping_methods | |||
}; | }; | |||
/* | /* | |||
- * GOPlugin | - * GOPlugin | |||
*/ | */ | |||
struct _py_GnmPlugin_object { | struct _py_GnmPlugin_object { | |||
skipping to change at line 730 | skipping to change at line 673 | |||
static PyObject * | static PyObject * | |||
py_GnmPlugin_get_dir_name_method (py_GnmPlugin_object *self, PyObject *args); | py_GnmPlugin_get_dir_name_method (py_GnmPlugin_object *self, PyObject *args); | |||
static PyObject * | static PyObject * | |||
py_GnmPlugin_get_id_method (py_GnmPlugin_object *self, PyObject *args); | py_GnmPlugin_get_id_method (py_GnmPlugin_object *self, PyObject *args); | |||
static PyObject * | static PyObject * | |||
py_GnmPlugin_get_name_method (py_GnmPlugin_object *self, PyObject *args); | py_GnmPlugin_get_name_method (py_GnmPlugin_object *self, PyObject *args); | |||
static PyObject * | static PyObject * | |||
py_GnmPlugin_get_description_method (py_GnmPlugin_object *self, PyObject *args); | py_GnmPlugin_get_description_method (py_GnmPlugin_object *self, PyObject *args); | |||
static struct PyMethodDef py_GnmPlugin_object_methods[] = { | static struct PyMethodDef py_GnmPlugin_object_methods[] = { | |||
{(char *) "get_dir_name", | {"get_dir_name", | |||
(PyCFunction) py_GnmPlugin_get_dir_name_method, METH_VARARGS}, | (PyCFunction) py_GnmPlugin_get_dir_name_method, METH_VARARGS}, | |||
{(char *) "get_id", | {"get_id", | |||
(PyCFunction) py_GnmPlugin_get_id_method, METH_VARARGS}, | (PyCFunction) py_GnmPlugin_get_id_method, METH_VARARGS}, | |||
{(char *) "get_name", | {"get_name", | |||
(PyCFunction) py_GnmPlugin_get_name_method, METH_VARARGS}, | (PyCFunction) py_GnmPlugin_get_name_method, METH_VARARGS}, | |||
{(char *) "get_description", | {"get_description", | |||
(PyCFunction) py_GnmPlugin_get_description_method, METH_VARARGS}, | (PyCFunction) py_GnmPlugin_get_description_method, METH_VARARGS}, | |||
{NULL, NULL} | {NULL, NULL} | |||
}; | }; | |||
static PyObject * | static PyObject * | |||
py_GnmPlugin_get_dir_name_method (py_GnmPlugin_object *self, PyObject *args) | py_GnmPlugin_get_dir_name_method (py_GnmPlugin_object *self, PyObject *args) | |||
{ | { | |||
if (!PyArg_ParseTuple (args, (char *) ":get_dir_name")) { | if (!PyArg_ParseTuple (args, ":get_dir_name")) { | |||
return NULL; | return NULL; | |||
} | } | |||
return PyUnicode_FromString (go_plugin_get_dir_name (self->pinfo)); | return PyUnicode_FromString (go_plugin_get_dir_name (self->pinfo)); | |||
} | } | |||
static PyObject * | static PyObject * | |||
py_GnmPlugin_get_id_method (py_GnmPlugin_object *self, PyObject *args) | py_GnmPlugin_get_id_method (py_GnmPlugin_object *self, PyObject *args) | |||
{ | { | |||
if (!PyArg_ParseTuple (args, (char *) ":get_id")) { | if (!PyArg_ParseTuple (args, ":get_id")) { | |||
return NULL; | return NULL; | |||
} | } | |||
return PyUnicode_FromString (go_plugin_get_id (self->pinfo)); | return PyUnicode_FromString (go_plugin_get_id (self->pinfo)); | |||
} | } | |||
static PyObject * | static PyObject * | |||
py_GnmPlugin_get_name_method (py_GnmPlugin_object *self, PyObject *args) | py_GnmPlugin_get_name_method (py_GnmPlugin_object *self, PyObject *args) | |||
{ | { | |||
if (!PyArg_ParseTuple (args, (char *) ":get_name")) { | if (!PyArg_ParseTuple (args, ":get_name")) { | |||
return NULL; | return NULL; | |||
} | } | |||
return PyUnicode_FromString (go_plugin_get_name (self->pinfo)); | return PyUnicode_FromString (go_plugin_get_name (self->pinfo)); | |||
} | } | |||
static PyObject * | static PyObject * | |||
py_GnmPlugin_get_description_method (py_GnmPlugin_object *self, PyObject *args) | py_GnmPlugin_get_description_method (py_GnmPlugin_object *self, PyObject *args) | |||
{ | { | |||
if (!PyArg_ParseTuple (args, (char *) ":get_description")) { | if (!PyArg_ParseTuple (args, ":get_description")) { | |||
return NULL; | return NULL; | |||
} | } | |||
return PyUnicode_FromString (go_plugin_get_description (self->pinfo)); | return PyUnicode_FromString (go_plugin_get_description (self->pinfo)); | |||
} | } | |||
#if 0 | #if 0 | |||
static GOPlugin * | static GOPlugin * | |||
py_GnmPlugin_as_GnmPlugin (py_GnmPlugin_object *self) | py_GnmPlugin_as_GnmPlugin (py_GnmPlugin_object *self) | |||
{ | { | |||
skipping to change at line 821 | skipping to change at line 764 | |||
return NULL; | return NULL; | |||
} | } | |||
self->pinfo = pinfo; | self->pinfo = pinfo; | |||
g_object_ref (self->pinfo); | g_object_ref (self->pinfo); | |||
return (PyObject *) self; | return (PyObject *) self; | |||
} | } | |||
static PyTypeObject py_GnmPlugin_object_type = { | static PyTypeObject py_GnmPlugin_object_type = { | |||
PyVarObject_HEAD_INIT(&PyType_Type, 0) | PyVarObject_HEAD_INIT(&PyType_Type, 0) | |||
.tp_name = (char *) "GOPlugin", | .tp_name = "GOPlugin", | |||
.tp_basicsize = sizeof (py_GnmPlugin_object), | .tp_basicsize = sizeof (py_GnmPlugin_object), | |||
.tp_dealloc = (destructor) &py_GnmPlugin_object_dealloc, | .tp_dealloc = (destructor) &py_GnmPlugin_object_dealloc, | |||
.tp_getattr = (getattrfunc) &py_GnmPlugin_object_getattr, | .tp_getattr = (getattrfunc) &py_GnmPlugin_object_getattr, | |||
.tp_methods = py_GnmPlugin_object_methods | .tp_methods = py_GnmPlugin_object_methods | |||
}; | }; | |||
static void | static void | |||
init_err (PyObject *module_dict, const char *name, GnmStdError e) | init_err (PyObject *module_dict, const char *name, GnmStdError e) | |||
{ | { | |||
GnmValue *v = value_new_error_std (NULL, e); | GnmValue *v = value_new_error_std (NULL, e); | |||
PyDict_SetItemString | gnm_py_dict_store | |||
(module_dict, (char *)name, | (module_dict, name, | |||
PyUnicode_FromString (v->v_err.mesg->str)); | PyUnicode_FromString (v->v_err.mesg->str)); | |||
value_release (v); | value_release (v); | |||
} | } | |||
PyObject * | PyObject * | |||
py_initgnumeric () | py_initgnumeric (void) | |||
{ | { | |||
PyObject *module_dict; | PyObject *module_dict; | |||
static struct PyModuleDef GnmModuleDef = { | static struct PyModuleDef GnmModuleDef = { | |||
PyModuleDef_HEAD_INIT, /* m_base */ | PyModuleDef_HEAD_INIT, /* m_base */ | |||
(char *) "Gnumeric", /* m_name */ | .m_name = "Gnumeric", | |||
0, /* m_doc */ | ||||
0, /* m_ size */ | ||||
0, /* m_methods */ | ||||
0, /* m_reload */ | ||||
0, /* m_traverse */ | ||||
0, /* m_clear */ | ||||
0, /* m_free */ | ||||
}; | }; | |||
if (GnmModule) | if (GnmModule) | |||
return GnmModule; | return GnmModule; | |||
GnmModule = PyModule_Create (&GnmModuleDef); | GnmModule = PyModule_Create (&GnmModuleDef); | |||
module_dict = PyModule_GetDict (GnmModule); | module_dict = PyModule_GetDict (GnmModule); | |||
(void) PyDict_SetItemString | // For historical reasons. New code use python True/False. | |||
(module_dict, (char *) "TRUE", py_new_Boolean_object (TRUE)); | gnm_py_dict_store (module_dict, "TRUE", PyBool_FromLong (TRUE)); | |||
(void) PyDict_SetItemString | gnm_py_dict_store (module_dict, "FALSE", PyBool_FromLong (FALSE)); | |||
(module_dict, (char *) "FALSE", py_new_Boolean_object (FALSE)); | ||||
gnm_py_dict_store | ||||
(void) PyDict_SetItemString | (module_dict, "GnumericError", | |||
(module_dict, (char *) "GnumericError", | PyErr_NewException ("Gnumeric.GnumericError", | |||
PyErr_NewException ((char *) "Gnumeric.GnumericError", | ||||
NULL, NULL)); | NULL, NULL)); | |||
init_err (module_dict, "GnumericErrorNULL", GNM_ERROR_NULL); | init_err (module_dict, "GnumericErrorNULL", GNM_ERROR_NULL); | |||
init_err (module_dict, "GnumericErrorDIV0", GNM_ERROR_DIV0); | init_err (module_dict, "GnumericErrorDIV0", GNM_ERROR_DIV0); | |||
init_err (module_dict, "GnumericErrorVALUE", GNM_ERROR_VALUE); | init_err (module_dict, "GnumericErrorVALUE", GNM_ERROR_VALUE); | |||
init_err (module_dict, "GnumericErrorREF", GNM_ERROR_REF); | init_err (module_dict, "GnumericErrorREF", GNM_ERROR_REF); | |||
init_err (module_dict, "GnumericErrorNAME", GNM_ERROR_NAME); | init_err (module_dict, "GnumericErrorNAME", GNM_ERROR_NAME); | |||
init_err (module_dict, "GnumericErrorNUM", GNM_ERROR_NUM); | init_err (module_dict, "GnumericErrorNUM", GNM_ERROR_NUM); | |||
init_err (module_dict, "GnumericErrorNA", GNM_ERROR_NA); | init_err (module_dict, "GnumericErrorNA", GNM_ERROR_NA); | |||
(void) PyDict_SetItemString | gnm_py_dict_store | |||
(module_dict, (char *) "functions", | (module_dict, "functions", | |||
py_new_GnumericFuncDict_object (module_dict)); | py_new_GnumericFuncDict_object (module_dict)); | |||
return GnmModule; | return GnmModule; | |||
} | } | |||
void | void | |||
py_gnumeric_shutdown (void) | ||||
{ | ||||
if (GnmModule) { | ||||
// At least clear the module. We leak a ref somewhere. | ||||
PyDict_Clear (PyModule_GetDict (GnmModule)); | ||||
Py_CLEAR (GnmModule); | ||||
} | ||||
} | ||||
void | ||||
py_gnumeric_add_plugin (PyObject *module, GnmPyInterpreter *interpreter) | py_gnumeric_add_plugin (PyObject *module, GnmPyInterpreter *interpreter) | |||
{ | { | |||
PyObject *module_dict, *py_pinfo; | PyObject *module_dict, *py_pinfo; | |||
GOPlugin *pinfo; | GOPlugin *pinfo; | |||
char *key, *name; | char *key, *name; | |||
int i; | int i; | |||
module_dict = PyModule_GetDict (module); | module_dict = PyModule_GetDict (module); | |||
pinfo = gnm_py_interpreter_get_plugin (interpreter); | pinfo = gnm_py_interpreter_get_plugin (interpreter); | |||
g_return_if_fail (pinfo); | g_return_if_fail (pinfo); | |||
name = g_strdup (go_plugin_get_name (pinfo)); | name = g_strdup (go_plugin_get_name (pinfo)); | |||
i = strlen (name); | i = strlen (name); | |||
while (i > 0) | while (i > 0) | |||
if (name[--i] == ' ') | if (name[--i] == ' ') | |||
name[i] = '_'; | name[i] = '_'; | |||
key = g_strconcat ("plugin_", name, "_info", NULL); | key = g_strconcat ("plugin_", name, "_info", NULL); | |||
py_pinfo = py_new_GnmPlugin_object (pinfo); | py_pinfo = py_new_GnmPlugin_object (pinfo); | |||
(void) PyDict_SetItemString (module_dict, key, py_pinfo); | gnm_py_dict_store (module_dict, key, py_pinfo); | |||
g_free (name); | g_free (name); | |||
g_free (key); | g_free (key); | |||
} | } | |||
End of changes. 41 change blocks. | ||||
124 lines changed or deleted | 68 lines changed or added |