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

BUG: Fix _ctypes class circular reference. (#13808) #14851

Merged
merged 1 commit into from Nov 7, 2019

Conversation

@charris
Copy link
Member

charris commented Nov 7, 2019

Backport of #14469.

In _ctypes class, ctypes.cast() was called twice. It causes circular reference
for _ctypes._data due to the CPython bug https://bugs.python.org/issue12836.
This bug of ctypes.cast() seems affecting all Python versions.
It can be verified with the code below.

from sys import getrefcount
import ctypes

z = ctypes.c_int(1)
pc = ctypes.cast(ctypes.byref(z), ctypes.c_char_p)
print(getrefcount(pc))  # 2: from getrefcount()
pv = ctypes.cast(pc, ctypes.c_void_p)
print(getrefcount(pc))  # 3: from getrefcount(), pc._objects; circular ref: pc -> pc._objects -> pc!
_objects = pc._objects
print(_objects == pv._objects)
print(getrefcount(_objects))  # 4: from getrefcount(), _objects, pc._objects, pv._objects
pc = pv = None
print(getrefcount(_objects))  # 3: from getrefcount(), _objects; circular ref: _objects -> pc -> pc._objects!
In _ctypes class, ctypes.cast() was called twice. It causes circular reference
for _ctypes._data due to the CPython bug https://bugs.python.org/issue12836.
@charris charris added this to the 1.17.4 release. milestone Nov 7, 2019
@charris charris merged commit 18a7e60 into numpy:maintenance/1.17.x Nov 7, 2019
15 of 16 checks passed
15 of 16 checks passed
Shippable Run 6966 status is FAILED.
Details
LGTM analysis: C/C++ No code changes detected
Details
LGTM analysis: JavaScript No code changes detected
Details
LGTM analysis: Python No new or fixed alerts
Details
azure-pipeline numpy.numpy Build #20191107.7 succeeded
Details
azure-pipeline numpy.numpy (Linux_PyPy3) Linux_PyPy3 succeeded
Details
azure-pipeline numpy.numpy (Linux_Python_36_32bit_full_with_asserts) Linux_Python_36_32bit_full_with_asserts succeeded
Details
azure-pipeline numpy.numpy (Windows Python35-64bit-full) Windows Python35-64bit-full succeeded
Details
azure-pipeline numpy.numpy (Windows Python36-32bit-fast) Windows Python36-32bit-fast succeeded
Details
azure-pipeline numpy.numpy (Windows Python36-64bit-full) Windows Python36-64bit-full succeeded
Details
azure-pipeline numpy.numpy (Windows Python37-32bit-fast) Windows Python37-32bit-fast succeeded
Details
azure-pipeline numpy.numpy (Windows Python37-64bit-full) Windows Python37-64bit-full succeeded
Details
azure-pipeline numpy.numpy (macOS) macOS succeeded
Details
ci/circleci Your tests passed on CircleCI!
Details
codecov/project 85.75% (target 1%)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@charris charris deleted the charris:backport-14469 branch Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.