[dia: 74/105] #19: Use PyObject_HEAD_INIT(NULL) as per Python c-api docs.



commit 6eba1dc800ba71adf8538e1b18cf94cc02444204
Author: Eduard Nicodei <eddnicodei gmail com>
Date:   Fri Jan 11 20:52:12 2019 +0000

    #19: Use PyObject_HEAD_INIT(NULL) as per Python c-api docs.
    
      - https://docs.python.org/2/c-api/typeobj.html#c.PyObject.ob_type
      - This also made obsolete some previous #defs
      - This is because Python plugin would not compile on Windows
        error: initializer element is not constant (neduard/#5).

 plug-ins/python/diamodule.c         | 10 +++++-----
 plug-ins/python/pydia-color.c       |  2 +-
 plug-ins/python/pydia-cpoint.c      |  2 +-
 plug-ins/python/pydia-diagram.c     |  2 +-
 plug-ins/python/pydia-diagramdata.c |  2 +-
 plug-ins/python/pydia-display.c     |  2 +-
 plug-ins/python/pydia-error.c       |  2 +-
 plug-ins/python/pydia-export.c      |  2 +-
 plug-ins/python/pydia-font.c        |  2 +-
 plug-ins/python/pydia-geometry.c    | 10 +++++-----
 plug-ins/python/pydia-handle.c      |  2 +-
 plug-ins/python/pydia-image.c       |  2 +-
 plug-ins/python/pydia-layer.c       |  2 +-
 plug-ins/python/pydia-menuitem.c    |  2 +-
 plug-ins/python/pydia-object.c      |  4 ++--
 plug-ins/python/pydia-object.h      | 15 ---------------
 plug-ins/python/pydia-paperinfo.c   |  2 +-
 plug-ins/python/pydia-properties.c  |  2 +-
 plug-ins/python/pydia-property.c    |  2 +-
 plug-ins/python/pydia-sheet.c       |  2 +-
 plug-ins/python/pydia-text.c        |  2 +-
 21 files changed, 29 insertions(+), 44 deletions(-)
---
diff --git a/plug-ins/python/diamodule.c b/plug-ins/python/diamodule.c
index 01b774d6..72ffa347 100644
--- a/plug-ins/python/diamodule.c
+++ b/plug-ins/python/diamodule.c
@@ -576,8 +576,8 @@ initdia(void)
 {
     PyObject *m, *d;
 
-#if defined (_MSC_VER)
-     /* see: Python FAQ 3.24 "Initializer not a constant." */
+    /* see: Python FAQ 3.24 "Initializer not a constant." */
+    /* https://docs.python.org/2/c-api/typeobj.html#c.PyObject.ob_type */
     PyDiaConnectionPoint_Type.ob_type = &PyType_Type;
     PyDiaDiagram_Type.ob_type = &PyType_Type;
     PyDiaDisplay_Type.ob_type = &PyType_Type;
@@ -588,9 +588,12 @@ initdia(void)
 
     PyDiaExportFilter_Type.ob_type = &PyType_Type;
     PyDiaDiagramData_Type.ob_type = &PyType_Type;
+
     PyDiaPoint_Type.ob_type = &PyType_Type;
     PyDiaRectangle_Type.ob_type = &PyType_Type;
     PyDiaBezPoint_Type.ob_type = &PyType_Type;
+    PyDiaArrow_Type.ob_type = &PyType_Type;
+    PyDiaMatrix_Type.ob_type = &PyType_Type;
 
     PyDiaFont_Type.ob_type = &PyType_Type;
     PyDiaColor_Type.ob_type = &PyType_Type;
@@ -598,13 +601,10 @@ initdia(void)
     PyDiaProperty_Type.ob_type = &PyType_Type;
     PyDiaProperties_Type.ob_type = &PyType_Type;
     PyDiaError_Type.ob_type = &PyType_Type;
-    PyDiaArrow_Type.ob_type = &PyType_Type;
-    PyDiaMatrix_Type.ob_type = &PyType_Type;
     PyDiaText_Type.ob_type = &PyType_Type;
     PyDiaPaperinfo_Type.ob_type = &PyType_Type;
     PyDiaMenuitem_Type.ob_type = &PyType_Type;
     PyDiaSheet_Type.ob_type = &PyType_Type;
-#endif
 
     m = Py_InitModule3("dia", dia_methods, dia_module_doc);
     d = PyModule_GetDict(m);
diff --git a/plug-ins/python/pydia-color.c b/plug-ins/python/pydia-color.c
index dcf27439..a554b142 100644
--- a/plug-ins/python/pydia-color.c
+++ b/plug-ins/python/pydia-color.c
@@ -99,7 +99,7 @@ static PyMemberDef PyDiaColor_Members[] = {
  * Python objetcs
  */
 PyTypeObject PyDiaColor_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "DiaColor",
     sizeof(PyDiaColor),
diff --git a/plug-ins/python/pydia-cpoint.c b/plug-ins/python/pydia-cpoint.c
index 1ba75962..61f20776 100644
--- a/plug-ins/python/pydia-cpoint.c
+++ b/plug-ins/python/pydia-cpoint.c
@@ -102,7 +102,7 @@ static PyMemberDef PyDiaConnectionPoint_Members[] = {
 };
 
 PyTypeObject PyDiaConnectionPoint_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.ConnectionPoint",
     sizeof(PyDiaConnectionPoint),
diff --git a/plug-ins/python/pydia-diagram.c b/plug-ins/python/pydia-diagram.c
index 447e6a1e..2fbf9a43 100644
--- a/plug-ins/python/pydia-diagram.c
+++ b/plug-ins/python/pydia-diagram.c
@@ -581,7 +581,7 @@ PyDiaDiagram_GetAttr(PyDiaDiagram *self, gchar *attr)
 }
 
 PyTypeObject PyDiaDiagram_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.Diagram",
     sizeof(PyDiaDiagram),
diff --git a/plug-ins/python/pydia-diagramdata.c b/plug-ins/python/pydia-diagramdata.c
index 6b0bedf9..9a219b09 100644
--- a/plug-ins/python/pydia-diagramdata.c
+++ b/plug-ins/python/pydia-diagramdata.c
@@ -425,7 +425,7 @@ PyDiaDiagramData_GetAttr(PyDiaDiagramData *self, gchar *attr)
 }
 
 PyTypeObject PyDiaDiagramData_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.DiagramData",
     sizeof(PyDiaDiagramData),
diff --git a/plug-ins/python/pydia-display.c b/plug-ins/python/pydia-display.c
index 1e8b063c..e1572231 100644
--- a/plug-ins/python/pydia-display.c
+++ b/plug-ins/python/pydia-display.c
@@ -262,7 +262,7 @@ PyDiaDisplay_GetAttr(PyDiaDisplay *self, gchar *attr)
 }
 
 PyTypeObject PyDiaDisplay_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.Display",
     sizeof(PyDiaDisplay),
