diff options
author | James Henstridge <james@daa.com.au> | 2000-06-29 01:15:21 +0000 |
---|---|---|
committer | James Henstridge <jamesh@src.gnome.org> | 2000-06-29 01:15:21 +0000 |
commit | 4e62c6450844aa49430fa450ce555370cb43dedb (patch) | |
tree | 67c8bd684a01a62f371d5e0f4217d7d77698a3aa | |
parent | 3b4003c57752d3d2d1386287c696f5a60d22aa1b (diff) | |
download | pygobject-4e62c6450844aa49430fa450ce555370cb43dedb.tar.gz pygobject-4e62c6450844aa49430fa450ce555370cb43dedb.tar.xz pygobject-4e62c6450844aa49430fa450ce555370cb43dedb.zip |
use pygobject.h.
2000-06-29 James Henstridge <james@daa.com.au>
* gobjectmodule.c: use pygobject.h.
* pygobject.h: header for modules that want to use GObject.
-rw-r--r-- | gobject/gobjectmodule.c | 30 | ||||
-rw-r--r-- | gobject/pygobject.h | 69 |
2 files changed, 86 insertions, 13 deletions
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c index acdd1d5..43f5792 100644 --- a/gobject/gobjectmodule.c +++ b/gobject/gobjectmodule.c @@ -1,25 +1,14 @@ /* -*- Mode: C; c-basic-offset: 4 -*- */ -#include <glib.h> -#include <gobject/gobject.h> +#define _INSIDE_PYGOBJECT_ +#include "pygobject.h" #include <gobject/gvaluetypes.h> #include <gobject/genums.h> -#include <Python.h> -#include "ExtensionClass.h" static GHashTable *class_hash; static GQuark pygobject_wrapper_key = 0; static GQuark pygobject_ownedref_key = 0; -typedef struct { - PyObject_HEAD - GObject *obj; - gboolean hasref; /* the GObject owns this reference */ - PyObject *inst_dict; /* the instance dictionary -- must be last */ -} PyGObject; - -#define pygobject_get(v) (((PyGObject *)v)->obj) - staticforward PyExtensionClass PyGObject_Type; static void pygobject_dealloc(PyGObject *self); static PyObject *pygobject_getattr(PyGObject *self, char *attr); @@ -625,6 +614,17 @@ static PyMethodDef pygobject_functions[] = { /* ----------------- gobject module initialisation -------------- */ +static struct _PyGObject_Functions functions = { + pygobject_register_class, + pygobject_register_wrapper, + pygobject_lookup_class, + pygobject_new, + pyg_enum_get_value, + pyg_flags_get_value, + pyg_value_from_pyobject, + pyg_value_as_pyobject, +}; + DL_EXPORT(void) initgobject(void) { @@ -639,6 +639,10 @@ initgobject(void) pygobject_wrapper_key = g_quark_from_static_string("py-gobject-wrapper"); pygobject_ownedref_key = g_quark_from_static_string("py-gobject-ownedref"); + /* for addon libraries ... */ + PyDict_SetItemString(d, "_PyGObject_API", + PyCObject_FromVoidPtr(&functions, NULL)); + if (PyErr_Occurred()) Py_FatalError("can't initialise module gobject"); } diff --git a/gobject/pygobject.h b/gobject/pygobject.h new file mode 100644 index 0000000..fae23a9 --- /dev/null +++ b/gobject/pygobject.h @@ -0,0 +1,69 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- */ +#ifndef _PYGOBJECT_H_ +#define _PYGOBJECT_H_ + +#include <Python.h> +#include <ExtensionClass.h> + +#include <glib.h> +#include <gobject/gobject.h> + +typedef struct { + PyObject_HEAD + GObject *obj; + gboolean hasref; /* the GObject owns this reference */ + PyObject *inst_dict; /* the instance dictionary -- must be last */ +} PyGObject; + +#define pygobject_get(v) (((PyGObject *)v)->obj) + +struct _PyGObject_Functions { + void (* register_class)(PyObject *dict, const gchar *class_name, + PyExtensionClass *ec, PyExtensionClass *parent); + void (* register_wrapper)(PyObject *self); + PyExtensionClass *(* lookup_class)(GType type); + PyObject *(* new)(GObject *obj); + gint (* enum_get_value)(GType enum_type, PyObject *obj, gint *val); + gint (* flags_get_value)(GType flag_type, PyObject *obj, gint *val); + int (* value_from_pyobject)(GValue *value, PyObject *obj); + PyObject *(* value_as_pyobject)(GValue *value); +}; + +#ifndef _INSIDE_PYGOBJECT_ + +#if defined(NO_IMPORT) || defined(NO_IMPORT_PYGOBJECT) +extern struct _PyGObject_Functions *_PyGObject_API; +#else +struct _PyGObject_Functions *_PyGObject_API; +#endif + +#define pygobject_register_class (_PyGObject_API->register_class) +#define pygobject_register_wrapper (_PyGObject_API->register_wrapper) +#define pygobject_lookup_class (_PyGObject_API->lookup_class) +#define pygobject_new (_PyGObject_API->new) +#define pyg_enum_get_value (_PyGObject_API->enum_get_value) +#define pyg_flags_get_value (_PyGObject_API->flags_get_value) +#define pyg_value_from_pyobject (_PyGObject_API->value_from_pyobject) +#define pyg_value_as_pyobject (_PyGObject_API->value_as_pyobject) + +#define init_pygobject() { \ + PyObject *gobject = PyImport_ImportModule("gobject"); \ + if (gobject != NULL) { \ + PyObject *mdict = PyModule_GetDict(gobject); \ + PyObject *cobject = PyDict_GetItemString(mdict, "_PyGObject_API"); \ + if (PyCObject_Check(cobject)) \ + _PyGObject_API = PyCObject_AsVoidPtr(cobject); \ + else { \ + Py_FatalException("could not find _PyGObject_API object"); \ + return; \ + } \ + } else { \ + Py_FatalException("could not import gobject"); \ + return; \ + } \ + ExtensionClassImported; \ +} + +#endif /* !_INSIDE_PYGOBJECT_ */ + +#endif /* !_PYGOBJECT_H_ */ |