Skip to content

Commit

Permalink
Fix warnings on GCC; simplify some more things.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Sep 18, 2024
1 parent 85b39df commit e6ad759
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 34 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ jobs:
# thus only use O3 (because Ofast enables fast-math, which has
# process-wide effects), we test with Ofast here, because we
# expect that some people will compile it themselves with that setting.
CPPFLAGS: "-Ofast -UNDEBUG"
CPPFLAGS: "-Ofast -UNDEBUG -Wall"
CFLAGS: "-Ofast -UNDEBUG -Wall"
- name: Install greenlet (Mac)
if: startsWith(runner.os, 'Mac')
run: |
Expand All @@ -84,7 +85,8 @@ jobs:
env:
# Unlike the above, we are actually distributing these
# wheels, so they need to be built for production use.
CPPFLAGS: "-O3"
CPPFLAGS: "-O3 -flto -ffunction-sections"
CFLAGS: "-O3 -flto -ffunction-sections"
# Build for both architectures
ARCHFLAGS: "-arch x86_64 -arch arm64"

Expand Down
2 changes: 1 addition & 1 deletion make-manylinux
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if [ -d /greenlet -a -d /opt/python ]; then
# Note: -Ofast includes -ffast-math which affects process-wide floating-point flags (e.g. can affect numpy).
# It may also violate standards compliance in a few ways. Rather than opt-out with -fno-fast-math,
# we use O3, which has neither of those problems.
export CFLAGS="-O3 -DNDEBUG"
export CFLAGS="-O3 -DNDEBUG -Wall"
# Build in an isolated directory
mkdir /tmp/build
cd /tmp/build
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

if sys.platform == 'darwin' or 'clang' in plat_compiler:
# The clang compiler doesn't use --std=c++11 by default
cpp_compile_args.append("--std=gnu++11")
cpp_compile_args.append("--std=c++11")
elif is_win and "MSC" in plat_compiler:
# Older versions of MSVC (Python 2.7) don't handle C++ exceptions
# correctly by default. While newer versions do handle exceptions
Expand Down
2 changes: 1 addition & 1 deletion src/greenlet/TGreenlet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ namespace greenlet
void set_new_cframe(_PyCFrame& frame) noexcept;
#endif

inline void may_switch_away() noexcept;
void may_switch_away() noexcept;
inline void will_switch_from(PyThreadState *const origin_tstate) noexcept;
void did_finish(PyThreadState* tstate) noexcept;
};
Expand Down
2 changes: 1 addition & 1 deletion src/greenlet/TUserGreenlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ UserGreenlet::inner_bootstrap(PyGreenlet* origin_greenlet, PyObject* run)
//PyObject* run = _run.relinquish_ownership();

/* in the new greenlet */
assert(this->thread_state()->borrow_current() == this->_self);
assert(this->thread_state()->borrow_current() == BorrowedGreenlet(this->_self));
// C++ exceptions cannot propagate to the parent greenlet from
// here. (TODO: Do we need a catch(...) clause, perhaps on the
// function itself? ALl we could do is terminate the program.)
Expand Down
8 changes: 0 additions & 8 deletions src/greenlet/greenlet_compiler_compat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@

#include <cstdint>

# if defined(__clang__)
# define G_FP_TMPL_STATIC static
# else
// GCC has no problem allowing static function pointers, but emits
// tons of warnings about "whose type uses the anonymous namespace [-Wsubobject-linkage]"
# define G_FP_TMPL_STATIC
# endif

