diff options
| author | Johan Dahlin <johan@gnome.org> | 2008-07-27 09:35:57 +0000 |
|---|---|---|
| committer | Johan Dahlin <johan@src.gnome.org> | 2008-07-27 09:35:57 +0000 |
| commit | 5ffb6e17bf5ea51abe9c9f440e7cfdd8920d143a (patch) | |
| tree | 869b1650717b1dac5490aa889683f01ecc0479ea /gobject | |
| parent | 2c1fecd16f1cc8943455cf3d573cf441162a8969 (diff) | |
| download | pygobject-5ffb6e17bf5ea51abe9c9f440e7cfdd8920d143a.tar.gz pygobject-5ffb6e17bf5ea51abe9c9f440e7cfdd8920d143a.tar.xz pygobject-5ffb6e17bf5ea51abe9c9f440e7cfdd8920d143a.zip | |
Use PYGLIB_DEFINE_TYPE macro and move struct field initialization to the
2008-07-27 Johan Dahlin <johan@gnome.org>
* gobject/pygboxed.c (pygobject_boxed_register_types):
* gobject/pygenum.c (pygobject_enum_register_types):
* gobject/pygflags.c (pygobject_flags_register_types):
* gobject/pygobject.c (pygobject_object_register_types):
* gobject/pygparamspec.c (pygobject_paramspec_register_types):
* gobject/pygpointer.c (pygobject_pointer_register_types):
* gobject/pygtype.c (pygobject_type_register_types):
Use PYGLIB_DEFINE_TYPE macro and move struct field initialization
to the registration methods.
svn path=/trunk/; revision=883
Diffstat (limited to 'gobject')
| -rw-r--r-- | gobject/pygboxed.c | 60 | ||||
| -rw-r--r-- | gobject/pygenum.c | 51 | ||||
| -rw-r--r-- | gobject/pygflags.c | 51 | ||||
| -rw-r--r-- | gobject/pygobject.c | 282 | ||||
| -rw-r--r-- | gobject/pygparamspec.c | 32 | ||||
| -rw-r--r-- | gobject/pygpointer.c | 56 | ||||
| -rw-r--r-- | gobject/pygtype.c | 94 |
7 files changed, 130 insertions, 496 deletions
diff --git a/gobject/pygboxed.c b/gobject/pygboxed.c index bf3d691..bf41fb8 100644 --- a/gobject/pygboxed.c +++ b/gobject/pygboxed.c @@ -31,6 +31,8 @@ GQuark pygboxed_type_key; GQuark pygboxed_marshal_key; +PYGLIB_DEFINE_TYPE("gobject.GBoxed", PyGBoxed_Type, PyGBoxed); + static void pyg_boxed_dealloc(PyGBoxed *self) { @@ -104,54 +106,6 @@ static PyMethodDef pygboxed_methods[] = { }; - -PyTypeObject PyGBoxed_Type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - "gobject.GBoxed", /* tp_name */ - sizeof(PyGBoxed), /* tp_basicsize */ - 0, /* tp_itemsize */ - /* methods */ - (destructor)pyg_boxed_dealloc, /* tp_dealloc */ - (printfunc)0, /* tp_print */ - (getattrfunc)0, /* tp_getattr */ - (setattrfunc)0, /* tp_setattr */ - (cmpfunc)pyg_boxed_compare, /* tp_compare */ - (reprfunc)pyg_boxed_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - (hashfunc)pyg_boxed_hash, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)0, /* tp_str */ - (getattrofunc)0, /* tp_getattro */ - (setattrofunc)0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - NULL, /* Documentation string */ - (traverseproc)0, /* tp_traverse */ - (inquiry)0, /* tp_clear */ - (richcmpfunc)0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)0, /* tp_iter */ - (iternextfunc)0, /* tp_iternext */ - pygboxed_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - (PyTypeObject *)0, /* tp_base */ - (PyObject *)0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)pyg_boxed_init, /* tp_init */ - (allocfunc)0, /* tp_alloc */ - (newfunc)0, /* tp_new */ - (freefunc)pyg_boxed_free, /* tp_free */ - (inquiry)0, /* tp_is_gc */ - (PyObject *)0, /* tp_bases */ -}; - - /** * pyg_register_boxed: * @dict: the module dictionary to store the wrapper class. @@ -253,6 +207,14 @@ pygobject_boxed_register_types(PyObject *d) pygboxed_type_key = g_quark_from_static_string("PyGBoxed::class"); pygboxed_marshal_key = g_quark_from_static_string("PyGBoxed::marshal"); + PyGBoxed_Type.tp_dealloc = (destructor)pyg_boxed_dealloc; + PyGBoxed_Type.tp_compare = (cmpfunc)pyg_boxed_compare; + PyGBoxed_Type.tp_repr = (reprfunc)pyg_boxed_repr; + PyGBoxed_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + PyGBoxed_Type.tp_methods = pygboxed_methods; + PyGBoxed_Type.tp_init = (initproc)pyg_boxed_init; + PyGBoxed_Type.tp_free = (freefunc)pyg_boxed_free; + PyGBoxed_Type.tp_hash = (hashfunc)pyg_boxed_hash; + PYGOBJECT_REGISTER_GTYPE(d, PyGBoxed_Type, "GBoxed", G_TYPE_BOXED); - } diff --git a/gobject/pygenum.c b/gobject/pygenum.c index c7ecd76..fadb7cf 100644 --- a/gobject/pygenum.c +++ b/gobject/pygenum.c @@ -30,6 +30,8 @@ GQuark pygenum_class_key; +PYGLIB_DEFINE_TYPE("gobject.GEnum", PyGEnum_Type, PyGEnum); + static PyObject * pyg_enum_richcompare(PyGEnum *self, PyObject *other, int op) { @@ -320,54 +322,19 @@ static PyGetSetDef pyg_enum_getsets[] = { { NULL, 0, 0 } }; -PyTypeObject PyGEnum_Type = { - PyObject_HEAD_INIT(NULL) - 0, - "gobject.GEnum", - sizeof(PyGEnum), - 0, - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - (reprfunc)pyg_enum_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - (reprfunc)pyg_enum_repr, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - 0, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - (richcmpfunc)pyg_enum_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - pyg_enum_methods, /* tp_methods */ - 0, /* tp_members */ - pyg_enum_getsets, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - pyg_enum_new, /* tp_new */ -}; - void pygobject_enum_register_types(PyObject *d) { pygenum_class_key = g_quark_from_static_string("PyGEnum::class"); PyGEnum_Type.tp_base = &PyInt_Type; + PyGEnum_Type.tp_repr = (reprfunc)pyg_enum_repr; + PyGEnum_Type.tp_str = (reprfunc)pyg_enum_repr; + PyGEnum_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + PyGEnum_Type.tp_richcompare = (richcmpfunc)pyg_enum_richcompare; + PyGEnum_Type.tp_methods = pyg_enum_methods; + PyGEnum_Type.tp_getset = pyg_enum_getsets; + PyGEnum_Type.tp_new = pyg_enum_new; PYGOBJECT_REGISTER_GTYPE(d, PyGEnum_Type, "GEnum", G_TYPE_ENUM); } diff --git a/gobject/pygflags.c b/gobject/pygflags.c index 0085560..3108378 100644 --- a/gobject/pygflags.c +++ b/gobject/pygflags.c @@ -31,6 +31,8 @@ GQuark pygflags_class_key; +PYGLIB_DEFINE_TYPE("gobject.GFlags", PyGFlags_Type, PyGFlags); + #define GET_INT_VALUE(x) (((PyIntObject*)x)->ob_ival) static PyObject * @@ -459,53 +461,18 @@ static PyNumberMethods pyg_flags_as_number = { 0, /* nb_inplace_true_divide */ }; -PyTypeObject PyGFlags_Type = { - PyObject_HEAD_INIT(NULL) - 0, - "gobject.GFlags", - sizeof(PyGFlags), - 0, - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - (reprfunc)pyg_flags_repr, /* tp_repr */ - &pyg_flags_as_number, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - (reprfunc)pyg_flags_repr, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - 0, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - (richcmpfunc)pyg_flags_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - pyg_flags_getsets, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - pyg_flags_new, /* tp_new */ -}; - void pygobject_flags_register_types(PyObject *d) { pygflags_class_key = g_quark_from_static_string("PyGFlags::class"); PyGFlags_Type.tp_base = &PyInt_Type; + PyGFlags_Type.tp_repr = (reprfunc)pyg_flags_repr; + PyGFlags_Type.tp_as_number = &pyg_flags_as_number; + PyGFlags_Type.tp_str = (reprfunc)pyg_flags_repr; + PyGFlags_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + PyGFlags_Type.tp_richcompare = (richcmpfunc)pyg_flags_richcompare; + PyGFlags_Type.tp_getset = pyg_flags_getsets; + PyGFlags_Type.tp_new = pyg_flags_new; PYGOBJECT_REGISTER_GTYPE(d, PyGFlags_Type, "GFlags", G_TYPE_FLAGS); } diff --git a/gobject/pygobject.c b/gobject/pygobject.c index 31d048b..24fc4b2 100644 --- a/gobject/pygobject.c +++ b/gobject/pygobject.c @@ -39,6 +39,12 @@ static PyObject * pygobject_weak_ref_new(GObject *obj, PyObject *callback, PyObj static inline PyGObjectData * pyg_object_peek_inst_data(GObject *obj); static PyObject * pygobject_weak_ref_new(GObject *obj, PyObject *callback, PyObject *user_data); GType PY_TYPE_OBJECT = 0; +GQuark pygobject_class_key; +GQuark pygobject_class_init_key; +GQuark pygobject_wrapper_key; +GQuark pygobject_has_updated_constructor_key; +GQuark pygobject_instance_data_key; + /* -------------- class <-> wrapper manipulation --------------- */ @@ -174,6 +180,8 @@ typedef struct { guint index; } PyGPropsIter; +PYGLIB_DEFINE_TYPE("gobject.GPropsIter", PyGPropsIter_Type, PyGPropsIter); + static void pyg_props_iter_dealloc(PyGPropsIter *self) { @@ -192,38 +200,6 @@ pygobject_props_iter_next(PyGPropsIter *iter) } } - -PyTypeObject PyGPropsIter_Type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - "gobject.GPropsIter", /* tp_name */ - sizeof(PyGPropsIter), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)pyg_props_iter_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - "GObject properties iterator", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - (iternextfunc)pygobject_props_iter_next, /* tp_iternext */ -}; - typedef struct { PyObject_HEAD /* a reference to the object containing the properties */ @@ -355,6 +331,8 @@ set_property_from_pspec(GObject *obj, return TRUE; } +PYGLIB_DEFINE_TYPE("gobject.GProps", PyGProps_Type, PyGProps); + static int PyGProps_setattro(PyGProps *self, PyObject *attr, PyObject *pvalue) { @@ -437,38 +415,7 @@ static PySequenceMethods _PyGProps_as_sequence = { 0 }; -PyTypeObject PyGProps_Type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - "gobject.GProps", /* tp_name */ - sizeof(PyGProps), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)PyGProps_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - (PySequenceMethods*)&_PyGProps_as_sequence, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - (getattrofunc)PyGProps_getattro, /* tp_getattro */ - (setattrofunc)PyGProps_setattro, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC, /* tp_flags */ - "The properties of the GObject accessible as " - "Python attributes.", /* tp_doc */ - (traverseproc)pygobject_props_traverse, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)pygobject_props_get_iter, /* tp_iter */ - 0, /* tp_iternext */ -}; - +PYGLIB_DEFINE_TYPE("gobject.GPropsDescr", PyGPropsDescr_Type, 0); static PyObject * pyg_props_descr_descr_get(PyObject *self, PyObject *obj, PyObject *type) @@ -492,50 +439,6 @@ pyg_props_descr_descr_get(PyObject *self, PyObject *obj, PyObject *type) return (PyObject *) gprops; } -PyTypeObject PyGPropsDescr_Type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - "gobject.GPropsDescr", /* tp_name */ - 0, /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - 0, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - pyg_props_descr_descr_get, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0, /* tp_free */ -}; - - /** * pygobject_register_class: * @dict: the module dictionary. A reference to the type will be stored here. @@ -981,6 +884,8 @@ pygobject_watch_closure(PyObject *self, GClosure *closure) /* -------------- PyGObject behaviour ----------------- */ +PYGLIB_DEFINE_TYPE("gobject.GObject", PyGObject_Type, PyGObject); + static void pygobject_dealloc(PyGObject *self) { @@ -2065,57 +1970,9 @@ static PyGetSetDef pygobject_getsets[] = { { NULL, 0, 0 } }; -PyTypeObject PyGObject_Type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - "gobject.GObject", /* tp_name */ - sizeof(PyGObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - /* methods */ - (destructor)pygobject_dealloc, /* tp_dealloc */ - (printfunc)0, /* tp_print */ - (getattrfunc)0, /* tp_getattr */ - (setattrfunc)0, /* tp_setattr */ - (cmpfunc)pygobject_compare, /* tp_compare */ - (reprfunc)pygobject_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - (hashfunc)pygobject_hash, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)0, /* tp_str */ - (getattrofunc)0, /* tp_getattro */ - (setattrofunc)pygobject_setattro, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | - Py_TPFLAGS_HAVE_GC, /* tp_flags */ - NULL, /* Documentation string */ - (traverseproc)pygobject_traverse, /* tp_traverse */ - (inquiry)pygobject_clear, /* tp_clear */ - (richcmpfunc)0, /* tp_richcompare */ - offsetof(PyGObject, weakreflist), /* tp_weaklistoffset */ - (getiterfunc)0, /* tp_iter */ - (iternextfunc)0, /* tp_iternext */ - pygobject_methods, /* tp_methods */ - 0, /* tp_members */ - pygobject_getsets, /* tp_getset */ - (PyTypeObject *)0, /* tp_base */ - (PyObject *)0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - offsetof(PyGObject, inst_dict), /* tp_dictoffset */ - (initproc)pygobject_init, /* tp_init */ - (allocfunc)0, /* tp_alloc */ - (newfunc)0, /* tp_new */ - (freefunc)pygobject_free, /* tp_free */ - (inquiry)0, /* tp_is_gc */ - (PyObject *)0, /* tp_bases */ -}; - - - /* ------------------------------------ */ - /* ****** GObject weak reference ****** */ - /* ------------------------------------ */ +/* ------------------------------------ */ +/* ****** GObject weak reference ****** */ +/* ------------------------------------ */ typedef struct { PyObject_HEAD @@ -2125,6 +1982,8 @@ typedef struct { gboolean have_floating_ref; } PyGObjectWeakRef; +PYGLIB_DEFINE_TYPE("gobject.GObjectWeakRef", PyGObjectWeakRef_Type, PyGObjectWeakRef); + static int pygobject_weak_ref_traverse(PyGObjectWeakRef *self, visitproc visit, void *arg) { @@ -2242,51 +2101,6 @@ pygobject_weak_ref_call(PyGObjectWeakRef *self, PyObject *args, PyObject *kw) } } -PyTypeObject PyGObjectWeakRef_Type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - "gobject.GObjectWeakRef", /* tp_name */ - sizeof(PyGObjectWeakRef), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)pygobject_weak_ref_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)pygobject_weak_ref_call, /*tp_call*/ - 0, /* tp_str */ - (getattrofunc)0, /* tp_getattro */ - (setattrofunc)0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC, /* tp_flags */ - "A GObject weak reference", /* tp_doc */ - (traverseproc)pygobject_weak_ref_traverse, /* tp_traverse */ - (inquiry)pygobject_weak_ref_clear, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - pygobject_weak_ref_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - NULL, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0, /* tp_free */ - 0, /* tp_is_gc */ - NULL, /* tp_bases */ -}; - static gpointer pyobject_copy(gpointer boxed) { @@ -2307,12 +2121,6 @@ pyobject_free(gpointer boxed) pyglib_gil_state_release(state); } -GQuark pygobject_class_key; -GQuark pygobject_class_init_key; -GQuark pygobject_wrapper_key; -GQuark pygobject_has_updated_constructor_key; -GQuark pygobject_instance_data_key; - void pygobject_object_register_types(PyObject *d) { @@ -2325,11 +2133,26 @@ pygobject_object_register_types(PyObject *d) g_quark_from_static_string("PyGObject::has-updated-constructor"); pygobject_instance_data_key = g_quark_from_static_string("PyGObject::instance-data"); + /* GObject */ if (!PY_TYPE_OBJECT) PY_TYPE_OBJECT = g_boxed_type_register_static("PyObject", pyobject_copy, pyobject_free); - + PyGObject_Type.tp_dealloc = (destructor)pygobject_dealloc; + PyGObject_Type.tp_compare = (cmpfunc)pygobject_compare; + PyGObject_Type.tp_repr = (reprfunc)pygobject_repr; + PyGObject_Type.tp_hash = (hashfunc)pygobject_hash; + PyGObject_Type.tp_setattro = (setattrofunc)pygobject_setattro; + PyGObject_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | + Py_TPFLAGS_HAVE_GC); + PyGObject_Type.tp_traverse = (traverseproc)pygobject_traverse; + PyGObject_Type.tp_clear = (inquiry)pygobject_clear; + PyGObject_Type.tp_weaklistoffset = offsetof(PyGObject, weakreflist); + PyGObject_Type.tp_methods = pygobject_methods; + PyGObject_Type.tp_getset = pygobject_getsets; + PyGObject_Type.tp_dictoffset = offsetof(PyGObject, inst_dict); + PyGObject_Type.tp_init = (initproc)pygobject_init; + PyGObject_Type.tp_free = (freefunc)pygobject_free; PyGObject_Type.tp_alloc = PyType_GenericAlloc; PyGObject_Type.tp_new = PyType_GenericNew; pygobject_register_class(d, "GObject", G_TYPE_OBJECT, @@ -2338,21 +2161,46 @@ pygobject_object_register_types(PyObject *d) pyg_object_descr_doc_get()); pyg_set_object_has_new_constructor(G_TYPE_OBJECT); - /* GObject properties descriptor */ + /* GProps */ + PyGProps_Type.tp_dealloc = (destructor)PyGProps_dealloc; + PyGProps_Type.tp_as_sequence = (PySequenceMethods*)&_PyGProps_as_sequence; + PyGProps_Type.tp_getattro = (getattrofunc)PyGProps_getattro; + PyGProps_Type.tp_setattro = (setattrofunc)PyGProps_setattro; + PyGProps_Type.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC; + PyGProps_Type.tp_doc = "The properties of the GObject accessible as " + "Python attributes."; + PyGProps_Type.tp_traverse = (traverseproc)pygobject_props_traverse; + PyGProps_Type.tp_iter = (getiterfunc)pygobject_props_get_iter; if (PyType_Ready(&PyGProps_Type) < 0) return; + + /* GPropsDescr */ + PyGPropsDescr_Type.tp_flags = Py_TPFLAGS_DEFAULT; + PyGPropsDescr_Type.tp_descr_get = pyg_props_descr_descr_get; if (PyType_Ready(&PyGPropsDescr_Type) < 0) return; - if (PyType_Ready(&PyGPropsIter_Type) < 0) - return; descr = PyObject_New(PyObject, &PyGPropsDescr_Type); PyDict_SetItemString(PyGObject_Type.tp_dict, "props", descr); PyDict_SetItemString(PyGObject_Type.tp_dict, "__module__", o=_PyUnicode_FromString("gobject._gobject")); Py_DECREF(o); - PyType_Ready(&PyGObjectWeakRef_Type); - PyDict_SetItemString(d, "GObjectWeakRef", (PyObject *) &PyGObjectWeakRef_Type); - + /* GPropsIter */ + PyGPropsIter_Type.tp_dealloc = (destructor)pyg_props_iter_dealloc; + PyGPropsIter_Type.tp_flags = Py_TPFLAGS_DEFAULT; + PyGPropsIter_Type.tp_doc = "GObject properties iterator"; + PyGPropsIter_Type.tp_iternext = (iternextfunc)pygobject_props_iter_next; + if (PyType_Ready(&PyGPropsIter_Type) < 0) + return; + PyGObjectWeakRef_Type.tp_dealloc = (destructor)pygobject_weak_ref_dealloc; + PyGObjectWeakRef_Type.tp_call = (ternaryfunc)pygobject_weak_ref_call; + PyGObjectWeakRef_Type.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC; + PyGObjectWeakRef_Type.tp_doc = "A GObject weak reference"; + PyGObjectWeakRef_Type.tp_traverse = (traverseproc)pygobject_weak_ref_traverse; + PyGObjectWeakRef_Type.tp_clear = (inquiry)pygobject_weak_ref_clear; + PyGObjectWeakRef_Type.tp_methods = pygobject_weak_ref_methods; + if (PyType_Ready(&PyGObjectWeakRef_Type) < 0) + return; + PyDict_SetItemString(d, "GObjectWeakRef", (PyObject *) &PyGObjectWeakRef_Type); } diff --git a/gobject/pygparamspec.c b/gobject/pygparamspec.c index 8a62141..a6e225e 100644 --- a/gobject/pygparamspec.c +++ b/gobject/pygparamspec.c @@ -25,9 +25,13 @@ # include <config.h> #endif +#include <pyglib.h> + #include "pygobject-private.h" #include "pygparamspec.h" +PYGLIB_DEFINE_TYPE("gobject.GParamSpec", PyGParamSpec_Type, PyGParamSpec); + static int pyg_param_spec_compare(PyGParamSpec *self, PyGParamSpec *v) { @@ -355,28 +359,6 @@ pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr) return NULL; } -PyTypeObject PyGParamSpec_Type = { - PyObject_HEAD_INIT(NULL) - 0, - "gobject.GParamSpec", - sizeof(PyGParamSpec), - 0, - (destructor)pyg_param_spec_dealloc, - (printfunc)0, - (getattrfunc)pyg_param_spec_getattr, - (setattrfunc)0, - (cmpfunc)pyg_param_spec_compare, - (reprfunc)pyg_param_spec_repr, - 0, - 0, - 0, - (hashfunc)pyg_param_spec_hash, - (ternaryfunc)0, - (reprfunc)0, - 0L,0L,0L,0L, - NULL -}; - /** * pyg_param_spec_new: * @pspec: a GParamSpec. @@ -403,6 +385,12 @@ void pygobject_paramspec_register_types(PyObject *d) { PyGParamSpec_Type.ob_type = &PyType_Type; + PyGParamSpec_Type.tp_dealloc = (destructor)pyg_param_spec_dealloc; + PyGParamSpec_Type.tp_getattr = (getattrfunc)pyg_param_spec_getattr; + PyGParamSpec_Type.tp_compare = (cmpfunc)pyg_param_spec_compare; + PyGParamSpec_Type.tp_repr = (reprfunc)pyg_param_spec_repr; + PyGParamSpec_Type.tp_hash = (hashfunc)pyg_param_spec_hash; + if (PyType_Ready(&PyGParamSpec_Type)) return; PyDict_SetItemString(d, "GParamSpec", (PyObject *)&PyGParamSpec_Type); diff --git a/gobject/pygpointer.c b/gobject/pygpointer.c index 013ea6c..d06118e 100644 --- a/gobject/pygpointer.c +++ b/gobject/pygpointer.c @@ -30,6 +30,8 @@ GQuark pygpointer_class_key; +PYGLIB_DEFINE_TYPE("gobject.GPointer", PyGPointer_Type, PyGPointer); + static void pyg_pointer_dealloc(PyGPointer *self) { @@ -82,52 +84,6 @@ pyg_pointer_free(PyObject *op) PyObject_FREE(op); } -PyTypeObject PyGPointer_Type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - "gobject.GPointer", /* tp_name */ - sizeof(PyGPointer), /* tp_basicsize */ - 0, /* tp_itemsize */ - /* methods */ - (destructor)pyg_pointer_dealloc, /* tp_dealloc */ - (printfunc)0, /* tp_print */ - (getattrfunc)0, /* tp_getattr */ - (setattrfunc)0, /* tp_setattr */ - (cmpfunc)pyg_pointer_compare, /* tp_compare */ - (reprfunc)pyg_pointer_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - (hashfunc)pyg_pointer_hash, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)0, /* tp_str */ - (getattrofunc)0, /* tp_getattro */ - (setattrofunc)0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - NULL, /* Documentation string */ - (traverseproc)0, /* tp_traverse */ - (inquiry)0, /* tp_clear */ - (richcmpfunc)0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)0, /* tp_iter */ - (iternextfunc)0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - (PyTypeObject *)0, /* tp_base */ - (PyObject *)0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)pyg_pointer_init, /* tp_init */ - (allocfunc)0, /* tp_alloc */ - (newfunc)0, /* tp_new */ - (freefunc)pyg_pointer_free, /* tp_free */ - (inquiry)0, /* tp_is_gc */ - (PyObject *)0, /* tp_bases */ -}; - /** * pyg_register_pointer: * @dict: the module dictionary to store the wrapper class. @@ -218,6 +174,12 @@ pygobject_pointer_register_types(PyObject *d) { pygpointer_class_key = g_quark_from_static_string("PyGPointer::class"); + PyGPointer_Type.tp_dealloc = (destructor)pyg_pointer_dealloc; + PyGPointer_Type.tp_compare = (cmpfunc)pyg_pointer_compare; + PyGPointer_Type.tp_repr = (reprfunc)pyg_pointer_repr; + PyGPointer_Type.tp_hash = (hashfunc)pyg_pointer_hash; + PyGPointer_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + PyGPointer_Type.tp_init = (initproc)pyg_pointer_init; + PyGPointer_Type.tp_free = (freefunc)pyg_pointer_free; PYGOBJECT_REGISTER_GTYPE(d, PyGPointer_Type, "GPointer", G_TYPE_POINTER); - } diff --git a/gobject/pygtype.c b/gobject/pygtype.c index ae1bbc7..184b96b 100644 --- a/gobject/pygtype.c +++ b/gobject/pygtype.c @@ -28,6 +28,7 @@ #include "pygobject-private.h" #include "pygparamspec.h" +#include "pygtype.h" /* -------------- __gtype__ objects ---------------------------- */ @@ -36,6 +37,8 @@ typedef struct { GType type; } PyGTypeWrapper; +PYGLIB_DEFINE_TYPE("gobject.GType", PyGTypeWrapper_Type, PyGTypeWrapper); + static int pyg_type_wrapper_compare(PyGTypeWrapper *self, PyGTypeWrapper *v) { @@ -271,46 +274,6 @@ pyg_type_wrapper_init(PyGTypeWrapper *self, PyObject *args, PyObject *kwargs) return 0; } -PyTypeObject PyGTypeWrapper_Type = { - PyObject_HEAD_INIT(NULL) - 0, - "gobject.GType", - sizeof(PyGTypeWrapper), - 0, - (destructor)pyg_type_wrapper_dealloc, - (printfunc)0, - (getattrfunc)0, - (setattrfunc)0, - (cmpfunc)pyg_type_wrapper_compare, - (reprfunc)pyg_type_wrapper_repr, - 0, - 0, - 0, - (hashfunc)pyg_type_wrapper_hash, - (ternaryfunc)0, - (reprfunc)0, - (getattrofunc)0, - (setattrofunc)0, - 0, - Py_TPFLAGS_DEFAULT, - NULL, - (traverseproc)0, - (inquiry)0, - (richcmpfunc)0, - 0, - (getiterfunc)0, - (iternextfunc)0, - _PyGTypeWrapper_methods, - 0, - _PyGTypeWrapper_getsets, - NULL, - NULL, - (descrgetfunc)0, - (descrsetfunc)0, - 0, - (initproc)pyg_type_wrapper_init -}; - /** * pyg_type_wrapper_new: * type: a GType @@ -1527,43 +1490,7 @@ object_doc_descr_get(PyObject *self, PyObject *obj, PyObject *type) return pystring; } -static PyTypeObject PyGObjectDoc_Type = { - PyObject_HEAD_INIT(NULL) - 0, - "gobject.GObject__doc__", - sizeof(PyObject), - 0, - (destructor)object_doc_dealloc, - (printfunc)0, - (getattrfunc)0, - (setattrfunc)0, - (cmpfunc)0, - (reprfunc)0, - 0, - 0, - 0, - (hashfunc)0, - (ternaryfunc)0, - (reprfunc)0, - (getattrofunc)0, - (setattrofunc)0, - 0, - Py_TPFLAGS_DEFAULT, - NULL, - (traverseproc)0, - (inquiry)0, - (richcmpfunc)0, - 0, - (getiterfunc)0, - (iternextfunc)0, - 0, - 0, - 0, - (PyTypeObject *)0, - (PyObject *)0, - (descrgetfunc)object_doc_descr_get, - (descrsetfunc)0 -}; +PYGLIB_DEFINE_TYPE("gobject.GObject.__doc__", PyGObjectDoc_Type, PyObject); /** * pyg_object_descr_doc_get: @@ -1784,8 +1711,21 @@ _pyg_strv_to_gvalue(GValue *value, PyObject *obj) void pygobject_type_register_types(PyObject *d) { + PyGTypeWrapper_Type.tp_dealloc = (destructor)pyg_type_wrapper_dealloc; + PyGTypeWrapper_Type.tp_compare = (cmpfunc)pyg_type_wrapper_compare; + PyGTypeWrapper_Type.tp_repr = (reprfunc)pyg_type_wrapper_repr; + PyGTypeWrapper_Type.tp_hash = (hashfunc)pyg_type_wrapper_hash; + PyGTypeWrapper_Type.tp_flags = Py_TPFLAGS_DEFAULT; + PyGTypeWrapper_Type.tp_methods = _PyGTypeWrapper_methods; + PyGTypeWrapper_Type.tp_getset = _PyGTypeWrapper_getsets; + PyGTypeWrapper_Type.tp_init = (initproc)pyg_type_wrapper_init; PYGLIB_REGISTER_TYPE(d, PyGTypeWrapper_Type, "GType"); + /* This type lazily registered in pyg_object_descr_doc_get */ + PyGObjectDoc_Type.tp_dealloc = (destructor)object_doc_dealloc; + PyGObjectDoc_Type.tp_flags = Py_TPFLAGS_DEFAULT; + PyGObjectDoc_Type.tp_descr_get = (descrgetfunc)object_doc_descr_get; + pyg_register_gtype_custom(G_TYPE_STRV, _pyg_strv_from_gvalue, _pyg_strv_to_gvalue); |
