From eefd9dbc8b3b4a80fc87f9b764457bff1a30e77f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Calixte?= Date: Thu, 20 Dec 2018 17:59:29 -0500 Subject: [PATCH] Don't use non constant in initializer --- boolean.go | 7 +++++-- byte_array.go | 3 +-- bytes.go | 3 +-- complex.go | 4 ++-- dict.go | 3 +-- float.go | 4 ++-- integer.go | 3 +-- list.go | 4 ++-- module.go | 3 +-- tuple.go | 4 ++-- type.c | 24 ------------------------ type.go | 4 ++-- type.h | 29 ----------------------------- unicode.go | 3 +-- 14 files changed, 21 insertions(+), 77 deletions(-) delete mode 100644 type.c delete mode 100644 type.h diff --git a/boolean.go b/boolean.go index ec498c7..c7ee260 100644 --- a/boolean.go +++ b/boolean.go @@ -10,10 +10,13 @@ package python3 /* #include "Python.h" #include "macro.h" -#include "type.h" */ import "C" +import ( + "unsafe" +) + //python boolean constants var ( Py_False = togo(C.Py_False) @@ -21,7 +24,7 @@ var ( ) //Bool : https://docs.python.org/3/c-api/bool.html#c.PyBool_Type -var Bool = togo(C._go_PyBool_Type) +var Bool = togo((*C.PyObject)(unsafe.Pointer(&C.PyBool_Type))) //PyBool_Check : https://docs.python.org/3/c-api/bool.html#c.PyBool_Check func PyBool_Check(o *PyObject) bool { diff --git a/byte_array.go b/byte_array.go index 200f5cd..a027f95 100644 --- a/byte_array.go +++ b/byte_array.go @@ -10,13 +10,12 @@ package python3 /* #include "Python.h" #include "macro.h" -#include "type.h" */ import "C" import "unsafe" //ByteArray : https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_Type -var ByteArray = togo(C._go_PyByteArray_Type) +var ByteArray = togo((*C.PyObject)(unsafe.Pointer(&C.PyByteArray_Type))) //PyByteArray_Check : https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_Check func PyByteArray_Check(o *PyObject) bool { diff --git a/bytes.go b/bytes.go index 7001f0b..0e91377 100644 --- a/bytes.go +++ b/bytes.go @@ -10,13 +10,12 @@ package python3 /* #include "Python.h" #include "macro.h" -#include "type.h" */ import "C" import "unsafe" //Bytes : https://docs.python.org/3/c-api/bytes.html#c.PyBytes_Type -var Bytes = togo(C._go_PyBytes_Type) +var Bytes = togo((*C.PyObject)(unsafe.Pointer(&C.PyBytes_Type))) //PyBytes_Check : https://docs.python.org/3/c-api/bytes.html#c.PyBytes_Check func PyBytes_Check(o *PyObject) bool { diff --git a/complex.go b/complex.go index b523870..d6b4010 100644 --- a/complex.go +++ b/complex.go @@ -10,12 +10,12 @@ package python3 /* #include "Python.h" #include "macro.h" -#include "type.h" */ import "C" +import "unsafe" //Complex : https://docs.python.org/3/c-api/complex.html#c.PyComplex_Type -var Complex = togo(C._go_PyComplex_Type) +var Complex = togo((*C.PyObject)(unsafe.Pointer(&C.PyComplex_Type))) //PyComplex_Check : https://docs.python.org/3/c-api/complex.html#c.PyComplex_Check func PyComplex_Check(p *PyObject) bool { diff --git a/dict.go b/dict.go index abcb0ba..b0d7072 100644 --- a/dict.go +++ b/dict.go @@ -10,7 +10,6 @@ package python3 /* #include "Python.h" #include "macro.h" -#include "type.h" */ import "C" import ( @@ -18,7 +17,7 @@ import ( ) //Dict : https://docs.python.org/3/c-api/dict.html#c.PyDict_Type -var Dict = togo(C._go_PyDict_Type) +var Dict = togo((*C.PyObject)(unsafe.Pointer(&C.PyDict_Type))) //PyDict_Check : https://docs.python.org/3/c-api/dict.html#c.PyDict_Check func PyDict_Check(p *PyObject) bool { diff --git a/float.go b/float.go index 37b1c22..52c384e 100644 --- a/float.go +++ b/float.go @@ -10,12 +10,12 @@ package python3 /* #include "Python.h" #include "macro.h" -#include "type.h" */ import "C" +import "unsafe" //Float : https://docs.python.org/3/c-api/float.html#c.PyFloat_Type -var Float = togo(C._go_PyFloat_Type) +var Float = togo((*C.PyObject)(unsafe.Pointer(&C.PyFloat_Type))) //PyFloat_Check : https://docs.python.org/3/c-api/float.html#c.PyFloat_Check func PyFloat_Check(p *PyObject) bool { diff --git a/integer.go b/integer.go index afd4621..1dc34a4 100644 --- a/integer.go +++ b/integer.go @@ -10,7 +10,6 @@ package python3 /* #include "Python.h" #include "macro.h" -#include "type.h" */ import "C" import ( @@ -18,7 +17,7 @@ import ( ) //Long : https://docs.python.org/3/c-api/long.html#c.PyLong_Type -var Long = togo(C._go_PyLong_Type) +var Long = togo((*C.PyObject)(unsafe.Pointer(&C.PyLong_Type))) //PyLong_Check : https://docs.python.org/3/c-api/long.html#c.PyLong_Check func PyLong_Check(p *PyObject) bool { diff --git a/list.go b/list.go index 7bc937b..60f58f1 100644 --- a/list.go +++ b/list.go @@ -10,12 +10,12 @@ package python3 /* #include "Python.h" #include "macro.h" -#include "type.h" */ import "C" +import "unsafe" //List : https://docs.python.org/3/c-api/list.html#c.PyList_Type -var List = togo(C._go_PyList_Type) +var List = togo((*C.PyObject)(unsafe.Pointer(&C.PyList_Type))) //PyList_Check : https://docs.python.org/3/c-api/list.html#c.PyList_Check func PyList_Check(p *PyObject) bool { diff --git a/module.go b/module.go index dd9709c..fb266f4 100644 --- a/module.go +++ b/module.go @@ -10,13 +10,12 @@ package python3 /* #include "Python.h" #include "macro.h" -#include "type.h" */ import "C" import "unsafe" //Module : https://docs.python.org/3/c-api/module.html#c.PyModule_Type -var Module = togo(C._go_PyModule_Type) +var Module = togo((*C.PyObject)(unsafe.Pointer(&C.PyModule_Type))) //PyModule_Check : https://docs.python.org/3/c-api/module.html#c.PyModule_Check func PyModule_Check(p *PyObject) bool { diff --git a/tuple.go b/tuple.go index 34c9a2b..f98a3a3 100644 --- a/tuple.go +++ b/tuple.go @@ -10,12 +10,12 @@ package python3 /* #include "Python.h" #include "macro.h" -#include "type.h" */ import "C" +import "unsafe" //Tuple : https://docs.python.org/3/c-api/tuple.html#c.PyTuple_Type -var Tuple = togo(C._go_PyTuple_Type) +var Tuple = togo((*C.PyObject)(unsafe.Pointer(&C.PyTuple_Type))) //PyTuple_Check : https://docs.python.org/3/c-api/tuple.html#c.PyTuple_Check func PyTuple_Check(p *PyObject) bool { diff --git a/type.c b/type.c deleted file mode 100644 index 8becf29..0000000 --- a/type.c +++ /dev/null @@ -1,24 +0,0 @@ -/* -Unless explicitly stated otherwise all files in this repository are licensed -under the $license_for_repo License. -This product includes software developed at Datadog (https://www.datadoghq.com/). -Copyright 2018 Datadog, Inc. -*/ - -#include "type.h" - -PyObject *_go_PyType_Type = (PyObject *)&PyType_Type; -PyObject *_go_PyLong_Type = (PyObject *)&PyLong_Type; -PyObject *_go_PyBool_Type = (PyObject *)&PyBool_Type; -PyObject *_go_PyFloat_Type = (PyObject *)&PyFloat_Type; -PyObject *_go_PyComplex_Type = (PyObject *)&PyComplex_Type; - -PyObject *_go_PyBytes_Type = (PyObject *)&PyBytes_Type; -PyObject *_go_PyByteArray_Type = (PyObject *)&PyByteArray_Type; -PyObject *_go_PyUnicode_Type = (PyObject *)&PyUnicode_Type; -PyObject *_go_PyTuple_Type = (PyObject *)&PyTuple_Type; -PyObject *_go_PyList_Type = (PyObject *)&PyList_Type; - -PyObject *_go_PyDict_Type = (PyObject *)&PyDict_Type; - -PyObject *_go_PyModule_Type = (PyObject *)&PyModule_Type; diff --git a/type.go b/type.go index 3a89483..8e239a6 100644 --- a/type.go +++ b/type.go @@ -10,12 +10,12 @@ package python3 /* #include "Python.h" #include "macro.h" -#include "type.h" */ import "C" +import "unsafe" //Type : https://docs.python.org/3/c-api/type.html#c.PyType_Type -var Type = togo(C._go_PyType_Type) +var Type = togo((*C.PyObject)(unsafe.Pointer(&C.PyType_Type))) //PyType_Check : https://docs.python.org/3/c-api/type.html#c.PyType_Check func PyType_Check(o *PyObject) bool { diff --git a/type.h b/type.h deleted file mode 100644 index a7e8b71..0000000 --- a/type.h +++ /dev/null @@ -1,29 +0,0 @@ -/* -Unless explicitly stated otherwise all files in this repository are licensed -under the $license_for_repo License. -This product includes software developed at Datadog (https://www.datadoghq.com/). -Copyright 2018 Datadog, Inc. -*/ - -#ifndef TYPE_H -#define TYPE_H - -#include "Python.h" - -extern PyObject *_go_PyType_Type; -extern PyObject *_go_PyLong_Type; -extern PyObject *_go_PyBool_Type; -extern PyObject *_go_PyFloat_Type; -extern PyObject *_go_PyComplex_Type; - -extern PyObject *_go_PyBytes_Type; -extern PyObject *_go_PyByteArray_Type; -extern PyObject *_go_PyUnicode_Type; -extern PyObject *_go_PyTuple_Type; -extern PyObject *_go_PyList_Type; - -extern PyObject *_go_PyDict_Type; - -extern PyObject *_go_PyModule_Type; - -#endif diff --git a/unicode.go b/unicode.go index 5502cc8..ff6eace 100644 --- a/unicode.go +++ b/unicode.go @@ -10,7 +10,6 @@ package python3 /* #include "Python.h" #include "macro.h" -#include "type.h" */ import "C" import ( @@ -18,7 +17,7 @@ import ( ) //Unicode : https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_Type -var Unicode = togo(C._go_PyUnicode_Type) +var Unicode = togo((*C.PyObject)(unsafe.Pointer(&C.PyUnicode_Type))) //PyUnicode_Check : https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_Check func PyUnicode_Check(o *PyObject) bool {