[pygobject] Remove PYGOBJECT_REGISTER_GTYPE



commit 9787959fa5003dc42ed609dab24fd3ea1231b0e1
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Thu Apr 16 18:52:25 2020 +0200

    Remove PYGOBJECT_REGISTER_GTYPE
    
    Less macro magic

 gi/pygboxed.c     | 14 ++++++++++++--
 gi/pygenum.c      | 12 +++++++++++-
 gi/pygflags.c     | 12 +++++++++++-
 gi/pygi-type.h    | 15 ---------------
 gi/pyginterface.c | 32 +++++++++++++++++++++-----------
 gi/pygpointer.c   | 13 ++++++++++++-
 6 files changed, 67 insertions(+), 31 deletions(-)
---
diff --git a/gi/pygboxed.c b/gi/pygboxed.c
index 8f3d0497..313d3848 100644
--- a/gi/pygboxed.c
+++ b/gi/pygboxed.c
@@ -244,6 +244,8 @@ pygi_gboxed_new (GType boxed_type, gpointer boxed, gboolean copy_boxed,
 int
 pygi_gboxed_register_types(PyObject *d)
 {
+    PyObject *pygtype;
+
     pygboxed_type_key        = g_quark_from_static_string("PyGBoxed::class");
 
     PyGBoxed_Type.tp_dealloc = (destructor)gboxed_dealloc;
@@ -254,8 +256,16 @@ pygi_gboxed_register_types(PyObject *d)
     PyGBoxed_Type.tp_init = (initproc)gboxed_init;
     PyGBoxed_Type.tp_free = (freefunc)gboxed_free;
     PyGBoxed_Type.tp_hash = (hashfunc)gboxed_hash;
-    
-    PYGOBJECT_REGISTER_GTYPE(d, PyGBoxed_Type, "GBoxed", G_TYPE_BOXED);
+    PyGBoxed_Type.tp_alloc = PyType_GenericAlloc;
+    PyGBoxed_Type.tp_new = PyType_GenericNew;
+    if (PyType_Ready(&PyGBoxed_Type))
+        return -1;
+
+    pygtype = pyg_type_wrapper_new (G_TYPE_POINTER);
+    PyDict_SetItemString (PyGBoxed_Type.tp_dict, "__gtype__", pygtype);
+    Py_DECREF (pygtype);
+
+    PyDict_SetItemString(d, "GBoxed", (PyObject *)&PyGBoxed_Type);
 
     return 0;
 }
diff --git a/gi/pygenum.c b/gi/pygenum.c
index 7b3351d3..3b276fa7 100644
--- a/gi/pygenum.c
+++ b/gi/pygenum.c
@@ -381,6 +381,8 @@ static PyGetSetDef pyg_enum_getsets[] = {
 int
 pygi_enum_register_types(PyObject *d)
 {
+    PyObject *pygtype;
+
     pygenum_class_key        = g_quark_from_static_string("PyGEnum::class");
 
     PyGEnum_Type.tp_base = &PyLong_Type;
@@ -392,7 +394,15 @@ pygi_enum_register_types(PyObject *d)
     PyGEnum_Type.tp_richcompare = (richcmpfunc)pyg_enum_richcompare;
     PyGEnum_Type.tp_methods = pyg_enum_methods;
     PyGEnum_Type.tp_getset = pyg_enum_getsets;
-    PYGOBJECT_REGISTER_GTYPE(d, PyGEnum_Type, "GEnum", G_TYPE_ENUM);
+    PyGEnum_Type.tp_alloc = PyType_GenericAlloc;
+    if (PyType_Ready(&PyGEnum_Type))
+        return -1;
+
+    pygtype = pyg_type_wrapper_new (G_TYPE_ENUM);
+    PyDict_SetItemString (PyGEnum_Type.tp_dict, "__gtype__", pygtype);
+    Py_DECREF (pygtype);
+
+    PyDict_SetItemString(d, "GEnum", (PyObject *)&PyGEnum_Type);
 
     return 0;
 }
diff --git a/gi/pygflags.c b/gi/pygflags.c
index d93fa362..fd5abd87 100644
--- a/gi/pygflags.c
+++ b/gi/pygflags.c
@@ -498,6 +498,8 @@ static PyNumberMethods pyg_flags_as_number = {
 int
 pygi_flags_register_types(PyObject *d)
 {
+    PyObject *pygtype;
+
     pygflags_class_key = g_quark_from_static_string("PyGFlags::class");
 
     PyGFlags_Type.tp_base = &PyLong_Type;
@@ -509,7 +511,15 @@ pygi_flags_register_types(PyObject *d)
     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;
-    PYGOBJECT_REGISTER_GTYPE(d, PyGFlags_Type, "GFlags", G_TYPE_FLAGS);
+    PyGFlags_Type.tp_alloc = PyType_GenericAlloc;
+    if (PyType_Ready(&PyGFlags_Type))
+        return -1;
+
+    pygtype = pyg_type_wrapper_new (G_TYPE_FLAGS);
+    PyDict_SetItemString (PyGFlags_Type.tp_dict, "__gtype__", pygtype);
+    Py_DECREF (pygtype);
+
+    PyDict_SetItemString(d, "GFlags", (PyObject *)&PyGFlags_Type);
 
     return 0;
 }
diff --git a/gi/pygi-type.h b/gi/pygi-type.h
index 8032571d..c7e1a45c 100644
--- a/gi/pygi-type.h
+++ b/gi/pygi-type.h
@@ -26,21 +26,6 @@
 #include <girepository.h>
 #include "pygobject-internal.h"
 
-#define PYGOBJECT_REGISTER_GTYPE(d, type, name, gtype)      \
-  {                                                         \
-    PyObject *o;                                            \
-    if (!type.tp_alloc)                                     \
-        type.tp_alloc = PyType_GenericAlloc;                \
-    if (!type.tp_new)                                       \
-        type.tp_new = PyType_GenericNew;                    \
-    if (PyType_Ready(&type))                                \
-        return -1;                                          \
-    PyDict_SetItemString(d, name, (PyObject *)&type);       \
-    PyDict_SetItemString(type.tp_dict, "__gtype__",         \
-                         o=pyg_type_wrapper_new(gtype));    \
-    Py_DECREF(o);                                           \
-}
-
 extern PyTypeObject PyGTypeWrapper_Type;
 
 typedef PyObject *(* fromvaluefunc)(const GValue *value);
diff --git a/gi/pyginterface.c b/gi/pyginterface.c
index db15587c..c3f2d320 100644
--- a/gi/pyginterface.c
+++ b/gi/pyginterface.c
@@ -108,19 +108,29 @@ pyg_lookup_interface_info(GType gtype)
 int
 pygi_interface_register_types(PyObject *d)
 {
-  pyginterface_type_key = g_quark_from_static_string("PyGInterface::type");
-  pyginterface_info_key = g_quark_from_static_string("PyGInterface::info");
+    PyObject *pygtype;
 
-  PyGInterface_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
-  PyGInterface_Type.tp_init = (initproc)pyg_interface_init;
-  PyGInterface_Type.tp_free = (freefunc)pyg_interface_free;
+    pyginterface_type_key = g_quark_from_static_string("PyGInterface::type");
+    pyginterface_info_key = g_quark_from_static_string("PyGInterface::info");
 
-  PYGOBJECT_REGISTER_GTYPE(d, PyGInterface_Type, "GInterface", G_TYPE_INTERFACE)
+    PyGInterface_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
+    PyGInterface_Type.tp_init = (initproc)pyg_interface_init;
+    PyGInterface_Type.tp_free = (freefunc)pyg_interface_free;
+    PyGInterface_Type.tp_alloc = PyType_GenericAlloc;
+    PyGInterface_Type.tp_new = PyType_GenericNew;
+    if (PyType_Ready(&PyGInterface_Type))
+        return -1;
 
-  PyDict_SetItemString(PyGInterface_Type.tp_dict, "__doc__",
-                      pyg_object_descr_doc_get());
-  PyDict_SetItemString(PyGInterface_Type.tp_dict, "__gdoc__",
-                      pyg_object_descr_doc_get());
+    pygtype = pyg_type_wrapper_new (G_TYPE_INTERFACE);
+    PyDict_SetItemString (PyGInterface_Type.tp_dict, "__gtype__", pygtype);
+    Py_DECREF (pygtype);
 
-  return 0;
+    PyDict_SetItemString(PyGInterface_Type.tp_dict, "__doc__",
+                pyg_object_descr_doc_get());
+    PyDict_SetItemString(PyGInterface_Type.tp_dict, "__gdoc__",
+                pyg_object_descr_doc_get());
+
+    PyDict_SetItemString(d, "GInterface", (PyObject *)&PyGInterface_Type);
+
+    return 0;
 }
diff --git a/gi/pygpointer.c b/gi/pygpointer.c
index 7818221f..6fc7c4ac 100644
--- a/gi/pygpointer.c
+++ b/gi/pygpointer.c
@@ -187,6 +187,8 @@ pyg_pointer_new(GType pointer_type, gpointer pointer)
 int
 pygi_pointer_register_types(PyObject *d)
 {
+    PyObject *pygtype;
+
     pygpointer_class_key     = g_quark_from_static_string("PyGPointer::class");
 
     PyGPointer_Type.tp_dealloc = (destructor)pyg_pointer_dealloc;
@@ -196,7 +198,16 @@ pygi_pointer_register_types(PyObject *d)
     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);
+    PyGPointer_Type.tp_alloc = PyType_GenericAlloc;
+    PyGPointer_Type.tp_new = PyType_GenericNew;
+    if (PyType_Ready(&PyGPointer_Type))
+        return -1;
+
+    pygtype = pyg_type_wrapper_new (G_TYPE_POINTER);
+    PyDict_SetItemString (PyGPointer_Type.tp_dict, "__gtype__", pygtype);
+    Py_DECREF (pygtype);
+
+    PyDict_SetItemString(d, "GPointer", (PyObject *)&PyGPointer_Type);
 
     return 0;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]