From 10ec1af2a28db14ed81a842c4328b9be223f3241 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 26 Aug 2019 16:09:47 -0700 Subject: [PATCH 1/6] Fix unused variable warning --- Objects/unicodeobject.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index aa933773233b58..64739574a84436 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -503,7 +503,11 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content) void *data; if (ascii->state.compact == 1) { +#ifdef NDEBUG + ; +#else data = compact + 1; +#end _PyObject_ASSERT(op, kind == PyUnicode_1BYTE_KIND || kind == PyUnicode_2BYTE_KIND || kind == PyUnicode_4BYTE_KIND); @@ -514,7 +518,11 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content) else { PyUnicodeObject *unicode = (PyUnicodeObject *)op; +#ifdef NDEBUG + ; +#else data = unicode->data.any; +#end if (kind == PyUnicode_WCHAR_KIND) { _PyObject_ASSERT(op, ascii->length == 0); _PyObject_ASSERT(op, ascii->hash == -1); From 2680e3aae7b8a478c1da19306a0e18ec3cfc2b3d Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 26 Aug 2019 16:19:30 -0700 Subject: [PATCH 2/6] Properly close the ifdef --- Objects/unicodeobject.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 64739574a84436..2a2285e4504ef0 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -507,7 +507,7 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content) ; #else data = compact + 1; -#end +#endif _PyObject_ASSERT(op, kind == PyUnicode_1BYTE_KIND || kind == PyUnicode_2BYTE_KIND || kind == PyUnicode_4BYTE_KIND); @@ -522,7 +522,7 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content) ; #else data = unicode->data.any; -#end +#endif if (kind == PyUnicode_WCHAR_KIND) { _PyObject_ASSERT(op, ascii->length == 0); _PyObject_ASSERT(op, ascii->hash == -1); From e4df1aecc070d53cf7698d90074717608f50082a Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 26 Aug 2019 16:48:04 -0700 Subject: [PATCH 3/6] Fix signed/unsigned comparison warning --- Python/peephole.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/peephole.c b/Python/peephole.c index 3e56e788b0079b..23d5dc5abfa70c 100644 --- a/Python/peephole.c +++ b/Python/peephole.c @@ -255,7 +255,7 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, than +255 (encoded as multiple bytes), just to keep the peephole optimizer simple. The optimizer leaves line number deltas unchanged. */ - for (j = 0; j < tabsiz; j += 2) { + for (j = 0; j < (unsigned int) tabsiz; j += 2) { if (lnotab[j] == 255) { goto exitUnchanged; } From 5f806bde2ec88425deff1ea332ca99bebd5b0d71 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 26 Aug 2019 17:35:12 -0700 Subject: [PATCH 4/6] Simplify ifdef logic --- Objects/unicodeobject.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 2a2285e4504ef0..a6a5d8bf39eebb 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -500,12 +500,12 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content) } else { PyCompactUnicodeObject *compact = (PyCompactUnicodeObject *)op; +#ifndef NDEBUG void *data; +#endif if (ascii->state.compact == 1) { -#ifdef NDEBUG - ; -#else +#ifndef NDEBUG data = compact + 1; #endif _PyObject_ASSERT(op, kind == PyUnicode_1BYTE_KIND @@ -518,9 +518,7 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content) else { PyUnicodeObject *unicode = (PyUnicodeObject *)op; -#ifdef NDEBUG - ; -#else +#ifndef NDEBUG data = unicode->data.any; #endif if (kind == PyUnicode_WCHAR_KIND) { From 4ca10084a0080750078b909927e1ba39cf80bddf Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 26 Aug 2019 17:45:24 -0700 Subject: [PATCH 5/6] Fix signed/unsigned comparison warning --- Python/pystrhex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/pystrhex.c b/Python/pystrhex.c index 5dc7c9613796e0..4bdabab6a06f6e 100644 --- a/Python/pystrhex.c +++ b/Python/pystrhex.c @@ -57,7 +57,7 @@ static PyObject *_Py_strhex_impl(const char* argbuf, const Py_ssize_t arglen, } resultlen += arglen * 2; - if (abs_bytes_per_sep >= arglen) { + if (abs_bytes_per_sep >= (unsigned int) arglen) { bytes_per_sep_group = 0; abs_bytes_per_sep = 0; } From 03c60f55dde934b8b74668dc91b9d0352945b8d3 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 27 Aug 2019 09:17:02 -0700 Subject: [PATCH 6/6] Fix review comments --- Objects/unicodeobject.c | 2 +- Python/peephole.c | 4 ++-- Python/pystrhex.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index a6a5d8bf39eebb..d4b2c93a845264 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -516,9 +516,9 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content) _PyObject_ASSERT(op, compact->utf8 != data); } else { +#ifndef NDEBUG PyUnicodeObject *unicode = (PyUnicodeObject *)op; -#ifndef NDEBUG data = unicode->data.any; #endif if (kind == PyUnicode_WCHAR_KIND) { diff --git a/Python/peephole.c b/Python/peephole.c index 23d5dc5abfa70c..d859648411fa3f 100644 --- a/Python/peephole.c +++ b/Python/peephole.c @@ -255,8 +255,8 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, than +255 (encoded as multiple bytes), just to keep the peephole optimizer simple. The optimizer leaves line number deltas unchanged. */ - for (j = 0; j < (unsigned int) tabsiz; j += 2) { - if (lnotab[j] == 255) { + for (i = 0; i < tabsiz; i += 2) { + if (lnotab[i] == 255) { goto exitUnchanged; } } diff --git a/Python/pystrhex.c b/Python/pystrhex.c index 4bdabab6a06f6e..9d34f71a2e9cf3 100644 --- a/Python/pystrhex.c +++ b/Python/pystrhex.c @@ -57,7 +57,7 @@ static PyObject *_Py_strhex_impl(const char* argbuf, const Py_ssize_t arglen, } resultlen += arglen * 2; - if (abs_bytes_per_sep >= (unsigned int) arglen) { + if ((size_t)abs_bytes_per_sep >= (size_t)arglen) { bytes_per_sep_group = 0; abs_bytes_per_sep = 0; }