summaryrefslogtreecommitdiff
path: root/Python/ast_opt.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/ast_opt.c')
-rw-r--r--Python/ast_opt.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/Python/ast_opt.c b/Python/ast_opt.c
index 1a0b2a05b1..8270fa8e37 100644
--- a/Python/ast_opt.c
+++ b/Python/ast_opt.c
@@ -2,6 +2,7 @@
#include "Python.h"
#include "pycore_ast.h" // _PyAST_GetDocString()
#include "pycore_compile.h" // _PyASTOptimizeState
+#include "pycore_long.h" // _PyLong
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_format.h" // F_LJUST
@@ -152,7 +153,9 @@ check_complexity(PyObject *obj, Py_ssize_t limit)
static PyObject *
safe_multiply(PyObject *v, PyObject *w)
{
- if (PyLong_Check(v) && PyLong_Check(w) && Py_SIZE(v) && Py_SIZE(w)) {
+ if (PyLong_Check(v) && PyLong_Check(w) &&
+ !_PyLong_IsZero((PyLongObject *)v) && !_PyLong_IsZero((PyLongObject *)w)
+ ) {
size_t vbits = _PyLong_NumBits(v);
size_t wbits = _PyLong_NumBits(w);
if (vbits == (size_t)-1 || wbits == (size_t)-1) {
@@ -198,7 +201,9 @@ safe_multiply(PyObject *v, PyObject *w)
static PyObject *
safe_power(PyObject *v, PyObject *w)
{
- if (PyLong_Check(v) && PyLong_Check(w) && Py_SIZE(v) && Py_SIZE(w) > 0) {
+ if (PyLong_Check(v) && PyLong_Check(w) &&
+ !_PyLong_IsZero((PyLongObject *)v) && _PyLong_IsPositive((PyLongObject *)w)
+ ) {
size_t vbits = _PyLong_NumBits(v);
size_t wbits = PyLong_AsSize_t(w);
if (vbits == (size_t)-1 || wbits == (size_t)-1) {
@@ -215,7 +220,9 @@ safe_power(PyObject *v, PyObject *w)
static PyObject *
safe_lshift(PyObject *v, PyObject *w)
{
- if (PyLong_Check(v) && PyLong_Check(w) && Py_SIZE(v) && Py_SIZE(w)) {
+ if (PyLong_Check(v) && PyLong_Check(w) &&
+ !_PyLong_IsZero((PyLongObject *)v) && !_PyLong_IsZero((PyLongObject *)w)
+ ) {
size_t vbits = _PyLong_NumBits(v);
size_t wbits = PyLong_AsSize_t(w);
if (vbits == (size_t)-1 || wbits == (size_t)-1) {