diff --git a/plug-ins/python/pydia-error.c b/plug-ins/python/pydia-error.c
index bef24473..3d8688ce 100644
--- a/plug-ins/python/pydia-error.c
+++ b/plug-ins/python/pydia-error.c
@@ -160,7 +160,7 @@ PyDiaError_Str(PyDiaError *self)
  * Python objetcs
  */
 PyTypeObject PyDiaError_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "DiaError",
     sizeof(PyDiaError),
diff --git a/plug-ins/python/pydia-export.c b/plug-ins/python/pydia-export.c
index cdaff50e..24b8772a 100644
--- a/plug-ins/python/pydia-export.c
+++ b/plug-ins/python/pydia-export.c
@@ -93,7 +93,7 @@ PyDiaExportFilter_GetAttr(PyDiaExportFilter *self, gchar *attr)
 }
 
 PyTypeObject PyDiaExportFilter_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.ExportFilter",
     sizeof(PyDiaExportFilter),
diff --git a/plug-ins/python/pydia-font.c b/plug-ins/python/pydia-font.c
index 21e2ef84..ce33f648 100644
--- a/plug-ins/python/pydia-font.c
+++ b/plug-ins/python/pydia-font.c
@@ -137,7 +137,7 @@ static PyMemberDef PyDiaFont_Members[] = {
  * Python objetc
  */
 PyTypeObject PyDiaFont_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.Font",
     sizeof(PyDiaFont),
diff --git a/plug-ins/python/pydia-geometry.c b/plug-ins/python/pydia-geometry.c
index 40bd8cc8..7c567db3 100644
--- a/plug-ins/python/pydia-geometry.c
+++ b/plug-ins/python/pydia-geometry.c
@@ -472,7 +472,7 @@ static PyMemberDef PyDiaPoint_Members[] = {
  * Python objetcs
  */
 PyTypeObject PyDiaPoint_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.Point",
     sizeof(PyDiaPoint),
@@ -517,7 +517,7 @@ static PyMemberDef PyDiaRect_Members[] = {
     { NULL }
 };
 PyTypeObject PyDiaRectangle_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.Rectangle",
     sizeof(PyDiaRectangle),
@@ -562,7 +562,7 @@ static PyMemberDef PyDiaBezPoint_Members[] = {
     { NULL }
 };
 PyTypeObject PyDiaBezPoint_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.BezPoint",
     sizeof(PyDiaBezPoint),
@@ -605,7 +605,7 @@ static PyMemberDef PyDiaArrow_Members[] = {
     { NULL }
 };
 PyTypeObject PyDiaArrow_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.Arrow",
     sizeof(PyDiaArrow),
@@ -648,7 +648,7 @@ static PyMemberDef PyDiaMatrix_Members[] = {
     { NULL }
 };
 PyTypeObject PyDiaMatrix_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.Matrix",
     sizeof(PyDiaMatrix),
diff --git a/plug-ins/python/pydia-handle.c b/plug-ins/python/pydia-handle.c
index 4c84d7d7..3c9811da 100644
--- a/plug-ins/python/pydia-handle.c
+++ b/plug-ins/python/pydia-handle.c
@@ -131,7 +131,7 @@ PyDiaHandle_GetAttr(PyDiaHandle *self, gchar *attr)
 }
 
 PyTypeObject PyDiaHandle_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.Handle",
     sizeof(PyDiaHandle),
diff --git a/plug-ins/python/pydia-image.c b/plug-ins/python/pydia-image.c
index 2f37016c..2c2c3fb3 100644
--- a/plug-ins/python/pydia-image.c
+++ b/plug-ins/python/pydia-image.c
@@ -177,7 +177,7 @@ static PyMemberDef PyDiaImage_Members[] = {
  * Python objetcs
  */
 PyTypeObject PyDiaImage_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.Image",
     sizeof(PyDiaImage),
diff --git a/plug-ins/python/pydia-layer.c b/plug-ins/python/pydia-layer.c
index 90ff7583..3ef09457 100644
--- a/plug-ins/python/pydia-layer.c
+++ b/plug-ins/python/pydia-layer.c
@@ -295,7 +295,7 @@ PyDiaLayer_GetAttr(PyDiaLayer *self, gchar *attr)
 }
 
 PyTypeObject PyDiaLayer_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.Layer",
     sizeof(PyDiaLayer),
diff --git a/plug-ins/python/pydia-menuitem.c b/plug-ins/python/pydia-menuitem.c
index 31b0b047..7c275c12 100644
--- a/plug-ins/python/pydia-menuitem.c
+++ b/plug-ins/python/pydia-menuitem.c
@@ -147,7 +147,7 @@ static PyMemberDef PyDiaMenuitem_Members[] = {
  * Python objetcs
  */
 PyTypeObject PyDiaMenuitem_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.Menuitem",
     sizeof(PyDiaMenuitem),
diff --git a/plug-ins/python/pydia-object.c b/plug-ins/python/pydia-object.c
index 0f98d262..da10e0dd 100644
--- a/plug-ins/python/pydia-object.c
+++ b/plug-ins/python/pydia-object.c
@@ -319,7 +319,7 @@ PyDiaObject_GetAttr(PyDiaObject *self, gchar *attr)
 }
 
 PyTypeObject PyDiaObject_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.Object",
     sizeof(PyDiaObject),
@@ -470,7 +470,7 @@ PyDiaObjectType_GetAttr(PyDiaObjectType *self, gchar *attr)
 }
 
 PyTypeObject PyDiaObjectType_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.ObjectType",
     sizeof(PyDiaObjectType),
