New submission from hydroflask <hydrofl...@yqxmail.com>:

`_ctypes_simple_instance` in _ctypes.c returns the opposite logic of what its 
documentation claims. It is supposed to return true when the argument (a type 
object) is a direct subclass of `Simple_Type` (`_SimpleCData` in Python code). 
However it returns false instead.

No bugs have manifested from this because all of the call sites ( 
`callproc.c::GetResult`, 
`callbacks.c::_CallPythonObject`,_`ctypes.c::PyCData_get`, 
`_ctypes.c::Simple_from_outparm`) invert the return value of this function. The 
last example, `ctypes.c::Simple_from_outparm` only calls `Simple_get_value()` 
when `_ctypes_simple_instance` returns false, which makes sense because 
otherwise the invocation of `_ctypes.c::Simple_from_outparm()` could trigger an 
assertion error.

This is not just simply an issue of inverted logic because the logic isn't 
inverted in all cases. In `_ctypes_simple_instance` in the case when 
`PyCSimpleTypeObject_Check(type)` returns false, if this were supposed to be 
perfect inverted logic then the whole routine would return 1 (True) not 0. 
Fortunately, due to the way the code is structured, I don't think there is a 
case when `PyCSimpleTypeObject_Check(type)` returns false so the incorrect case 
where it returns a constant 0 is effectively dead code.

I have compiled a version of Python with the attached patch and run "make test" 
with no issues.

----------
components: ctypes
files: _ctypes_simple_instance_inverted.patch
keywords: patch
messages: 412947
nosy: hydroflask
priority: normal
severity: normal
status: open
title: _ctypes_simple_instance returns inverted logic
type: enhancement
versions: Python 3.10, Python 3.11, Python 3.7, Python 3.8, Python 3.9
Added file: 
https://bugs.python.org/file50612/_ctypes_simple_instance_inverted.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46697>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to