# define G_NO_COPIES_OF_CLS(Cls) private: \
Cls(const Cls& other) = delete; \
Cls& operator=(const Cls& other) = delete
Expand Down
4 changes: 2 additions & 2 deletions src/greenlet/greenlet_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace greenlet {

#include "greenlet.h"

G_FP_TMPL_STATIC inline void
void
greenlet::refs::MainGreenletExactChecker(void *p)
{
if (!p) {
Expand Down Expand Up @@ -89,7 +89,7 @@ extern PyTypeObject PyGreenlet_Type;
* Forward declarations needed in multiple files.
*/
static PyObject* green_switch(PyGreenlet* self, PyObject* args, PyObject* kwargs);
static int green_is_gc(BorrowedGreenlet self);


#ifdef __clang__
# pragma clang diagnostic pop
Expand Down
41 changes: 25 additions & 16 deletions src/greenlet/greenlet_refs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#define PY_SSIZE_T_CLEAN
#include <Python.h>

#include <string>

//#include "greenlet_internal.hpp"
#include "greenlet_compiler_compat.hpp"
#include "greenlet_cpython_compat.hpp"
Expand Down Expand Up @@ -34,13 +37,13 @@ namespace greenlet
// implemented as macros.)
typedef void (*TypeChecker)(void*);

G_FP_TMPL_STATIC inline void
void
NoOpChecker(void*)
{
return;
}

G_FP_TMPL_STATIC inline void
void
GreenletChecker(void *p)
{
if (!p) {
Expand All @@ -63,7 +66,7 @@ namespace greenlet
}
}

G_FP_TMPL_STATIC inline void
void
MainGreenletExactChecker(void *p);

template <typename T, TypeChecker>
Expand Down Expand Up @@ -93,7 +96,7 @@ namespace greenlet

typedef _BorrowedGreenlet<PyGreenlet, GreenletChecker> BorrowedGreenlet;

G_FP_TMPL_STATIC inline void
void
ContextExactChecker(void *p)
{
if (!p) {
Expand Down Expand Up @@ -171,7 +174,7 @@ namespace greenlet {
protected:
T* p;
public:
explicit PyObjectPointer(T* it=nullptr) : p(it)
PyObjectPointer(T* it=nullptr) : p(it)
{
TC(p);
}
Expand All @@ -186,7 +189,7 @@ namespace greenlet {
// TODO: This should probably not exist here, but be moved
// down to relevant sub-types.

inline T* borrow() const noexcept
T* borrow() const noexcept
{
return this->p;
}
Expand All @@ -196,7 +199,7 @@ namespace greenlet {
return reinterpret_cast<PyObject*>(this->p);
}

inline T* operator->() const noexcept
T* operator->() const noexcept
{
return this->p;
}
Expand All @@ -206,7 +209,7 @@ namespace greenlet {
return this->p == Py_None;
}

inline PyObject* acquire_or_None() const noexcept
PyObject* acquire_or_None() const noexcept
{
PyObject* result = this->p ? reinterpret_cast<PyObject*>(this->p) : Py_None;
Py_INCREF(result);
Expand All @@ -215,15 +218,20 @@ namespace greenlet {

explicit operator bool() const noexcept
{
return p != nullptr;
return this->p != nullptr;
}

bool operator!() const noexcept
{
return this->p == nullptr;
}

inline Py_ssize_t REFCNT() const noexcept
Py_ssize_t REFCNT() const noexcept
{
return p ? Py_REFCNT(p) : -42;
}

inline PyTypeObject* TYPE() const noexcept
PyTypeObject* TYPE() const noexcept
{
return p ? Py_TYPE(p) : nullptr;
}
Expand Down Expand Up @@ -270,9 +278,9 @@ namespace greenlet {
#endif

template<typename T, TypeChecker TC>
inline bool operator==(const PyObjectPointer<T, TC>& lhs, const void* const rhs) noexcept
inline bool operator==(const PyObjectPointer<T, TC>& lhs, const PyObject* const rhs) noexcept
{
return lhs.borrow_o() == rhs;
return static_cast<const void*>(lhs.borrow_o()) == static_cast<const void*>(rhs);
}

template<typename T, TypeChecker TC, typename X, TypeChecker XC>
Expand Down Expand Up @@ -422,6 +430,7 @@ namespace greenlet {
target = o.relinquish_ownership();
}


class NewReference : public OwnedObject
{
private:
Expand Down Expand Up @@ -572,8 +581,8 @@ namespace greenlet {
{
return reinterpret_cast<PyObject*>(this->p);
}
inline Greenlet* operator->() const noexcept;
inline operator Greenlet*() const noexcept;
Greenlet* operator->() const noexcept;
operator Greenlet*() const noexcept;
};

typedef _BorrowedGreenlet<PyGreenlet> BorrowedGreenlet;
Expand Down Expand Up @@ -789,7 +798,7 @@ namespace greenlet {
return OwnedObject::consuming(PyObject_Call(this->p, args.borrow(), kwargs.borrow()));
}

G_FP_TMPL_STATIC inline void
inline void
ListChecker(void * p)
{
if (!p) {
Expand Down
4 changes: 2 additions & 2 deletions src/greenlet/greenlet_thread_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ class ThreadState {
#endif
}

inline bool has_main_greenlet()
inline bool has_main_greenlet() const noexcept
{
return !!this->main_greenlet;
return bool(this->main_greenlet);
}

// Called from the ThreadStateCreator when we're in non-standard
Expand Down

0 comments on commit e6ad759

Please sign in to comment.