Do not export a variable, use a function instead

This commit is contained in:
Yevgen Muntyan 2008-01-18 12:05:06 -06:00
parent e769201d51
commit 2784c609e0
2 changed files with 48 additions and 42 deletions

View File

@ -17,11 +17,11 @@
G_BEGIN_DECLS
#define MOO_PY_API_VERSION 94
#define MOO_PY_API_VERSION 95
typedef struct _MooPyAPI MooPyAPI;
typedef struct _MooPyObject MooPyObject;
typedef struct _MooPyMethodDef MooPyMethodDef;
typedef struct MooPyAPI MooPyAPI;
typedef struct MooPyObject MooPyObject;
typedef struct MooPyMethodDef MooPyMethodDef;
typedef MooPyObject* (*MooPyCFunction) (MooPyObject*, MooPyObject*);
@ -41,14 +41,14 @@ enum {
MOO_PY_NOT_IMPLEMENTED_ERROR
};
struct _MooPyMethodDef {
struct MooPyMethodDef {
const char *ml_name;
MooPyCFunction ml_meth;
int ml_flags;
const char *ml_doc;
};
struct _MooPyAPI {
struct MooPyAPI {
MooPyObject *py_none;
MooPyObject *py_true;
MooPyObject *py_false;
@ -109,7 +109,7 @@ struct _MooPyAPI {
};
extern MooPyAPI *moo_py_api;
MooPyAPI *moo_py_api_ (void);
gboolean moo_python_init (guint version,
MooPyAPI *api);
@ -119,35 +119,35 @@ void moo_python_add_data (gpointer data,
MooPyObject *moo_Py_INCREF (MooPyObject *obj);
void moo_Py_DECREF (MooPyObject *obj);
#define moo_python_running() (moo_py_api != NULL)
#define moo_python_running() (moo_py_api_() != NULL)
#define moo_python_get_info moo_py_api->get_info
#define moo_python_get_info moo_py_api_()->get_info
#define moo_python_run_simple_string moo_py_api->run_simple_string
#define moo_python_run_string moo_py_api->run_string
#define moo_python_run_file moo_py_api->run_file
#define moo_python_run_code moo_py_api->run_code
#define moo_python_create_script_dict moo_py_api->create_script_dict
#define moo_python_run_simple_string moo_py_api_()->run_simple_string
#define moo_python_run_string moo_py_api_()->run_string
#define moo_python_run_file moo_py_api_()->run_file
#define moo_python_run_code moo_py_api_()->run_code
#define moo_python_create_script_dict moo_py_api_()->create_script_dict
#define moo_py_dict_get_item moo_py_api->dict_get_item
#define moo_py_dict_set_item moo_py_api->dict_set_item
#define moo_py_dict_del_item moo_py_api->dict_del_item
#define moo_py_dict_get_item moo_py_api_()->dict_get_item
#define moo_py_dict_set_item moo_py_api_()->dict_set_item
#define moo_py_dict_del_item moo_py_api_()->dict_del_item
#define moo_py_import_exec moo_py_api->import_exec
#define moo_py_object_from_gobject moo_py_api->py_object_from_gobject
#define moo_gobject_from_py_object moo_py_api->gobject_from_py_object
#define moo_py_import_exec moo_py_api_()->import_exec
#define moo_py_object_from_gobject moo_py_api_()->py_object_from_gobject
#define moo_gobject_from_py_object moo_py_api_()->gobject_from_py_object
#define moo_py_set_error moo_py_api->set_error
#define moo_py_set_error moo_py_api_()->set_error
#define moo_PyErr_Print moo_py_api->py_err_print
#define moo_PyObject_CallMethod moo_py_api->py_object_call_method
#define moo_PyObject_CallFunction moo_py_api->py_object_call_function
#define moo_PyCFunction_New moo_py_api->py_c_function_new
#define moo_PyModule_AddObject moo_py_api->py_module_add_object
#define moo_PyArg_ParseTuple moo_py_api->py_arg_parse_tuple
#define moo_Py_None moo_py_api->py_none
#define moo_Py_True moo_py_api->py_true
#define moo_Py_False moo_py_api->py_false
#define moo_PyErr_Print moo_py_api_()->py_err_print
#define moo_PyObject_CallMethod moo_py_api_()->py_object_call_method
#define moo_PyObject_CallFunction moo_py_api_()->py_object_call_function
#define moo_PyCFunction_New moo_py_api_()->py_c_function_new
#define moo_PyModule_AddObject moo_py_api_()->py_module_add_object
#define moo_PyArg_ParseTuple moo_py_api_()->py_arg_parse_tuple
#define moo_Py_None moo_py_api_()->py_none
#define moo_Py_True moo_py_api_()->py_true
#define moo_Py_False moo_py_api_()->py_false
G_END_DECLS

View File

@ -23,7 +23,13 @@ typedef struct {
GDestroyNotify destroy;
} Data;
MooPyAPI *moo_py_api = NULL;
static MooPyAPI *moo_py_api_var = NULL;
MooPyAPI *
moo_py_api_ (void)
{
return moo_py_api_var;
}
void
@ -32,13 +38,13 @@ moo_python_add_data (gpointer data,
{
Data *d;
g_return_if_fail (moo_py_api != NULL);
g_return_if_fail (moo_py_api_var != NULL);
g_return_if_fail (destroy != NULL);
d = g_new (Data, 1);
d->data = data;
d->destroy = destroy;
moo_py_api->_free_list = g_slist_prepend (moo_py_api->_free_list, d);
moo_py_api_var->_free_list = g_slist_prepend (moo_py_api_var->_free_list, d);
}
static void
@ -59,18 +65,18 @@ moo_python_init (guint version,
if (version != MOO_PY_API_VERSION)
return FALSE;
g_return_val_if_fail (!moo_py_api || !api, FALSE);
g_return_val_if_fail (!moo_py_api_var || !api, FALSE);
if (moo_py_api)
if (moo_py_api_var)
{
g_slist_foreach (moo_py_api->_free_list, (GFunc) data_free, NULL);
g_slist_free (moo_py_api->_free_list);
g_slist_foreach (moo_py_api_var->_free_list, (GFunc) data_free, NULL);
g_slist_free (moo_py_api_var->_free_list);
}
moo_py_api = api;
moo_py_api_var = api;
if (moo_py_api)
moo_py_api->_free_list = NULL;
if (moo_py_api_var)
moo_py_api_var->_free_list = NULL;
return TRUE;
}
@ -82,7 +88,7 @@ moo_Py_INCREF (MooPyObject *obj)
g_return_val_if_fail (moo_python_running (), obj);
if (obj)
moo_py_api->incref (obj);
moo_py_api_var->incref (obj);
return obj;
}
@ -94,7 +100,7 @@ moo_Py_DECREF (MooPyObject *obj)
g_return_if_fail (moo_python_running ());
if (obj)
moo_py_api->decref (obj);
moo_py_api_var->decref (obj);
}