From 8705612581587f43300b83b6c382efed46147942 Mon Sep 17 00:00:00 2001
From: Leo Singer <leo.singer@ligo.org>
Date: Tue, 16 Jul 2024 16:00:17 -0400
Subject: [PATCH] Initialize PyTypeObjects with PyVarObject_HEAD_INIT
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This fixes the following errors on clang (`Apple clang version 15.0.0
(clang-1500.3.9.4)`):

```
src/infinity.c:271:2: error: incompatible pointer to integer conversion initializing 'Py_ssize_t' (aka 'long') with an expression of type 'void *' [-Wint-conversion]
        PyObject_HEAD_INIT(NULL)
        ^~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/Library/Frameworks/Python.framework/Versions/3.12/include/python3.12/object.h:142:9: note: expanded from macro 'PyObject_HEAD_INIT'
        (type)                   \
        ^~~~~~
```

and the following warnings on gcc (`gcc (Debian 12.2.0-14) 12.2.0`):

```
src/infinity.c:270:39: warning: missing braces around initializer [-Wmissing-braces]
  270 | PyTypeObject segments_Infinity_Type = {
      |                                       ^
In file included from /usr/local/include/python3.12/Python.h:44,
                 from src/infinity.c:29:
/usr/local/include/python3.12/object.h:142:9: warning: initialization of ‘long int’ from ‘void *’ makes integer from pointer without a cast [-Wint-conversion]
  142 |         (type)                   \
      |         ^
src/infinity.c:271:9: note: in expansion of macro ‘PyObject_HEAD_INIT’
  271 |         PyObject_HEAD_INIT(NULL)
      |         ^~~~~~~~~~~~~~~~~~
/usr/local/include/python3.12/object.h:142:9: note: (near initialization for ‘segments_Infinity_Type.ob_base.ob_size’)
  142 |         (type)                   \
      |         ^
src/infinity.c:271:9: note: in expansion of macro ‘PyObject_HEAD_INIT’
  271 |         PyObject_HEAD_INIT(NULL)
      |         ^~~~~~~~~~~~~~~~~~
```

Fixes #20.
---
 src/infinity.c    | 2 +-
 src/segment.c     | 2 +-
 src/segmentlist.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/infinity.c b/src/infinity.c
index d85ea13..87ceb23 100644
--- a/src/infinity.c
+++ b/src/infinity.c
@@ -268,7 +268,7 @@ static struct PyMethodDef methods[] = {
 
 
 PyTypeObject segments_Infinity_Type = {
-	PyObject_HEAD_INIT(NULL)
+	PyVarObject_HEAD_INIT(NULL, 0)
 	.tp_as_number = &as_number,
 	.tp_basicsize = sizeof(segments_Infinity),
 	.tp_doc =
diff --git a/src/segment.c b/src/segment.c
index cc9a418..1f373c8 100644
--- a/src/segment.c
+++ b/src/segment.c
@@ -480,7 +480,7 @@ static struct PyMethodDef methods[] = {
 
 
 PyTypeObject segments_Segment_Type = {
-	PyObject_HEAD_INIT(NULL)
+	PyVarObject_HEAD_INIT(NULL, 0)
 	.tp_as_number = &as_number,
 	.tp_as_sequence = &as_sequence,
 	.tp_doc =
diff --git a/src/segmentlist.c b/src/segmentlist.c
index 98b6b76..f666487 100644
--- a/src/segmentlist.c
+++ b/src/segmentlist.c
@@ -1540,7 +1540,7 @@ static struct PyMethodDef methods[] = {
 
 
 PyTypeObject segments_SegmentList_Type = {
-	PyObject_HEAD_INIT(NULL)
+	PyVarObject_HEAD_INIT(NULL, 0)
 	.tp_as_number = &as_number,
 	.tp_as_sequence = &as_sequence,
 	.tp_doc =
-- 
GitLab

