From 06e61097a798bf9203884d3bb5ffddcf3296a3b2 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Wed, 17 Feb 2021 22:32:54 +0100 Subject: [PATCH] Use empty structs instead of empty enums for opaque types. Empty enums are uninhabited types and can cause issues like https://github.com/rust-lang/rust/issues/74840 This fixes the compiler warning: static of uninhabited type --- python27-sys/src/dictobject.rs | 2 +- python27-sys/src/longobject.rs | 2 +- python27-sys/src/pyarena.rs | 2 +- python27-sys/src/pystate.rs | 2 +- python27-sys/src/pythonrun.rs | 8 +++++--- python27-sys/src/setobject.rs | 2 +- python3-sys/src/code.rs | 3 ++- python3-sys/src/frameobject.rs | 3 ++- python3-sys/src/longobject.rs | 3 ++- python3-sys/src/object.rs | 3 ++- python3-sys/src/pyarena.rs | 3 ++- python3-sys/src/pystate.rs | 7 +++++-- python3-sys/src/pythonrun.rs | 11 ++++++++--- python3-sys/src/weakrefobject.rs | 3 ++- 14 files changed, 35 insertions(+), 19 deletions(-) diff --git a/python27-sys/src/dictobject.rs b/python27-sys/src/dictobject.rs index 6ff80709..bba92db8 100644 --- a/python27-sys/src/dictobject.rs +++ b/python27-sys/src/dictobject.rs @@ -3,7 +3,7 @@ use libc::{c_char, c_int}; use crate::object::*; use crate::pyport::Py_ssize_t; -//pub enum PyDictObject { /* representation hidden */ } +//#[repr(C)] pub struct PyDictObject { /* representation hidden */ } #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/longobject.rs b/python27-sys/src/longobject.rs index 99622b0d..5479747b 100644 --- a/python27-sys/src/longobject.rs +++ b/python27-sys/src/longobject.rs @@ -3,7 +3,7 @@ use libc::{c_char, c_double, c_int, c_long, c_longlong, c_ulong, c_ulonglong, c_ use crate::object::*; use crate::pyport::Py_ssize_t; -//enum PyLongObject { /* representation hidden */ } +//#[repr(C)] struct PyLongObject { /* representation hidden */ } #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/pyarena.rs b/python27-sys/src/pyarena.rs index 6eef43e1..bdd93aa2 100644 --- a/python27-sys/src/pyarena.rs +++ b/python27-sys/src/pyarena.rs @@ -3,7 +3,7 @@ use libc::{c_int, c_void, size_t}; use crate::object::PyObject; #[allow(missing_copy_implementations)] -pub enum PyArena {} +#[repr(C)] pub struct PyArena { _private: [u8; 0] } #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/pystate.rs b/python27-sys/src/pystate.rs index c95f28b3..e31776c3 100644 --- a/python27-sys/src/pystate.rs +++ b/python27-sys/src/pystate.rs @@ -3,7 +3,7 @@ use libc::{c_int, c_long}; use crate::frameobject::PyFrameObject; use crate::object::PyObject; -pub enum PyInterpreterState {} +#[repr(C)] pub struct PyInterpreterState { _private: [u8; 0] } pub type Py_tracefunc = unsafe extern "C" fn( arg1: *mut PyObject, diff --git a/python27-sys/src/pythonrun.rs b/python27-sys/src/pythonrun.rs index 44b0fe13..1ecbcceb 100644 --- a/python27-sys/src/pythonrun.rs +++ b/python27-sys/src/pythonrun.rs @@ -22,11 +22,13 @@ pub struct PyCompilerFlags { } #[allow(missing_copy_implementations)] -pub enum Struct__mod {} +#[repr(C)] pub struct Struct__mod { _private: [u8; 0] } + #[allow(missing_copy_implementations)] -pub enum Struct__node {} +#[repr(C)] pub struct Struct__node { _private: [u8; 0] } + #[allow(missing_copy_implementations)] -pub enum Struct_symtable {} +#[repr(C)] pub struct Struct_symtable { _private: [u8; 0] } #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/setobject.rs b/python27-sys/src/setobject.rs index 14f9122d..ebe2a3eb 100644 --- a/python27-sys/src/setobject.rs +++ b/python27-sys/src/setobject.rs @@ -3,7 +3,7 @@ use libc::c_int; use crate::object::*; use crate::pyport::Py_ssize_t; -//enum PySetObject { /* representation hidden */ } +//#[repr(C)] pub struct PySetObject { _private: [u8; 0] } #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/code.rs b/python3-sys/src/code.rs index d9708d2c..2541588f 100644 --- a/python3-sys/src/code.rs +++ b/python3-sys/src/code.rs @@ -5,7 +5,8 @@ use crate::object::*; use crate::pyport::Py_ssize_t; #[cfg(Py_3_8)] -pub enum _PyOpcache {} +#[repr(C)] +pub struct _PyOpcache { _private: [u8; 0] } #[repr(C)] #[derive(Copy)] diff --git a/python3-sys/src/frameobject.rs b/python3-sys/src/frameobject.rs index d04f1283..75a5fdcf 100644 --- a/python3-sys/src/frameobject.rs +++ b/python3-sys/src/frameobject.rs @@ -14,7 +14,8 @@ pub struct PyTryBlock { } #[cfg(Py_LIMITED_API)] -pub enum PyFrameObject {} +#[repr(C)] +pub struct PyFrameObject { _private: [u8; 0] } #[cfg(not(Py_LIMITED_API))] #[repr(C)] diff --git a/python3-sys/src/longobject.rs b/python3-sys/src/longobject.rs index d419eae8..ffffcc8b 100644 --- a/python3-sys/src/longobject.rs +++ b/python3-sys/src/longobject.rs @@ -3,7 +3,8 @@ use libc::{c_char, c_double, c_int, c_long, c_longlong, c_ulong, c_ulonglong, c_ use crate::object::*; use crate::pyport::Py_ssize_t; -pub enum PyLongObject {} +#[repr(C)] +pub struct PyLongObject { _private: [u8; 0] } #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/object.rs b/python3-sys/src/object.rs index 5d193a96..f313b8cb 100644 --- a/python3-sys/src/object.rs +++ b/python3-sys/src/object.rs @@ -201,7 +201,8 @@ pub type vectorcallfunc = unsafe extern "C" fn( ) -> *mut crate::object::PyObject; #[cfg(Py_LIMITED_API)] -pub enum PyTypeObject {} +#[repr(C)] +pub struct PyTypeObject { _private: [u8; 0] } #[cfg(not(Py_LIMITED_API))] mod typeobject { diff --git a/python3-sys/src/pyarena.rs b/python3-sys/src/pyarena.rs index bfe42fdb..f848d6a3 100644 --- a/python3-sys/src/pyarena.rs +++ b/python3-sys/src/pyarena.rs @@ -1 +1,2 @@ -pub enum PyArena {} +#[repr(C)] +pub struct PyArena { _private: [u8; 0] } diff --git a/python3-sys/src/pystate.rs b/python3-sys/src/pystate.rs index 0a715cf0..938aafc4 100644 --- a/python3-sys/src/pystate.rs +++ b/python3-sys/src/pystate.rs @@ -8,8 +8,11 @@ use crate::object::PyObject; #[cfg(Py_3_6)] pub const MAX_CO_EXTRA_USERS: libc::c_int = 255; -pub enum PyInterpreterState {} -pub enum PyThreadState {} +#[repr(C)] +pub struct PyInterpreterState { _private: [u8; 0] } + +#[repr(C)] +pub struct PyThreadState { _private: [u8; 0] } #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/pythonrun.rs b/python3-sys/src/pythonrun.rs index c59f6c17..1ce38254 100644 --- a/python3-sys/src/pythonrun.rs +++ b/python3-sys/src/pythonrun.rs @@ -37,7 +37,9 @@ pub struct PyCompilerFlags { } #[cfg(not(Py_LIMITED_API))] -pub enum _mod {} +#[repr(C)] +pub struct _mod { _private: [u8; 0] } + #[cfg(not(Py_LIMITED_API))] #[cfg_attr(windows, link(name = "pythonXY"))] @@ -116,8 +118,11 @@ extern "C" { ) -> *mut _mod; } -pub enum symtable {} -pub enum _node {} +#[repr(C)] +pub struct symtable { _private: [u8; 0] } + +#[repr(C)] +pub struct _node { _private: [u8; 0] } #[inline] #[deprecated(since = "0.5.2", note = "Deprecated since Python 3.9")] diff --git a/python3-sys/src/weakrefobject.rs b/python3-sys/src/weakrefobject.rs index c7628ad4..b183224e 100644 --- a/python3-sys/src/weakrefobject.rs +++ b/python3-sys/src/weakrefobject.rs @@ -2,7 +2,8 @@ use libc::c_int; use crate::object::*; -pub enum PyWeakReference {} +#[repr(C)] +pub struct PyWeakReference { _private: [u8; 0] } #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" {