diff options
author | Barry Warsaw <barry@python.org> | 2017-09-15 01:13:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-15 01:13:16 (GMT) |
commit | b2e5794870eb4728ddfaafc0f79a40299576434f (patch) | |
tree | b625687bc81fd33c04fd83820e1276db92d9fa1a /Modules | |
parent | d384a81f557dab0b142bfcc9850bc68df46496ef (diff) | |
download | cpython-b2e5794870eb4728ddfaafc0f79a40299576434f.zip cpython-b2e5794870eb4728ddfaafc0f79a40299576434f.tar.gz cpython-b2e5794870eb4728ddfaafc0f79a40299576434f.tar.bz2 |
bpo-31338 (#3374)
* Add Py_UNREACHABLE() as an alias to abort().
* Use Py_UNREACHABLE() instead of assert(0)
* Convert more unreachable code to use Py_UNREACHABLE()
* Document Py_UNREACHABLE() and a few other macros.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_datetimemodule.c | 3 | ||||
-rw-r--r-- | Modules/_pickle.c | 3 | ||||
-rw-r--r-- | Modules/_tracemalloc.c | 2 | ||||
-rw-r--r-- | Modules/mathmodule.c | 3 |
4 files changed, 4 insertions, 7 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 1b68ff3..619ac84 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -1453,8 +1453,7 @@ diff_to_bool(int diff, int op) case Py_LT: istrue = diff < 0; break; case Py_GT: istrue = diff > 0; break; default: - assert(! "op unknown"); - istrue = 0; /* To shut up compiler */ + Py_UNREACHABLE(); } result = istrue ? Py_True : Py_False; Py_INCREF(result); diff --git a/Modules/_pickle.c b/Modules/_pickle.c index 3165b4e..fb69f14 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -750,8 +750,7 @@ _PyMemoTable_Lookup(PyMemoTable *self, PyObject *key) if (entry->me_key == NULL || entry->me_key == key) return entry; } - assert(0); /* Never reached */ - return NULL; + Py_UNREACHABLE(); } /* Returns -1 on failure, 0 on success. */ diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index feb32a0..386f2f1 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -726,7 +726,7 @@ tracemalloc_realloc(void *ctx, void *ptr, size_t new_size) The GIL and the table lock ensures that only one thread is allocating memory. */ - assert(0 && "should never happen"); + Py_UNREACHABLE(); } TABLES_UNLOCK(); } diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index c19620d..5d9fe5a 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -105,8 +105,7 @@ sinpi(double x) r = sin(pi*(y-2.0)); break; default: - assert(0); /* should never get here */ - r = -1.23e200; /* silence gcc warning */ + Py_UNREACHABLE(); } return copysign(1.0, x)*r; } |