Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
9b5b8c92
Commit
9b5b8c92
authored
Jan 14, 2020
by
Josh Tobin
Committed by
Stefan Behnel
Jan 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bitwise "&" operator with negative operand (GH-3312)
parent
90ca446a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
1 deletion
+7
-1
Cython/Utility/Optimize.c
Cython/Utility/Optimize.c
+5
-1
tests/run/pyintop.pyx
tests/run/pyintop.pyx
+2
-0
No files found.
Cython/Utility/Optimize.c
View file @
9b5b8c92
...
@@ -923,7 +923,11 @@ static {{c_ret_type}} {{cfunc_name}}(PyObject *op1, PyObject *op2, CYTHON_UNUSED
...
@@ -923,7 +923,11 @@ static {{c_ret_type}} {{cfunc_name}}(PyObject *op1, PyObject *op2, CYTHON_UNUSED
{{
if
c_op
==
'&'
}}
{{
if
c_op
==
'&'
}}
// special case for &-ing arbitrarily large numbers with known single digit operands
// special case for &-ing arbitrarily large numbers with known single digit operands
if
((
intval
&
PyLong_MASK
)
==
intval
)
{
if
((
intval
&
PyLong_MASK
)
==
intval
)
{
return
PyLong_FromLong
(
likely
(
size
)
?
digits
[
0
]
&
intval
:
0
);
long
result
=
0
;
if
(
likely
(
size
))
{
result
=
intval
&
(
likely
(
size
>
0
)
?
digits
[
0
]
:
(
PyLong_MASK
-
digits
[
0
]
+
1
));
}
return
PyLong_FromLong
(
result
);
}
}
{{
endif
}}
{{
endif
}}
// special cases for 0: + - * % / // | ^ & >> <<
// special cases for 0: + - * % / // | ^ & >> <<
...
...
tests/run/pyintop.pyx
View file @
9b5b8c92
...
@@ -79,6 +79,8 @@ def and_int(obj2):
...
@@ -79,6 +79,8 @@ def and_int(obj2):
0
0
>>> and_int(18)
>>> and_int(18)
16
16
>>> and_int(-1)
16
"""
"""
obj1
=
obj2
&
0x10
obj1
=
obj2
&
0x10
return
obj1
return
obj1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment