Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend fallthrough safety to LLVM in gmpy2_mpmath.c #502

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/gmpy2_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -726,3 +726,14 @@ GMPy_Context_##NAME(PyObject *self, PyObject *args) \
} \
return GMPy_Number_##NAME(PyTuple_GET_ITEM(args, 0), PyTuple_GET_ITEM(args, 1), context); \
}

/*********************************************************************/

#if defined(__has_attribute)
# if __has_attribute(fallthrough)
# define GMPY_FALLTHROUGH __attribute__((fallthrough))
# endif
#endif
#if !defined(GMPY_FALLTHROUGH)
# define GMPY_FALLTHROUGH (void)0
#endif
8 changes: 5 additions & 3 deletions src/gmpy2_mpmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

/* Internal helper function for mpmath. */

#include "gmpy2_macros.h"

static PyObject *
mpmath_build_mpf(long sign, MPZ_Object *man, PyObject *exp, mp_bitcnt_t bc)
{
Expand Down Expand Up @@ -287,17 +289,17 @@ Pympz_mpmath_create_fast(PyObject *self, PyObject *const *args, Py_ssize_t nargs
switch (nargs) {
case 4:
rnd = PyString_1Char(args[3]);
/* fallthrough */
GMPY_FALLTHROUGH;
case 3:
prec = GMPy_Integer_AsLong(args[2]);
if (prec == (mp_bitcnt_t)(-1)) {
VALUE_ERROR("could not convert prec to positive int");
return NULL;
}
/* fallthrough */
GMPY_FALLTHROUGH;
case 2:
exp = args[1];
/* fallthrough */
GMPY_FALLTHROUGH;
case 1:
man = GMPy_MPZ_From_Integer(args[0], NULL);
if (!man) {
Expand Down