diff --git a/plug-ins/python/pydia-object.h b/plug-ins/python/pydia-object.h
index ac7eae31..4ca84396 100644
--- a/plug-ins/python/pydia-object.h
+++ b/plug-ins/python/pydia-object.h
@@ -43,19 +43,4 @@ PyObject *PyDiaObjectType_New(DiaObjectType *otype);
 #define PyDiaObject_Check(o) ((o)->ob_type == &PyDiaObject_Type)
 #define PyDiaObjectType_Check(o) ((o)->ob_type == &PyDiaObjectType_Type)
 
-#ifdef _MSC_VER
-#  pragma warning(default:4047)
-  /* see: Python FAQ 3.24 "Initializer not a constant." */
-#  if 1 /* set to 0 to get all todos */
-#    undef PyObject_HEAD_INIT
-#    ifdef Py_TRACE_REFS
-#      define PyObject_HEAD_INIT(a) \
-         0, 0, 1, NULL, /* must be set by init function */
-#    else
-#      define PyObject_HEAD_INIT(a) \
-         1, NULL, /* must be set by init function */
-#    endif /* Py_TRACE_REFS */
-#  endif
-#endif
-
 #endif
diff --git a/plug-ins/python/pydia-paperinfo.c b/plug-ins/python/pydia-paperinfo.c
index d4453e2b..0fd41b40 100644
--- a/plug-ins/python/pydia-paperinfo.c
+++ b/plug-ins/python/pydia-paperinfo.c
@@ -127,7 +127,7 @@ static PyMemberDef PyDiaPaperinfo_Members[] = {
  * Python objetcs
  */
 PyTypeObject PyDiaPaperinfo_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.Paperinfo",
     sizeof(PyDiaPaperinfo),
diff --git a/plug-ins/python/pydia-properties.c b/plug-ins/python/pydia-properties.c
index 3ee57bf3..98edbbc7 100644
--- a/plug-ins/python/pydia-properties.c
+++ b/plug-ins/python/pydia-properties.c
@@ -281,7 +281,7 @@ PyDiaProperties_GetAttr(PyDiaProperties *self, gchar *attr)
  * Python object
  */
 PyTypeObject PyDiaProperties_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.Properties",
     sizeof(PyDiaProperties),
diff --git a/plug-ins/python/pydia-property.c b/plug-ins/python/pydia-property.c
index 642c8318..5fe4fd92 100644
--- a/plug-ins/python/pydia-property.c
+++ b/plug-ins/python/pydia-property.c
@@ -926,7 +926,7 @@ static PyMemberDef PyDiaProperty_Members[] = {
  * Python object
  */
 PyTypeObject PyDiaProperty_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.Property",
     sizeof(PyDiaProperty),
diff --git a/plug-ins/python/pydia-sheet.c b/plug-ins/python/pydia-sheet.c
index 91f3414a..9c3529d0 100644
--- a/plug-ins/python/pydia-sheet.c
+++ b/plug-ins/python/pydia-sheet.c
@@ -126,7 +126,7 @@ PyDiaSheet_GetAttr(PyDiaSheet *self, gchar *attr)
 }
 
 PyTypeObject PyDiaSheet_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.Sheet",
     sizeof(PyDiaSheet),
diff --git a/plug-ins/python/pydia-text.c b/plug-ins/python/pydia-text.c
index ab5feedc..7a1f2b63 100644
--- a/plug-ins/python/pydia-text.c
+++ b/plug-ins/python/pydia-text.c
@@ -138,7 +138,7 @@ static PyMemberDef PyDiaText_Members[] = {
  * Python objetcs
  */
 PyTypeObject PyDiaText_Type = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
     "dia.Text",
     sizeof(PyDiaText),


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