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

_ctypes\cfield.c identical subexpressions in Z_set #70032

Closed
ariccio mannequin opened this issue Dec 12, 2015 · 5 comments
Closed

_ctypes\cfield.c identical subexpressions in Z_set #70032

ariccio mannequin opened this issue Dec 12, 2015 · 5 comments
Labels
topic-ctypes type-feature A feature request or enhancement

Comments

@ariccio
Copy link
Mannequin

ariccio mannequin commented Dec 12, 2015

BPO 25845
Nosy @amauryfa, @abalkin, @meadori, @vadmium, @ariccio

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2015-12-12.07:38:51.973>
created_at = <Date 2015-12-12.04:50:49.417>
labels = ['ctypes', 'type-feature']
title = '_ctypes\\cfield.c identical subexpressions in Z_set'
updated_at = <Date 2015-12-12.07:38:51.929>
user = 'https://github.com/ariccio'

bugs.python.org fields:

activity = <Date 2015-12-12.07:38:51.929>
actor = 'martin.panter'
assignee = 'none'
closed = True
closed_date = <Date 2015-12-12.07:38:51.973>
closer = 'martin.panter'
components = ['ctypes']
creation = <Date 2015-12-12.04:50:49.417>
creator = 'Alexander Riccio'
dependencies = []
files = []
hgrepos = []
issue_num = 25845
keywords = []
message_count = 5.0
messages = ['256256', '256261', '256262', '256269', '256271']
nosy_count = 7.0
nosy_names = ['amaury.forgeotdarc', 'belopolsky', 'meador.inge', 'python-dev', 'martin.panter', 'random832', 'Alexander Riccio']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue25845'
versions = ['Python 3.5', 'Python 3.6']

@ariccio
Copy link
Mannequin Author

ariccio mannequin commented Dec 12, 2015

I found this while writing up a separate bug (CPython doesn't use static analysis!).

In _ctypes/cfield.c, Z_set has a bug of some sort:

    if (PyLong_Check(value) || PyLong_Check(value)) {

See: https://hg.python.org/cpython/file/tip/Modules/_ctypes/cfield.c#l1378

...which has been there for at least 5 years: https://hg.python.org/cpython/rev/cab14be0ada1

I'm not sure what the original programmer meant - it's been around forever & I don't know what was there before it - but PyLong_Check(value) is evaluated twice. Which doesn't really make sense.

Compiling with /analyze found this quite easily:

c:\pythondev\repo\modules\_ctypes\cfield.c(1378): warning C6287: Redundant code: the left and right sub-expressions are identical.

There's a similar issue in P_set, at line 1486.

@ariccio ariccio mannequin added the topic-ctypes label Dec 12, 2015
@random832
Copy link
Mannequin

random832 mannequin commented Dec 12, 2015

Looks like a result of searching and replacing PyInt with PyLong - the diff can be found here, if anyone cares. https://hg.python.org/cpython-fullhistory/rev/f324631462a2.

Oddly, there was _another, older_ revision that fixed this correctly: https://hg.python.org/cpython-fullhistory/rev/003d35215ef2 - looks like there was a bad merge somewhere along the line.

@random832
Copy link
Mannequin

random832 mannequin commented Dec 12, 2015

Sorry, my mistake, I was looking at z_set instead of Z_set. The earlier fix had left Z_set out for some reason. Anyway, just some historical interest anyway.

@python-dev
Copy link
Mannequin

python-dev mannequin commented Dec 12, 2015

New changeset 26859a7e385c by Martin Panter in branch '3.5':
Issue bpo-25845: Drop redundant checks leftover from int to long conversion
https://hg.python.org/cpython/rev/26859a7e385c

New changeset 9be59ad8af80 by Martin Panter in branch 'default':
Issue bpo-25845: Merge PyLong_Check() cleanup from 3.5
https://hg.python.org/cpython/rev/9be59ad8af80

@vadmium
Copy link
Member

vadmium commented Dec 12, 2015

History is good for understanding how things became the way they are. :) Thanks Alexander and Random!

@vadmium vadmium closed this as completed Dec 12, 2015
@vadmium vadmium added the type-feature A feature request or enhancement label Dec 12, 2015
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-ctypes type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant